|
4 | 4 | import zigpy.zdo
|
5 | 5 | import zigpy.endpoint
|
6 | 6 | import zigpy.profiles
|
7 |
| -from zigpy.zdo.types import ZDOCmd |
| 7 | +import zigpy.zdo.types as zdo_t |
8 | 8 | from zigpy.exceptions import DeliveryError
|
9 | 9 |
|
10 | 10 | import zigpy_znp.types as t
|
11 | 11 | import zigpy_znp.config as conf
|
12 | 12 | import zigpy_znp.commands as c
|
13 | 13 | from zigpy_znp.exceptions import InvalidCommandResponse
|
14 | 14 |
|
15 |
| -from ..conftest import FORMED_DEVICES, CoroutineMock, FormedLaunchpadCC26X2R1 |
| 15 | +from ..conftest import ( |
| 16 | + FORMED_DEVICES, |
| 17 | + CoroutineMock, |
| 18 | + FormedLaunchpadCC26X2R1, |
| 19 | + zdo_request_matcher, |
| 20 | + serialize_zdo_command, |
| 21 | +) |
16 | 22 |
|
17 | 23 |
|
18 | 24 | @pytest.mark.parametrize("device", FORMED_DEVICES)
|
@@ -177,52 +183,6 @@ async def test_request_addr_mode(device, addr, make_application, mocker):
|
177 | 183 | await app.shutdown()
|
178 | 184 |
|
179 | 185 |
|
180 |
| -@pytest.mark.parametrize("device", FORMED_DEVICES) |
181 |
| -@pytest.mark.parametrize("status", [t.ZDOStatus.SUCCESS, t.ZDOStatus.TIMEOUT, None]) |
182 |
| -async def test_remove(device, make_application, status, mocker): |
183 |
| - app, znp_server = make_application(server_cls=device) |
184 |
| - app._config[conf.CONF_ZNP_CONFIG][conf.CONF_ARSP_TIMEOUT] = 0.1 |
185 |
| - |
186 |
| - # Only zigpy>=0.29.0 has this method |
187 |
| - if hasattr(app, "_remove_device"): |
188 |
| - mocker.spy(app, "_remove_device") |
189 |
| - |
190 |
| - await app.startup(auto_form=False) |
191 |
| - device = app.add_initialized_device(ieee=t.EUI64(range(8)), nwk=0xAABB) |
192 |
| - |
193 |
| - responses = [c.ZDO.MgmtLeaveReq.Rsp(Status=t.Status.SUCCESS)] |
194 |
| - |
195 |
| - if status is not None: |
196 |
| - responses.append(c.ZDO.MgmtLeaveRsp.Callback(Src=0x0000, Status=status)) |
197 |
| - |
198 |
| - # Normal ZDO leave must fail |
199 |
| - normal_remove_req = znp_server.reply_once_to( |
200 |
| - request=c.ZDO.MgmtLeaveReq.Req( |
201 |
| - DstAddr=device.nwk, IEEE=device.ieee, partial=True |
202 |
| - ), |
203 |
| - responses=[ |
204 |
| - c.ZDO.MgmtLeaveReq.Rsp(Status=t.Status.SUCCESS), |
205 |
| - c.ZDO.MgmtLeaveRsp.Callback(Src=device.nwk, Status=t.ZDOStatus.TIMEOUT), |
206 |
| - ], |
207 |
| - ) |
208 |
| - |
209 |
| - # Make sure the device exists |
210 |
| - assert app.get_device(nwk=device.nwk) is device |
211 |
| - |
212 |
| - await app.remove(device.ieee) |
213 |
| - await normal_remove_req |
214 |
| - |
215 |
| - if hasattr(app, "_remove_device"): |
216 |
| - # Make sure the device is going to be removed |
217 |
| - assert app._remove_device.call_count == 1 |
218 |
| - else: |
219 |
| - # Make sure the device is gone |
220 |
| - with pytest.raises(KeyError): |
221 |
| - app.get_device(ieee=device.ieee) |
222 |
| - |
223 |
| - await app.shutdown() |
224 |
| - |
225 |
| - |
226 | 186 | @pytest.mark.parametrize("device", FORMED_DEVICES)
|
227 | 187 | async def test_mrequest(device, make_application, mocker):
|
228 | 188 | app, znp_server = make_application(server_cls=device)
|
@@ -274,25 +234,6 @@ async def test_mrequest_doesnt_block(device, make_application, event_loop):
|
274 | 234 | await app.shutdown()
|
275 | 235 |
|
276 | 236 |
|
277 |
| -@pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1]) |
278 |
| -async def test_unimplemented_zdo_converter(device, make_application, mocker): |
279 |
| - app, znp_server = make_application(server_cls=device) |
280 |
| - await app.startup() |
281 |
| - |
282 |
| - with pytest.raises(RuntimeError): |
283 |
| - await zigpy.zdo.broadcast( |
284 |
| - app, |
285 |
| - ZDOCmd.Remove_node_cache_req, |
286 |
| - 0x0000, |
287 |
| - 0x00, |
288 |
| - t.NWK(0x1234), |
289 |
| - t.EUI64.convert("11:22:33:44:55:66:77:88"), |
290 |
| - broadcast_address=0xFFFC, |
291 |
| - ) |
292 |
| - |
293 |
| - await app.shutdown() |
294 |
| - |
295 |
| - |
296 | 237 | @pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1])
|
297 | 238 | async def test_broadcast(device, make_application, mocker):
|
298 | 239 | app, znp_server = make_application(server_cls=device)
|
@@ -595,28 +536,46 @@ def set_route_discovered(req):
|
595 | 536 | return c.ZDO.ExtRouteDisc.Rsp(Status=t.Status.SUCCESS)
|
596 | 537 |
|
597 | 538 | znp_server.reply_to(
|
598 |
| - c.ZDO.ExtRouteChk.Req(Dst=device.nwk, partial=True), |
| 539 | + request=c.ZDO.ExtRouteChk.Req(Dst=device.nwk, partial=True), |
599 | 540 | responses=[route_replier],
|
600 | 541 | override=True,
|
601 | 542 | )
|
602 | 543 |
|
603 | 544 | was_route_discovered = znp_server.reply_once_to(
|
604 |
| - c.ZDO.ExtRouteDisc.Req( |
| 545 | + request=c.ZDO.ExtRouteDisc.Req( |
605 | 546 | Dst=device.nwk, Options=c.zdo.RouteDiscoveryOptions.UNICAST, partial=True
|
606 | 547 | ),
|
607 | 548 | responses=[set_route_discovered],
|
608 | 549 | )
|
609 | 550 |
|
610 | 551 | zdo_req = znp_server.reply_once_to(
|
611 |
| - c.ZDO.ActiveEpReq.Req(DstAddr=device.nwk, NWKAddrOfInterest=device.nwk), |
| 552 | + request=zdo_request_matcher( |
| 553 | + dst_addr=t.AddrModeAddress(t.AddrMode.NWK, device.nwk), |
| 554 | + command_id=zdo_t.ZDOCmd.Active_EP_req, |
| 555 | + TSN=7, |
| 556 | + zdo_NWKAddrOfInterest=device.nwk, |
| 557 | + ), |
612 | 558 | responses=[
|
613 |
| - c.ZDO.ActiveEpReq.Rsp(Status=t.Status.SUCCESS), |
614 | 559 | c.ZDO.ActiveEpRsp.Callback(
|
615 | 560 | Src=device.nwk,
|
616 | 561 | Status=t.ZDOStatus.SUCCESS,
|
617 | 562 | NWK=device.nwk,
|
618 | 563 | ActiveEndpoints=[],
|
619 | 564 | ),
|
| 565 | + c.ZDO.MsgCbIncoming.Callback( |
| 566 | + Src=device.nwk, |
| 567 | + IsBroadcast=t.Bool.false, |
| 568 | + ClusterId=zdo_t.ZDOCmd.Active_EP_rsp, |
| 569 | + SecurityUse=0, |
| 570 | + TSN=7, |
| 571 | + MacDst=device.nwk, |
| 572 | + Data=serialize_zdo_command( |
| 573 | + command_id=zdo_t.ZDOCmd.Active_EP_rsp, |
| 574 | + Status=t.ZDOStatus.SUCCESS, |
| 575 | + NWKAddrOfInterest=device.nwk, |
| 576 | + ActiveEPList=[], |
| 577 | + ), |
| 578 | + ), |
620 | 579 | ],
|
621 | 580 | )
|
622 | 581 |
|
|
0 commit comments