Skip to content

Commit

Permalink
Implement permit_with_link_key (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Sep 27, 2023
1 parent d6c39ea commit fc4a131
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions zigpy_znp/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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:
Expand Down

0 comments on commit fc4a131

Please sign in to comment.