mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 00:24:00 +02:00
Added unlocker classes concept
This commit is contained in:
parent
739c1a1e19
commit
5b77dff18d
3 changed files with 60 additions and 3 deletions
|
@ -10,6 +10,7 @@ from binascii import hexlify
|
|||
|
||||
from brmdoor_nfc import NFCDevice, NFCError
|
||||
from brmdoor_authenticator import UidAuthenticator
|
||||
import unlocker
|
||||
|
||||
class BrmdoorConfigError(ConfigParser.Error):
|
||||
"""
|
||||
|
@ -43,6 +44,7 @@ class BrmdoorConfig(object):
|
|||
self.unknownUidTimeoutSecs = self.config.getint("brmdoor", "unknown_uid_timeout_secs")
|
||||
self.logFile = self.config.get("brmdoor", "log_file")
|
||||
self.logLevel = self.convertLoglevel(self.config.get("brmdoor", "log_level"))
|
||||
self.unlocker = self.config.get("brmdoor", "unlocker")
|
||||
|
||||
def convertLoglevel(self, levelString):
|
||||
"""Converts string 'debug', 'info', etc. into corresponding
|
||||
|
@ -64,6 +66,10 @@ class NFCScanner(object):
|
|||
self.authenticator = UidAuthenticator(config.authDbFilename)
|
||||
self.unknownUidTimeoutSecs = config.unknownUidTimeoutSecs
|
||||
self.lockOpenedSecs = config.lockOpenedSecs
|
||||
|
||||
unlockerClassName = config.unlocker
|
||||
unlockerClass = getattr(unlocker, unlockerClassName)
|
||||
self.unlocker = unlockerClass(config)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
|
@ -107,7 +113,7 @@ class NFCScanner(object):
|
|||
return
|
||||
|
||||
logging.info("Unlocking for UID %s", record)
|
||||
time.sleep(self.lockOpenedSecs)
|
||||
self.unlocker.unlock()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -125,6 +131,6 @@ if __name__ == "__main__":
|
|||
logging.basicConfig(filename=config.logFile, level=config.logLevel,
|
||||
format="%(asctime)s %(levelname)s %(message)s [%(pathname)s:%(lineno)d]")
|
||||
|
||||
nfcUnlocker = NFCUnlocker(config)
|
||||
nfcUnlocker.run()
|
||||
nfcScanner = NFCScanner(config)
|
||||
nfcScanner.run()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue