Skip to content

Commit eff5c0c

Browse files
committed
Fix bug that prevented the coordinator from permitting joins
1 parent b1ded73 commit eff5c0c

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

tests/application/test_joining.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,29 @@ async def test_permit_join(device, fixed_joining_bug, mocker, make_application):
6666
await app.shutdown()
6767

6868

69+
@pytest.mark.parametrize("device", FORMED_DEVICES)
70+
async def test_join_coordinator(device, make_application):
71+
app, znp_server = make_application(server_cls=device)
72+
73+
# Handle us opening joins on the coordinator
74+
permit_join_coordinator = znp_server.reply_once_to(
75+
request=c.ZDO.MgmtPermitJoinReq.Req(
76+
AddrMode=t.AddrMode.NWK, Dst=0x0000, Duration=60, partial=True
77+
),
78+
responses=[
79+
c.ZDO.MgmtPermitJoinReq.Rsp(Status=t.Status.SUCCESS),
80+
c.ZDO.MgmtPermitJoinRsp.Callback(Src=0x0000, Status=t.ZDOStatus.SUCCESS),
81+
],
82+
)
83+
84+
await app.startup(auto_form=False)
85+
await app.permit(node=app.ieee)
86+
87+
await permit_join_coordinator
88+
89+
await app.shutdown()
90+
91+
6992
@pytest.mark.parametrize("device", FORMED_ZSTACK3_DEVICES)
7093
@pytest.mark.parametrize("permit_result", [None, asyncio.TimeoutError()])
7194
async def test_permit_join_with_key(device, permit_result, make_application, mocker):

zigpy_znp/zigbee/application.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def model(self):
100100
model = "CC2538" if self.application._znp.nvram.align_structs else "CC2531"
101101
version = "Home 1.2" if self.application._znp.version == 1.2 else "3.0.x"
102102

103-
build = self.application._version_rsp.CodeRevision
104-
105-
return f"{model}, Z-Stack {version} (build {build})"
103+
return f"{model}, Z-Stack {version} (build {self.application._zstack_build_id})"
106104

107105

108106
class ControllerApplication(zigpy.application.ControllerApplication):
@@ -328,7 +326,7 @@ async def _startup(self, auto_form=False, force_form=False, read_only=False):
328326
LOGGER.info("Network settings")
329327
LOGGER.info(" Model: %s", self.zigpy_device.model)
330328
LOGGER.info(" Z-Stack version: %s", self._znp.version)
331-
LOGGER.info(" Z-Stack build id: %s", self._version_rsp.CodeRevision)
329+
LOGGER.info(" Z-Stack build id: %s", self._zstack_build_id)
332330
LOGGER.info(" Max concurrent requests: %s", max_concurrent_requests)
333331
LOGGER.info(" Channel: %s", self.channel)
334332
LOGGER.info(" PAN ID: 0x%04X", self.pan_id)
@@ -704,10 +702,11 @@ async def permit(self, time_s=60, node=None):
704702

705703
# If joins were permitted through a specific router, older Z-Stack builds
706704
# did not allow the key to be distributed unless the coordinator itself was
707-
# also permitting joins.
705+
# also permitting joins. This also needs to happen if we're permitting joins
706+
# through the coordinator itself.
708707
#
709708
# Fixed in https://github.com/Koenkk/Z-Stack-firmware/commit/efac5ee46b9b437
710-
if time_s == 0 or self._version_rsp.CodeRevision < 20210708:
709+
if time_s == 0 or self._zstack_build_id < 20210708 or node == self.ieee:
711710
response = await self._znp.request_callback_rsp(
712711
request=c.ZDO.MgmtPermitJoinReq.Req(
713712
AddrMode=t.AddrMode.NWK,
@@ -979,6 +978,14 @@ async def on_af_message(self, msg: c.AF.IncomingMsg.Callback) -> None:
979978
# Internal methods #
980979
####################
981980

981+
@property
982+
def _zstack_build_id(self) -> t.uint32_t:
983+
"""
984+
Z-Stack build ID, more recently the build date.
985+
"""
986+
987+
return self._version_rsp.CodeRevision
988+
982989
@property
983990
def zigpy_device(self) -> zigpy.device.Device:
984991
"""

0 commit comments

Comments
 (0)