From 8d37886ee126c7d777e9789bdc8c708ea381c6bf Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Mon, 8 Oct 2018 22:14:25 +0200 Subject: [PATCH] doorlockd: propagate cfg through Logic Signed-off-by: Ralf Ramsauer --- doorlockd | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/doorlockd b/doorlockd index a461b55..bd8188a 100755 --- a/doorlockd +++ b/doorlockd @@ -72,12 +72,9 @@ class Config: cfg = Config(SYSCONFDIR) # Booleans -simulate_serial = cfg.boolean('SIMULATE_SERIAL') run_hooks = cfg.boolean('RUN_HOOKS') sounds = cfg.boolean('SOUNDS') -serial_port = cfg.str('SERIAL_PORT') - wave_emergency = 'emergency_unlock.wav' wave_lock = 'lock.wav' @@ -176,9 +173,12 @@ class DoorHandler: # TBD DOOR NOT CLOSED def __init__(self, device): - if simulate_serial: + if cfg.boolean('SIMULATE_SERIAL'): return + device = cfg.str('SERIAL_PORT') + log.info('Using serial port: %s' % device) + self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=0) self.thread = Thread(target=self.thread_worker) @@ -263,9 +263,9 @@ class DoorHandler: class Logic: - def __init__(self): + def __init__(self, cfg): self.auth = Authenticator(cfg) - self.door_handler = DoorHandler(serial_port) + self.door_handler = DoorHandler(cfg) def _request(self, state, credentials): err = self.auth.try_auth(credentials) @@ -289,9 +289,8 @@ if __name__ == '__main__': logging.basicConfig(level=log_level, stream=sys.stdout, format=log_fmt, datefmt=date_fmt) 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, static_folder)