Skip to content

Commit

Permalink
Nuki:
Browse files Browse the repository at this point in the history
- Read Lock State via LISTS webservice, as direct lock access is returning 503 in case of locking
- Update Lock state via Lists once lock state is changed to get intermediate states
  • Loading branch information
psilo909 committed Dec 26, 2023
1 parent 7151815 commit d0d2441
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
47 changes: 44 additions & 3 deletions nuki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


class Nuki(SmartPlugin):
PLUGIN_VERSION = "1.6.1"
PLUGIN_VERSION = "1.6.2"

def __init__(self, sh, *args, **kwargs):

Expand Down Expand Up @@ -110,7 +110,7 @@ def _scheduler_job(self):
# will also be executed at start
self._get_paired_nukis()
self._register_callback()
self._get_nuki_status()
self._get_nuki_status_via_list()

def stop(self):
self.alive = False
Expand Down Expand Up @@ -163,9 +163,37 @@ def update_item(self, item, caller=None, source=None, dest=None):
# self._get_nuki_status()
self.logger.info(
"Plugin '{0}': update item: {1}".format(self.get_shortname(), item.property.path))
# immediatly update lock state via list, to e.g. the status information that lock is locking
self._get_nuki_status_via_list()
else:
self.logger.error("Plugin '{}': no response.".format(self.get_shortname()))

@staticmethod
def update_lock_state_via_list(nuki_id, nuki_data):
nuki_battery = None
nuki_state = None
nuki_doorstate = None

lock_state=nuki_data['lastKnownState']

if 'state' in lock_state:
nuki_state = lock_state['state']
if 'doorsensorState' in lock_state:
nuki_doorstate = lock_state['doorsensorState']
if 'batteryCritical' in lock_state:
nuki_battery = 0 if not lock_state['batteryCritical'] else 1

for item, key in nuki_event_items.items():
if key == nuki_id:
item(nuki_state, 'NUKI')
for item, key in nuki_door_items.items():
if key == nuki_id:
item(nuki_doorstate, 'NUKI')
for item, key in nuki_battery_items.items():
if key == nuki_id:
item(nuki_battery, 'NUKI')


@staticmethod
def update_lock_state(nuki_id, lock_state):

Expand Down Expand Up @@ -244,6 +272,20 @@ def _register_callback(self):
"Plugin '{}': No callback ip set. Automatic Nuki lock status updates not available.".format
(self.get_shortname()))

def _get_nuki_status_via_list(self):
self.logger.info("Plugin '{}': Getting Nuki status ...".format
(self.get_shortname()))

response = self._api_call(self._base_url, endpoint='list', token=self._token,
no_wait=self._noWait)
if response is None:
self.logger.info("Plugin '{}': Getting Nuki status ... Response is None.".format(self.get_shortname()))
return
for nuki_id in paired_nukis:
for nuki_data in response:
if nuki_data['nukiId'] == int(nuki_id):
Nuki.update_lock_state_via_list(nuki_id, nuki_data)

def _get_nuki_status(self):
self.logger.info("Plugin '{}': Getting Nuki status ...".format
(self.get_shortname()))
Expand Down Expand Up @@ -387,7 +429,6 @@ def index(self):
self.plugin.logger.debug(
"Plugin '{pluginname}' - NukiWebServiceInterface: Status Smartlock: ID: {nuki_id} Status: {state_name}".
format(pluginname=self.plugin.get_shortname(), nuki_id=nuki_id, state_name=state_name))

Nuki.update_lock_state(nuki_id, input_json)
except Exception as err:
self.plugin.logger.error(
Expand Down
2 changes: 1 addition & 1 deletion nuki/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugin:
# documentation: https://github.com/smarthomeNG/smarthome/wiki/CLI-Plugin # url of documentation (wiki) page
support: https://knx-user-forum.de/node/1052437

version: 1.6.1 # Plugin version
version: 1.6.2 # Plugin version
sh_minversion: 1.9.0 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
multi_instance: False # plugin supports multi instance
Expand Down

0 comments on commit d0d2441

Please sign in to comment.