Skip to content

Commit 1fcf592

Browse files
committed
Test _send_request failure
1 parent 6b49be4 commit 1fcf592

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test_application.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,51 @@ async def test_zigpy_request(application, mocker):
631631
await data_req
632632

633633

634+
@pytest_mark_asyncio_timeout(seconds=10)
635+
async def test_zigpy_request_failure(application, mocker):
636+
app, znp_server = application
637+
await app.startup(auto_form=False)
638+
639+
TSN = 1
640+
641+
device = app.add_device(ieee=t.EUI64(range(8)), nwk=0xAABB)
642+
device.status = zigpy.device.Status.ENDPOINTS_INIT
643+
device.initializing = False
644+
645+
device.add_endpoint(1).add_input_cluster(6)
646+
647+
# Fail to respond to a light turn on request
648+
znp_server.reply_to(
649+
request=c.AFCommands.DataRequestExt.Req(
650+
DstAddrModeAddress=t.AddrModeAddress(
651+
mode=t.AddrMode.NWK, address=device.nwk
652+
),
653+
DstEndpoint=1,
654+
SrcEndpoint=1,
655+
ClusterId=6,
656+
TSN=TSN,
657+
Data=bytes([0x01, TSN, 0x01]),
658+
partial=True,
659+
),
660+
responses=[
661+
c.AFCommands.DataRequestExt.Rsp(Status=t.Status.Success),
662+
c.AFCommands.DataConfirm.Callback(
663+
Status=t.Status.Failure, Endpoint=1, TSN=TSN,
664+
),
665+
],
666+
)
667+
668+
mocker.patch.object(
669+
app, "_send_request", new=CoroutineMock(wraps=app._send_request)
670+
)
671+
672+
# Fail to turn on the light
673+
with pytest.raises(zigpy.exceptions.DeliveryError):
674+
await device.endpoints[1].on_off.on()
675+
676+
assert app._send_request.call_count == 1
677+
678+
634679
@pytest_mark_asyncio_timeout(seconds=3)
635680
@pytest.mark.parametrize(
636681
"use_ieee,dev_addr",

0 commit comments

Comments
 (0)