From 67879a659d545deaa88118c6fbc60536321f27b2 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Fri, 16 Mar 2018 16:52:43 +0100 Subject: [PATCH] doorlockd: add simulation mode Signed-off-by: Ralf Ramsauer --- doorlockd-new/TODOs | 1 - doorlockd-new/config.cfg | 1 + doorlockd-new/doorlockd.py | 12 ++++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doorlockd-new/TODOs b/doorlockd-new/TODOs index 6d51c5f..0d34548 100644 --- a/doorlockd-new/TODOs +++ b/doorlockd-new/TODOs @@ -1,3 +1,2 @@ - Connect to LDAP -- Add 'demo' mode - Add support for post/pre lock/unlock hooks diff --git a/doorlockd-new/config.cfg b/doorlockd-new/config.cfg index 6322a90..327d580 100644 --- a/doorlockd-new/config.cfg +++ b/doorlockd-new/config.cfg @@ -1,4 +1,5 @@ DEBUG = True +SIMULATE = True SECRET_KEY = 'foobar' BOOTSTRAP_SERVE_LOCAL = True diff --git a/doorlockd-new/doorlockd.py b/doorlockd-new/doorlockd.py index b3aad1a..801acc0 100755 --- a/doorlockd-new/doorlockd.py +++ b/doorlockd-new/doorlockd.py @@ -57,6 +57,8 @@ webapp = Flask(__name__) webapp.config.from_pyfile('config.cfg') socketio = SocketIO(webapp, async_mode=None) Bootstrap(webapp) +serial_port = webapp.config.get('SERIAL_PORT') +simulate = webapp.config.get('SIMULATE') # copied from sudo eperm_insults = { @@ -134,6 +136,9 @@ class DoorHandler: state = DoorState.Close def __init__(self, device): + if simulate: + return + self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1) self.thread = Thread(target=self.thread_worker) @@ -178,11 +183,14 @@ class DoorHandler: class Logic: def __init__(self): - self.door_handler = DoorHandler(webapp.config.get('SERIAL_PORT')) + self.door_handler = DoorHandler(serial_port) def _try_auth_ldap(self, user, password): + if simulate: + log.info('SIMULATION MODE! ACCEPTING ANYTHING!') + return LogicResponse.Success + log.info('Trying to LDAP auth (user, password) as user %s', user) - return LogicResponse.Success return LogicResponse.LDAP def try_auth(self, credentials):