Skip to content

Commit 7ef8f82

Browse files
committed
Test joins through a specific device and fix addressing bug
1 parent ffaa197 commit 7ef8f82

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
- id: debug-statements
66

77
- repo: https://github.com/psf/black
8-
rev: 22.1.0
8+
rev: 22.3.0
99
hooks:
1010
- id: black
1111

tests/application/test_joining.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,41 @@ async def test_join_coordinator(device, make_application):
101101
await app.shutdown()
102102

103103

104+
@pytest.mark.parametrize("device", FORMED_DEVICES)
105+
async def test_join_device(device, make_application):
106+
ieee = t.EUI64.convert("EC:1B:BD:FF:FE:54:4F:40")
107+
nwk = 0x1234
108+
109+
app, znp_server = await make_application(server_cls=device)
110+
device = app.add_initialized_device(ieee=ieee, nwk=nwk)
111+
112+
permit_join = znp_server.reply_once_to(
113+
request=c.ZDO.MgmtPermitJoinReq.Req(
114+
AddrMode=t.AddrMode.NWK, Dst=nwk, Duration=60, partial=True
115+
),
116+
responses=[
117+
c.ZDO.MgmtPermitJoinReq.Rsp(Status=t.Status.SUCCESS),
118+
c.ZDO.MgmtPermitJoinRsp.Callback(Src=nwk, Status=t.ZDOStatus.SUCCESS),
119+
c.ZDO.MsgCbIncoming.Callback(
120+
Src=nwk,
121+
IsBroadcast=t.Bool.false,
122+
ClusterId=32822,
123+
SecurityUse=0,
124+
TSN=7,
125+
MacDst=0x0000,
126+
Data=b"\x00",
127+
),
128+
],
129+
)
130+
131+
await app.startup(auto_form=False)
132+
await app.permit(node=ieee)
133+
134+
await permit_join
135+
136+
await app.shutdown()
137+
138+
104139
@pytest.mark.parametrize("device", FORMED_ZSTACK3_DEVICES)
105140
@pytest.mark.parametrize("permit_result", [None, asyncio.TimeoutError()])
106141
async def test_permit_join_with_key(device, permit_result, make_application, mocker):

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def connection_made(self):
11111111
class BaseLaunchpadCC26X2R1(BaseZStack3Device):
11121112
version = 3.30
11131113
align_structs = True
1114-
code_revision = 20200805
1114+
code_revision = 20220219
11151115

11161116
def _create_network_nvram(self):
11171117
super()._create_network_nvram()

zigpy_znp/types/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def __init__(self, *, partial=False, **params):
345345
and not issubclass(param.type, enum.Enum),
346346

347347
isinstance(value, bytes)
348-
and issubclass(param.type, (t.ShortBytes, t.LongBytes)),
348+
and issubclass(param.type, (t.ShortBytes, t.LongBytes, t.Bytes)),
349349

350350
isinstance(value, list) and issubclass(param.type, list),
351351
isinstance(value, bool) and issubclass(param.type, t.Bool),

zigpy_znp/zigbee/application.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,13 @@ async def _send_request_raw(
12361236
# addressing another device. The router will receive the ZDO request and a
12371237
# device will try to join, but Z-Stack will never send the network key.
12381238
if cluster == zdo_t.ZDOCmd.Mgmt_Permit_Joining_req:
1239+
if dst_addr.mode == t.AddrMode.Broadcast:
1240+
# The coordinator responds to broadcasts
1241+
permit_addr = 0x0000
1242+
else:
1243+
# Otherwise, the destination device responds
1244+
permit_addr = dst_addr.address
1245+
12391246
await self._znp.request_callback_rsp(
12401247
request=c.ZDO.MgmtPermitJoinReq.Req(
12411248
AddrMode=dst_addr.mode,
@@ -1244,7 +1251,9 @@ async def _send_request_raw(
12441251
TCSignificance=data[2],
12451252
),
12461253
RspStatus=t.Status.SUCCESS,
1247-
callback=c.ZDO.MgmtPermitJoinRsp.Callback(Src=0x0000, partial=True),
1254+
callback=c.ZDO.MgmtPermitJoinRsp.Callback(
1255+
Src=permit_addr, partial=True
1256+
),
12481257
)
12491258
# Internally forward ZDO requests destined for the coordinator back to zigpy
12501259
# so we can send internal Z-Stack requests when necessary

0 commit comments

Comments
 (0)