1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00

doorlockd: propagate cfg through Logic

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-10-08 22:14:25 +02:00
parent 5b296b777d
commit 8d37886ee1

View File

@ -72,12 +72,9 @@ class Config:
cfg = Config(SYSCONFDIR) cfg = Config(SYSCONFDIR)
# Booleans # Booleans
simulate_serial = cfg.boolean('SIMULATE_SERIAL')
run_hooks = cfg.boolean('RUN_HOOKS') run_hooks = cfg.boolean('RUN_HOOKS')
sounds = cfg.boolean('SOUNDS') sounds = cfg.boolean('SOUNDS')
serial_port = cfg.str('SERIAL_PORT')
wave_emergency = 'emergency_unlock.wav' wave_emergency = 'emergency_unlock.wav'
wave_lock = 'lock.wav' wave_lock = 'lock.wav'
@ -176,9 +173,12 @@ class DoorHandler:
# TBD DOOR NOT CLOSED # TBD DOOR NOT CLOSED
def __init__(self, device): def __init__(self, device):
if simulate_serial: if cfg.boolean('SIMULATE_SERIAL'):
return return
device = cfg.str('SERIAL_PORT')
log.info('Using serial port: %s' % device)
self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N', self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N',
stopbits=1, timeout=0) stopbits=1, timeout=0)
self.thread = Thread(target=self.thread_worker) self.thread = Thread(target=self.thread_worker)
@ -263,9 +263,9 @@ class DoorHandler:
class Logic: class Logic:
def __init__(self): def __init__(self, cfg):
self.auth = Authenticator(cfg) self.auth = Authenticator(cfg)
self.door_handler = DoorHandler(serial_port) self.door_handler = DoorHandler(cfg)
def _request(self, state, credentials): def _request(self, state, credentials):
err = self.auth.try_auth(credentials) err = self.auth.try_auth(credentials)
@ -289,9 +289,8 @@ if __name__ == '__main__':
logging.basicConfig(level=log_level, stream=sys.stdout, logging.basicConfig(level=log_level, stream=sys.stdout,
format=log_fmt, datefmt=date_fmt) format=log_fmt, datefmt=date_fmt)
log.info('Starting doorlockd') log.info('Starting doorlockd')
log.info('Using serial port: %s' % serial_port)
logic = Logic() logic = Logic(cfg)
webapp_run(cfg, logic, __status__, __version__, template_folder, webapp_run(cfg, logic, __status__, __version__, template_folder,
static_folder) static_folder)