mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 10:24:26 +01:00
update nuki state handling
update state handling so that manual state changes of the nuki (key or button press) are reflected to the internal doorlock state. Refactor general state handling to support this Signed-off-by: Thomas Schmid <tom@lfence.de>
This commit is contained in:
parent
03e27930ce
commit
e7955cab59
@ -37,7 +37,7 @@ __status__ = 'Development'
|
|||||||
__maintainer__ = 'Ralf Ramsauer'
|
__maintainer__ = 'Ralf Ramsauer'
|
||||||
__version__ = '0.0'
|
__version__ = '0.0'
|
||||||
|
|
||||||
log_level = logging.DEBUG
|
log_level = logging.INFO
|
||||||
date_fmt = '%Y-%m-%d %H:%M:%S'
|
date_fmt = '%Y-%m-%d %H:%M:%S'
|
||||||
log_fmt = '%(asctime)-15s %(levelname)-8s %(message)s'
|
log_fmt = '%(asctime)-15s %(levelname)-8s %(message)s'
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
@ -77,7 +77,7 @@ class DoorHandler:
|
|||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
self.backend.set_state(self.state)
|
self.backend.set_state(self.state)
|
||||||
self.backend.register_state_changed_handler(self.update_state)
|
self.backend.register_state_changed_handler(self.backend_state_change_handler)
|
||||||
|
|
||||||
def backend_state_change_handler(self, new_state):
|
def backend_state_change_handler(self, new_state):
|
||||||
self.update_state(self.state, new_state, DoorlockResponse.Success)
|
self.update_state(self.state, new_state, DoorlockResponse.Success)
|
||||||
@ -121,7 +121,7 @@ class DoorHandler:
|
|||||||
elif state == DoorState.Open:
|
elif state == DoorState.Open:
|
||||||
err = self.open()
|
err = self.open()
|
||||||
|
|
||||||
self.update_state(old_state, self.state, err)
|
self.update_state(old_state, state, err)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
@ -145,15 +145,15 @@ class NukiBridge(DoorlockBackend):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if not NukiBridgeDevice.compare_device_state(dev_state, last_dev_state):
|
if not NukiBridgeDevice.compare_device_state(dev_state, last_dev_state):
|
||||||
log.debug(f"Nuki changed state: {dev_state}")
|
log.info(f"Nuki changed state: {dev_state}")
|
||||||
|
|
||||||
if self.current_state != DoorState.Closed and dev_state["stateName"] == "locked":
|
if self.current_state != DoorState.Closed and dev_state["stateName"] == "locked":
|
||||||
self.current_state = DoorState.Closed
|
self.current_state = DoorState.Closed
|
||||||
self.state_change_callback(self.current_state, DoorlockResponse.Success)
|
self.state_change_callback(self.current_state)
|
||||||
|
|
||||||
if self.current_state != DoorState.Open and dev_state["stateName"] == "unlocked":
|
if self.current_state != DoorState.Open and dev_state["stateName"] == "unlocked":
|
||||||
self.current_state = DoorState.Open
|
self.current_state = DoorState.Open
|
||||||
self.state_change_callback(self.current_state, DoorlockResponse.Success)
|
self.state_change_callback(self.current_state)
|
||||||
|
|
||||||
last_dev_state = dev_state
|
last_dev_state = dev_state
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
Loading…
Reference in New Issue
Block a user