diff --git a/bellows/zigbee/application.py b/bellows/zigbee/application.py index 6bb3b919..fe30ead3 100644 --- a/bellows/zigbee/application.py +++ b/bellows/zigbee/application.py @@ -711,12 +711,13 @@ def _handle_frame_sent( cnt_name = f"unknown_msg_type_{msg}" try: - request = self._pending[message_tag] + pending_tag = (destination, message_tag) + request = self._pending[pending_tag] request.result.set_result((status, f"message send {msg}")) self.state.counters[COUNTERS_CTRL][cnt_name].increment() except KeyError: self.state.counters[COUNTERS_CTRL][f"{cnt_name}_unexpected"].increment() - LOGGER.debug("Unexpected message send notification tag: %s", message_tag) + LOGGER.debug("Unexpected message send notification tag: %s", pending_tag) except asyncio.InvalidStateError as exc: self.state.counters[COUNTERS_CTRL][f"{cnt_name}_duplicate"].increment() LOGGER.debug( @@ -724,7 +725,7 @@ def _handle_frame_sent( "Invalid state on future for message tag %s " "- probably duplicate response: %s" ), - message_tag, + pending_tag, exc, ) @@ -846,7 +847,8 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None: async with self._limit_concurrency(): message_tag = self.get_sequence() - with self._pending.new(message_tag) as req: + pending_tag = (packet.dst.address, message_tag) + with self._pending.new(pending_tag) as req: for attempt, retry_delay in enumerate(RETRY_DELAYS): async with self._req_lock: if packet.dst.addr_mode == zigpy.types.AddrMode.NWK: @@ -901,7 +903,7 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None: if attempt < len(RETRY_DELAYS): LOGGER.debug( "Request %s failed to enqueue, retrying in %ss: %s", - message_tag, + pending_tag, retry_delay, status, ) diff --git a/tests/test_application.py b/tests/test_application.py index c992b8e3..ab10a91c 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -491,7 +491,7 @@ def test_frame_handler_ignored(app, aps_frame): ), ) def test_send_failure(app, aps, ieee, msg_type): - req = app._pending[254] = MagicMock() + req = app._pending[(0xBEED, 254)] = MagicMock() app.ezsp_callback_handler( "messageSentHandler", [msg_type, 0xBEED, aps, 254, sentinel.status, b""] ) @@ -501,7 +501,7 @@ def test_send_failure(app, aps, ieee, msg_type): def test_dup_send_failure(app, aps, ieee): - req = app._pending[254] = MagicMock() + req = app._pending[(0xBEED, 254)] = MagicMock() req.result.set_result.side_effect = asyncio.InvalidStateError() app.ezsp_callback_handler( "messageSentHandler", @@ -533,7 +533,7 @@ def test_send_failure_unexpected(app, aps, ieee): def test_send_success(app, aps, ieee): - req = app._pending[253] = MagicMock() + req = app._pending[(0xBEED, 253)] = MagicMock() app.ezsp_callback_handler( "messageSentHandler", [ @@ -558,7 +558,7 @@ def test_unexpected_send_success(app, aps, ieee): def test_dup_send_success(app, aps, ieee): - req = app._pending[253] = MagicMock() + req = app._pending[(0xBEED, 253)] = MagicMock() req.result.set_result.side_effect = asyncio.InvalidStateError() app.ezsp_callback_handler( "messageSentHandler",