ronengr / hass_nuki_bt

Control Nuki Lock over bluetooth
MIT License
39 stars 8 forks source link

Error pairing Nuki 4 (non-pro) #49

Closed waffelmaik closed 6 months ago

waffelmaik commented 7 months ago

System Health details

System Information

version core-2024.4.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.6.25-haos
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1469 Downloaded Repositories | 6
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | 4. Mai 2024 um 02:00 relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | false remote_server | eu-central-1-9.ui.nabu.casa certificate_status | ready instance_id | 0e1b1468c2ef4294b850d631b3be47c0 can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.2 -- | -- update_channel | stable supervisor_version | supervisor-2024.04.0 agent_version | 1.6.0 docker_version | 25.0.5 disk_total | 30.8 GB disk_used | 11.1 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.4.0), Terminal & SSH (9.13.0), File editor (5.8.0), chrony (3.0.1), Piper (1.5.0), Whisper (2.0.0), Matter Server (5.5.1), OpenThread Border Router (2.5.1)
Dashboards dashboards | 3 -- | -- resources | 1 views | 2 mode | storage
Recorder oldest_recorder_run | 12. April 2024 um 18:33 -- | -- current_recorder_run | 22. April 2024 um 09:43 estimated_db_size | 346.64 MiB database_engine | sqlite database_version | 3.44.2

Checklist

Describe the issue

I have two nuki 4 (non-pro). Both are automatically discovered by nuki_bt and on first look I'm able to pair them in bridge mode. But the Integration is not properly working afterwards. ha_error

The system is running on a proxmox host with USB passthrough of a TP-Link TP-JmJk UB500 adapter.

Reproduction steps

  1. connect bluetooth dongle and reboot
  2. make sure bluetooth is working
  3. add repo and download addon in HACS
  4. restart HA, Nukis are detected
  5. click configure, type in nuki PIN, set lock to pairing mode and configure it in automatic mode
  6. integration seems to start but errors out

Debug logs

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: custom_components.hass_nuki_bt
Quelle: components/bluetooth/active_update_coordinator.py:131
Integration: Nuki Türöffner (Dokumentation, Probleme)
Erstmals aufgetreten: 09:45:29 (2 Vorkommnisse)
Zuletzt protokolliert: 10:11:56

54:D2:72:0A:15:8D: Failure while polling
54:D2:72:AC:45:FD: Failure while polling
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 366, in _send_command
    msg = await self._notify_future
          ^^^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/active_update_coordinator.py", line 131, in _async_poll
    self.data = await self._async_poll_data(self._last_service_info)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/active_update_coordinator.py", line 124, in _async_poll_data
    return await self._poll_method(last_service_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hass_nuki_bt/coordinator.py", line 110, in _async_update
    await self.device.update_state()
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 440, in update_state
    await self.update_config()
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 496, in update_config
    msg = await self._send_encrtypted_command(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 193, in _send_encrtypted_command
    return await self._send_command(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 365, in _send_command
    async with async_timeout.timeout(self.command_response_timeout):
  File "/usr/local/lib/python3.12/site-packages/async_timeout/__init__.py", line 141, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.12/site-packages/async_timeout/__init__.py", line 228, in _do_exit
    raise asyncio.TimeoutError
TimeoutError

_________________________________________________________________________

Logger: homeassistant
Quelle: /usr/src/homeassistant/homeassistant/runner.py:146
Erstmals aufgetreten: 09:45:31 (2 Vorkommnisse)
Zuletzt protokolliert: 10:11:58

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 272, in _notification_handler
    msg = self._parse_message(bytes(data), encrypted)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/nuki.py", line 206, in _parse_message
    msg = self._const.NukiMessage.parse(self._decrypt_message(data))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 288, in parse
    return self.parse_stream(io.BytesIO(data), **contextkw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 300, in parse_stream
    return self._parsereport(stream, context, "(parsing)")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 2120, in _parse
    subobj = sc._parsereport(stream, context, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 2653, in _parse
    return self.subcon._parsereport(stream, context, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyNukiBT/const.py", line 948, in _parse
    hash1 = self.checksumfield._parsereport(stream, context, path)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 1041, in _parse
    data = stream_read(stream, self.length, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/construct/core.py", line 91, in stream_read
    raise StreamError("stream read less than specified amount, expected %d, found %d" % (length, len(data)), path=path)
construct.core.StreamError: Error in path (parsing) -> crc
stream read less than specified amount, expected 2, found 1

_________________________________________________________________________

Logger: homeassistant.config_entries
Quelle: config_entries.py:551
Erstmals aufgetreten: 09:45:31 (2 Vorkommnisse)
Zuletzt protokolliert: 10:11:58

Error setting up entry Nuki_3A0A158D for hass_nuki_bt
Error setting up entry Nuki_39AC45FD for hass_nuki_bt
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hass_nuki_bt/__init__.py", line 86, in async_setup_entry
    if not await coordinator.async_wait_ready():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hass_nuki_bt/coordinator.py", line 152, in async_wait_ready
    await self._async_update()
  File "/config/custom_components/hass_nuki_bt/coordinator.py", line 117, in _async_update
    if logs[0].type == NukiConst.LogEntryType.LOCK_ACTION:
       ~~~~^^^
IndexError: list index out of range

Diagnostics dump

No response

mycanaletto commented 7 months ago

Hello,

I have a Nuki 4 Pro without a bridge. HA can't see it, neither in manual nor in discovery (wifi on or off).

I have BT proxy all over the place....

Help !

ronengr commented 6 months ago

@waffelmaik there is a known issue with getting config info from nuki 4 a workaround was introduced in version 0.0.12 that allows nuki 4 to work without getting the config info. please let me know if you are still experiencing issues after upgrading to latest version of hass_nuki_bt

ronengr commented 6 months ago

@mycanaletto I'm sorry but i'm not that familiar with nuki4, so my ability to help is limited. As far as I know, nuki 4 pro should have BT, so theoretically this should work. are you able to control the lock from the phone when WIFI is off?

If you have the BT address of the device you can try to add it manually. maybe Nuki changed the BT name in 4pro so auto discover doesn't work if you have a way to list BT devices in the area and see the BT address and name of the nuki, that could be helpfull

mycanaletto commented 6 months ago

@mycanaletto I'm sorry but i'm not that familiar with nuki4, so my ability to help is limited. As far as I know, nuki 4 pro should have BT, so theoretically this should work. are you able to control the lock from the phone when WIFI is off?

If you have the BT address of the device you can try to add it manually. maybe Nuki changed the BT name in 4pro so auto discover doesn't work if you have a way to list BT devices in the area and see the BT address and name of the nuki, that could be helpfull

Thanks all the same. I ended up using ESP with Nuki Hub and it works fine.

waffelmaik commented 6 months ago

I fiddled around with it a little more and now I figured that when I try to pair it without providing a PIN it works. When typing the PIN during setup it still errors out the way as shown above. It never occurred to me, to try without PIN so I can not tell you if this would have worked prior 0.0.12. Since I’m not missing any features this way it would be fine from my side, but nevertheless there still seems to be some kind of bug.

Best regards

ronengr commented 6 months ago

@waffelmaik Thanks. I think i found the bug and am working on a fix.

Currently the only use of the PIN is to get the "Last action user name" (Who did the last lock/unlock operation). but hopefully later I will add some more functionality that requires the PIN (like the ability to add users to the lock etc).