Skip to content

Commit 8ddf758

Browse files
committed
Test request more thoroughly
1 parent e8f175d commit 8ddf758

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/test_application.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import zigpy_znp.commands as c
1010
import zigpy_znp.config as conf
1111

12+
import zigpy.device
1213
from zigpy.zdo.types import ZDOCmd
1314

1415
from zigpy_znp.uart import ZnpMtProtocol
@@ -523,13 +524,98 @@ async def test_zdo_request_interception(application, mocker):
523524
dst_ep=0,
524525
sequence=0,
525526
data=b"test",
527+
use_ieee=False,
526528
)
527529

528530
await active_ep_req
529531

530532
assert status == t.Status.Success
531533

532534

535+
@pytest_mark_asyncio_timeout(seconds=10)
536+
async def test_zigpy_request(application, mocker):
537+
app, znp_server = application
538+
await app.startup(auto_form=False)
539+
540+
TSN = 1
541+
542+
device = app.add_device(ieee=t.EUI64(range(8)), nwk=0xAABB)
543+
device.status = zigpy.device.Status.ENDPOINTS_INIT
544+
device.initializing = False
545+
546+
device.add_endpoint(1).add_input_cluster(6)
547+
548+
# Respond to a light turn on request
549+
data_req = znp_server.reply_once_to(
550+
request=c.AFCommands.DataRequestExt.Req(
551+
DstAddrModeAddress=t.AddrModeAddress(
552+
mode=t.AddrMode.NWK, address=device.nwk
553+
),
554+
DstEndpoint=1,
555+
SrcEndpoint=1,
556+
ClusterId=6,
557+
TSN=TSN,
558+
Data=bytes([0x01, TSN, 0x01]),
559+
partial=True,
560+
),
561+
responses=[
562+
c.AFCommands.DataRequestExt.Rsp(Status=t.Status.Success),
563+
c.AFCommands.DataConfirm.Callback(
564+
Status=t.Status.Success, Endpoint=1, TSN=TSN,
565+
),
566+
c.ZDOCommands.SrcRtgInd.Callback(DstAddr=device.nwk, Relays=[]),
567+
c.AFCommands.IncomingMsg.Callback(
568+
GroupId=0x0000,
569+
ClusterId=6,
570+
SrcAddr=device.nwk,
571+
SrcEndpoint=1,
572+
DstEndpoint=1,
573+
WasBroadcast=False,
574+
LQI=63,
575+
SecurityUse=False,
576+
TimeStamp=1198515,
577+
TSN=0,
578+
Data=bytes([0x08, TSN, 0x0B, 0x00, 0x00]),
579+
MacSrcAddr=device.nwk,
580+
MsgResultRadius=29,
581+
),
582+
],
583+
)
584+
585+
# Turn on the light
586+
await device.endpoints[1].on_off.on()
587+
await data_req
588+
589+
590+
@pytest_mark_asyncio_timeout(seconds=2)
591+
@pytest.mark.parametrize(
592+
"use_ieee,dev_addr",
593+
[
594+
(True, t.AddrModeAddress(mode=t.AddrMode.IEEE, address=t.EUI64(range(8)))),
595+
(False, t.AddrModeAddress(mode=t.AddrMode.NWK, address=t.NWK(0xAABB))),
596+
],
597+
)
598+
async def test_request_use_ieee(application, mocker, use_ieee, dev_addr):
599+
app, znp_server = application
600+
device = app.add_device(ieee=t.EUI64(range(8)), nwk=0xAABB)
601+
602+
send_req = mocker.patch.object(app, "_send_request", new=CoroutineMock())
603+
604+
await app.request(
605+
device,
606+
use_ieee=use_ieee,
607+
profile=None,
608+
cluster=None,
609+
src_ep=None,
610+
dst_ep=None,
611+
sequence=None,
612+
data=None,
613+
)
614+
615+
assert send_req.call_count == 1
616+
assert send_req.mock_calls[0][2]["dst_addr"] == dev_addr
617+
618+
533619
@pytest_mark_asyncio_timeout()
534620
async def test_update_network_noop(mocker, application):
535621
app, znp_server = application

0 commit comments

Comments
 (0)