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:
Thomas 2024-01-03 21:10:07 +01:00
parent 03e27930ce
commit e7955cab59
3 changed files with 6 additions and 6 deletions

View File

@ -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()

View File

@ -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

View File

@ -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)