diff --git a/tests/test_application.py b/tests/test_application.py index 7c5a6db..1162c48 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -3,6 +3,7 @@ import pytest +from zigpy.exceptions import DeliveryError from zigpy.types import EUI64 from zigpy_deconz.api import Deconz from zigpy_deconz.zigbee.application import ControllerApplication @@ -145,12 +146,16 @@ async def test_permit(app): assert app._api.write_parameter.call_args_list[0][0][1] == time_s -async def _test_request(app, do_reply=True, expect_reply=True, **kwargs): +async def _test_request(app, do_reply=True, expect_reply=True, + send_succes=True, **kwargs): seq = 123 nwk = 0x2345 def aps_data_request(req_id, dst_addr, dst_ep, profile, cluster, src_ep, data): - app._pending[req_id][0].set_result(mock.sentinel.transmit_confirm) + if send_succes: + app._pending[req_id][0].set_result(0) + else: + app._pending[req_id][0].set_result(mock.sentinel.send_fail) if expect_reply: if do_reply: app._pending[req_id][1].set_result(mock.sentinel.reply_result) @@ -177,6 +182,13 @@ async def test_request_no_reply(app): await _test_request(app, False, True, tries=2, timeout=0.1) +@pytest.mark.asyncio +async def test_request_send_failure(app): + with pytest.raises(DeliveryError): + await _test_request(app, False, True, send_succes=False, + tries=2, timeout=0.1) + + def _handle_reply(app, tsn): app.handle_message = mock.MagicMock() return app._handle_reply( diff --git a/zigpy_deconz/zigbee/application.py b/zigpy_deconz/zigbee/application.py index 23fa1da..8da0ec1 100644 --- a/zigpy_deconz/zigbee/application.py +++ b/zigpy_deconz/zigbee/application.py @@ -6,6 +6,7 @@ from zigpy_deconz import types as t import zigpy.application +import zigpy.exceptions import zigpy.types import zigpy.util import zigpy.device @@ -111,6 +112,10 @@ async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence, data, e if r: LOGGER.warning("Error while sending frame: 0x%02x", r) + self._pending.pop(sequence, None) + raise zigpy.exceptions.DeliveryError( + "[0x%04x:%s:0x%04x] failed transmission request: %s" % (nwk, dst_ep, cluster, r) + ) if not expect_reply: self._pending.pop(sequence, None)