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
11 changes: 11 additions & 0 deletions tests/test_send_receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,14 @@ async def test_send_packet_deliver_failure(app, tx_packet): # noqa: F811
await app.send_packet(tx_packet)

assert "Failed to deliver" in str(e)


async def test_send_packet_disconnected(app, tx_packet): # noqa: F811
"""Sending after the radio was disconnected fails cleanly."""
app._api = None

with pytest.raises(zigpy.exceptions.DeliveryError) as e:
await app.send_packet(tx_packet)

assert "not connected" in str(e)
assert not app._pending_requests
5 changes: 5 additions & 0 deletions zigpy_deconz/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ async def send_packet(self, packet):
tx_options |= t.DeconzTransmitOptions.USE_APS_ACKS

async with self._limit_concurrency(priority=packet.priority):
# The radio can be disconnected while the request waits its turn, e.g.
# when a device is replied to after startup has failed
if self._api is None:
raise zigpy.exceptions.DeliveryError("Coordinator is not connected")

req_id = self.get_sequence()

if req_id in self._pending_requests:
Expand Down
Loading