pschmitt / pynuki Goto Github PK
View Code? Open in Web Editor NEWPython bindings for nuki.io bridges
Home Page: https://pypi.org/project/pynuki/
License: GNU General Public License v3.0
Python bindings for nuki.io bridges
Home Page: https://pypi.org/project/pynuki/
License: GNU General Public License v3.0
Hi @pschmitt, I'm seeing these errors in my HA logs, and the lock is no longer available in HA until I restart the HA server. The opener continues to work just fine.
This is with pynuki 1.3.7 and homeassistant-0.110.1.
Thanks!
may 22 00:33:24 hass hass[170685]: 2020-05-22 00:33:24 INFO (SyncWorker_2) [pynetgear] Get attached devices
may 22 00:33:35 hass hass[170685]: 2020-05-22 00:33:35 INFO (SyncWorker_3) [pynetgear] Get attached devices
may 22 00:33:46 hass hass[170685]: 2020-05-22 00:33:46 INFO (SyncWorker_3) [pynetgear] Get attached devices
may 22 00:33:48 hass hass[170685]: 2020-05-22 00:33:48 ERROR (MainThread) [homeassistant.helpers.entity] Update for lock.hodor fails
may 22 00:33:48 hass hass[170685]: Traceback (most recent call last):
may 22 00:33:48 hass hass[170685]: File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
may 22 00:33:48 hass hass[170685]: await self.async_device_update()
may 22 00:33:48 hass hass[170685]: File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 472, in async_device_update
may 22 00:33:48 hass hass[170685]: await self.hass.async_add_executor_job(self.update)
may 22 00:33:48 hass hass[170685]: File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
may 22 00:33:48 hass hass[170685]: result = self.fn(*self.args, **self.kwargs)
may 22 00:33:48 hass hass[170685]: File "/home/homeassistant/.homeassistant/custom_components/nuki/lock.py", line 124, in update
may 22 00:33:48 hass hass[170685]: self._nuki_device.update(aggressive=level)
may 22 00:33:48 hass hass[170685]: File "/srv/homeassistant/lib/python3.8/site-packages/pynuki/device.py", line 89, in update
may 22 00:33:48 hass hass[170685]: assert data, (
may 22 00:33:48 hass hass[170685]: AssertionError: Failed to update data for lock. Nuki ID None volatized.
No idea if this goes here. But i get an error with the nuki opener. As far as i could read from a HA forum post by you, you don't have one? If i can test stuff for you, please do tell. The error is as follows.
404 Client Error: Not Found for url: http://[MYip]:8080/lockAction?token=[MyToken]&nukiId=[MyNukiID]&action=3&noWait=1
Nuki Bridge HTTP API V1.13.1 introduced 2 new device types, which the actual version does not support. As I found out, the implementation of Nuki integration in Home Assistant relies on your work, so probably update this library will fix the issues in HA ... thank you!
https://developer.nuki.io/page/nuki-bridge-http-api-1-13/4/
Nuki device type
0 => smartlock (Nuki Smart Lock 1.0/2.0)
2 => opener (Nuki Opener)
3 => smartdoor (Nuki Smart Door)
4 => smartlock 3 (Nuki Smart Lock 3.0 (Pro))
My Python skills are not good enough to supply a complete fix, but this could be a simple option. A better option would be to add an array that contains all supported device types, but that's probably more complicated...
pynuki/constants.py
After line 22, add:
DEVICE_TYPE_SMARTDOOR = 3
DEVICE_TYPE_NEWLOCK = 4
pynuki/bridge.py
After Line 218, add
elif dev_type == const.DEVICE_TYPE_NEWLOCK:
//modify data that device_data.get("deviceType") gives back 2 instead of 3 ... no idea how that is done in Phyton :-(
dev = NukiLock(self, data)
elif dev_type == const.DEVICE_TYPE_NEWLOCK:
//modify data that device_data.get("deviceType") gives back 2 instead of 4 ...no idea how that is done in Phyton :-(
dev = NukiLock(self, data)
Logger: homeassistant.helpers.entity
Source: components/nuki/lock.py:124
First occurred: 11:40:21 (377 occurrences)
Last logged: 14:56:51
Update for lock.porta fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 472, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/nuki/lock.py", line 124, in update
self._nuki_device.update(aggressive=level)
File "/usr/local/lib/python3.7/site-packages/pynuki/device.py", line 90, in update
"Failed to update data for lock. "
AssertionError: Failed to update data for lock. Nuki ID None volatized.
Code states: Based on the Bridge API version 1.5
Latest version of the http API is 1.7 (30-3-2018):
https://developer.nuki.io/page/nuki-bridge-http-api-170/4/
Changelog says that since 1.5 has been added: bridge discovery
https://developer.nuki.io/page/nuki-bridge-http-api-170/4/#heading--bridge-discovery
The problem seems to be in _get_devices() where the condition on self.list(device_type=device_type) is ignored when device_type is 0.
It works properly for openers(), returning just devices of device_type 2.
I've just updated Home Assistant to latest version (0.111), and now the Nuki lock is not detected (connected to Android Nuki bridge).
I've seen that bridge.locks is empty, due to the software bridge doesn't return "deviceType" in list command and then is append as a NukiDevice to the devices list.
[{"nukiId":XXXXXX"name":"Cerradura","lastKnownState":{"state":1,"stateName":"locked","batteryCritical":false,"timestamp":"2020-06-11T07:26:03+02:00"}}]
So, I think for backwards compatibility, if there is no "deviceType" when retrieving _get_devices, it should be created as NukiLock instead of a NukiDevice.
What do you think?
As far as I can tell this library is using a polling mechanism to get the lockState. As the resource from the bridge are limited this often results in 503 errors. A better approach would be to use the callback mechanism. You can set an endpoint which the bridge calls when a change in state has been detected. This is more reliable, gives faster feedback and reduces the network traffic and load on the bridge.
https://developer.nuki.io/page/nuki-bridge-http-api-1-12/4#heading--callback
It would be a big improvement to have this in Home Assistant.
If you know any javascript you could have a look at this library which was initially developed by me and uses the callbacks: https://github.com/pfreguia/nuki.homey . I can answer questions about this all but I dont know Phyton so I cant actually code it.
Hashed tokens are deprecated.
See https://developer.nuki.io/t/bridge-beta-fw-1-22-1-2-14-0-with-new-encrypted-bridge-http-api-token/15816
I have a Nuki-Lock and a Nuki-Bridge connected to Home Assistant.
{
"bridgeType":1,
"ids":{
"hardwareId": ####,
"serverId": ####
},
"versions":{
"firmwareVersion":"2.14.0",
"wifiFirmwareVersion":"2.3.0"
},
"uptime":43432,
"currentTime":"2022-07-30T06:35:40+00:00",
"wlanConnected":true,
"serverConnected":true,
"scanResults":[
{
"deviceType":4,
"nukiId": ####,
"name":"Nuki_####",
"rssi":-50,
"paired":true
}
]
}
But at some time, pynuki wasnt able to call the api due to an invalid token... after some investigation i found out, that the line:
Line 94 in 22433b3
Line 96 in 22433b3
Unfortunately i cannot disable "secure"-tokens via Home Assistant.. but on the other hand it would be fine if i know why hased tokens don't work on my setup (and how i can fix that)... now everytime pynuki get's updated, i need to "patch" it to get my setup work again.
Thanks in advance,
Benedikt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.