Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joining with link key #150

Merged
merged 4 commits into from
Oct 1, 2023
Merged

Joining with link key #150

merged 4 commits into from
Oct 1, 2023

Conversation

Shulyaka
Copy link
Contributor

Add support for device joining via install codes.

Successful logs:

INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script
INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service
DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=zha, service=permit, service_data=duration=60, install_code=C9A7D2441A711695CD62170D3328EA2B423D, source_ieee=0013A200419823F9>
INFO (MainThread) [homeassistant.components.zha.websocket_api] Allowing join for 00:13:a2:00:41:98:23:f9 device with install code
DEBUG (MainThread) [zigpy_xbee.api] at command: KT (60,)
DEBUG (MainThread) [zigpy_xbee.api] Command at (b'KT', b'\x00<')
DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x082KT\x00<'
DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x882KT\x00'
DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
DEBUG (MainThread) [zigpy_xbee.api] Command register_joining_device (00:13:a2:00:41:98:23:f9, 65534, 1, b'\xc9\xa7\xd2D\x1aq\x16\x95\xcdb\x17\r3(\xea+B=')
DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'$3\x00\x13\xa2\x00A\x98#\xf9\xff\xfe\x01\xc9\xa7\xd2D\x1aq\x16\x95\xcdb\x17\r3(\xea+B='
DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\xa43\x00'
DEBUG (MainThread) [zigpy_xbee.api] Frame received: registration_status
DEBUG (MainThread) [zigpy_xbee.api] Registration Status: SUCCESS

Unsuccessful logs (invalid IEEE provided):

INFO [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script
INFO [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service
DEBUG [homeassistant.core] Bus:Handling <Event call_service[L]: domain=zha, service=permit, service_data=duration=60, source_ieee=0000000000000000, install_code=C9A7D2441A711695CD62170D3328EA2B423D>
INFO [homeassistant.components.zha.websocket_api] Allowing join for 00:00:00:00:00:00:00:00 device with install code
DEBUG [zigpy_xbee.api] at command: KT (60,)
DEBUG [zigpy_xbee.api] Command at (b'KT', b'\x00<')
DEBUG [zigpy_xbee.uart] Sending: b'\x085KT\x00<'
DEBUG [zigpy_xbee.uart] Frame received: b'\x885KT\x00'
DEBUG [zigpy_xbee.api] Frame received: at_response
DEBUG [zigpy_xbee.api] Command register_joining_device (00:00:00:00:00:00:00:00, 65534, 1, b'\xc9\xa7\xd2D\x1aq\x16\x95\xcdb\x17\r3(\xea+B=')
DEBUG [zigpy_xbee.uart] Sending: b'$6\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfe\x01\xc9\xa7\xd2D\x1aq\x16\x95\xcdb\x17\r3(\xea+B='
DEBUG [zigpy_xbee.uart] Frame received: b'\xa46\xb3'
DEBUG [zigpy_xbee.api] Frame received: registration_status
ERROR [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Registration Status: INVALID_ADDRESS
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/core.py", line 1969, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/core.py", line 2006, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 980, in admin_handler
    await result
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/zha/websocket_api.py", line 1256, in permit
    await application_controller.permit_with_key(
  File "/srv/homeassistant/lib/python3.11/site-packages/zigpy_xbee/zigbee/application.py", line 304, in permit_with_key
    await self._api.register_joining_device(node, reserved, key_type, code)
RuntimeError: Registration Status: INVALID_ADDRESS

@Shulyaka Shulyaka changed the title Joining with install code support Joining with install code Sep 26, 2023
@codecov
Copy link

codecov bot commented Oct 1, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (098b19c) 99.87% compared to head (d1b4cd2) 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##              dev      #150      +/-   ##
===========================================
+ Coverage   99.87%   100.00%   +0.12%     
===========================================
  Files           6         6              
  Lines         807       830      +23     
===========================================
+ Hits          806       830      +24     
+ Misses          1         0       -1     
Files Coverage Δ
zigpy_xbee/api.py 100.00% <100.00%> (ø)
zigpy_xbee/zigbee/application.py 100.00% <100.00%> (+0.44%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@puddly
Copy link
Contributor

puddly commented Oct 1, 2023

For this PR, I'm hoping to implement zigpy/zigpy#1261, since the install code can be converted into a link key before getting to the radio library. It looks like XBee implements both at the moment with a simple enum to swap between the two?

I think it's enough to just implement joining with a key and provide a stub implementation of the old method.

For comparison, here's a PR for zigpy-znp implementing this: https://github.com/zigpy/zigpy-znp/pull/226/files

I'll make a PR removing the stub from radio libraries in the future.

@Shulyaka
Copy link
Contributor Author

Shulyaka commented Oct 1, 2023

Yes, XBee supports both link keys and install codes, converting the code to the key on device.
I will update the PR.

@Shulyaka Shulyaka marked this pull request as draft October 1, 2023 18:15
@Shulyaka
Copy link
Contributor Author

Shulyaka commented Oct 1, 2023

Done.
When a default permit_with_key method is implemented, we can delete the xbee method (and the key_type argument).

@Shulyaka Shulyaka marked this pull request as ready for review October 1, 2023 20:07
@Shulyaka Shulyaka changed the title Joining with install code Joining with link key Oct 1, 2023
@puddly puddly merged commit 53d516c into zigpy:dev Oct 1, 2023
14 checks passed
@Shulyaka Shulyaka deleted the install_code branch October 1, 2023 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants