Skip to content

Commit fb4aab9

Browse files
committed
Drop the zigpy Requests class
1 parent 37241f1 commit fb4aab9

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

zigpy_deconz/zigbee/application.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self, config: dict[str, Any]):
7373
super().__init__(config=config)
7474
self._api = None
7575

76-
self._pending = zigpy.util.Requests()
76+
self._pending_requests = {}
7777

7878
self._delayed_neighbor_scan_task = None
7979
self._reconnect_task = None
@@ -504,7 +504,14 @@ async def send_packet(self, packet):
504504
async with self._limit_concurrency(priority=packet.priority):
505505
req_id = self.get_sequence()
506506

507-
with self._pending.new(req_id) as req:
507+
if req_id in self._pending_requests:
508+
raise zigpy.exceptions.DeliveryError(
509+
f"Request with id {req_id} is already pending, cannot send"
510+
)
511+
512+
future = self._pending_requests[req_id] = asyncio.Future()
513+
514+
try:
508515
try:
509516
await self._api.aps_data_request(
510517
req_id=req_id,
@@ -525,31 +532,35 @@ async def send_packet(self, packet):
525532
)
526533

527534
async with asyncio_timeout(SEND_CONFIRM_TIMEOUT):
528-
status = await req.result
535+
status = await future
529536

530537
if status != TXStatus.SUCCESS:
531538
raise zigpy.exceptions.DeliveryError(
532539
f"Failed to deliver packet: {status!r}", status
533540
)
541+
finally:
542+
del self._pending_requests[req_id]
534543

535544
async def permit_ncp(self, time_s=60):
536545
assert 0 <= time_s <= 254
537546
await self._api.write_parameter(NetworkParameter.permit_join, time_s)
538547

539548
def handle_tx_confirm(self, req_id, status):
540549
try:
541-
self._pending[req_id].result.set_result(status)
542-
return
550+
future = self._pending_requests[req_id]
543551
except KeyError:
544552
LOGGER.warning(
545553
"Unexpected transmit confirm for request id %s, Status: %s",
546554
req_id,
547555
status,
548556
)
549-
except asyncio.InvalidStateError as exc:
550-
LOGGER.debug(
551-
"Invalid state on future - probably duplicate response: %s", exc
552-
)
557+
else:
558+
try:
559+
future.set_result(status)
560+
except asyncio.InvalidStateError as exc:
561+
LOGGER.debug(
562+
"Invalid state on future - probably duplicate response: %s", exc
563+
)
553564

554565
async def restore_neighbours(self) -> None:
555566
"""Restore children."""

0 commit comments

Comments
 (0)