Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions zigpy_deconz/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down