From fc4a131ed0ca1536991ec403a75b8ecdfc221acd Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 26 Sep 2023 21:45:22 -0400 Subject: [PATCH] Implement `permit_with_link_key` (#226) --- zigpy_znp/zigbee/application.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/zigpy_znp/zigbee/application.py b/zigpy_znp/zigbee/application.py index 5f92a797..46ef99ed 100644 --- a/zigpy_znp/zigbee/application.py +++ b/zigpy_znp/zigbee/application.py @@ -343,22 +343,20 @@ async def force_remove(self, dev: zigpy.device.Device) -> None: # Z-Stack does not have any way to do this - async def permit_with_key(self, node: t.EUI64, code: bytes, time_s=60): + async def permit_with_link_key( + self, node: t.EUI64, link_key: t.KeyData, time_s: int = 60 + ) -> None: """ - Permits a new device to join with the given IEEE and Install Code. + Permits a new device to join with the given IEEE and link key. """ - key = zigpy.util.convert_install_code(code) - install_code_format = c.app_config.InstallCodeFormat.KeyDerivedFromInstallCode - - if key is None: - raise ValueError(f"Invalid install code: {code!r}") - await self._znp.request( c.AppConfig.BDBAddInstallCode.Req( - InstallCodeFormat=install_code_format, + InstallCodeFormat=( + c.app_config.InstallCodeFormat.KeyDerivedFromInstallCode + ), IEEE=node, - InstallCode=t.Bytes(key), + InstallCode=link_key.serialize(), ), RspStatus=t.Status.SUCCESS, ) @@ -384,6 +382,18 @@ async def permit_with_key(self, node: t.EUI64, code: bytes, time_s=60): RspStatus=t.Status.SUCCESS, ) + async def permit_with_key(self, node: t.EUI64, code: bytes, time_s=60): + """ + Permits a new device to join with the given IEEE and Install Code. + """ + + key = zigpy.util.convert_install_code(code) + + if key is None: + raise ValueError(f"Invalid install code: {code!r}") + + await self.permit_with_link_key(node=node, link_key=key, time_s=time_s) + async def _move_network_to_channel( self, new_channel: int, new_nwk_update_id: int ) -> None: