Skip to content

Commit

Permalink
Limit request concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Dec 10, 2023
1 parent 8314dcd commit 2b1b21f
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions zigpy_xbee/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,30 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None:
"Cannot send a packet to a device without a known IEEE address"
)

send_req = self._api.tx_explicit(
long_addr,
short_addr,
packet.src_ep or 0,
packet.dst_ep or 0,
packet.cluster_id,
packet.profile_id,
packet.radius,
tx_opts,
packet.data.serialize(),
)

try:
v = await asyncio.wait_for(send_req, timeout=TIMEOUT_TX_STATUS)
except asyncio.TimeoutError:
raise zigpy.exceptions.DeliveryError(
"Timeout waiting for ACK", status=TXStatus.NETWORK_ACK_FAILURE
async with self._limit_concurrency():
send_req = self._api.tx_explicit(
long_addr,
short_addr,
packet.src_ep or 0,
packet.dst_ep or 0,
packet.cluster_id,
packet.profile_id,
packet.radius,
tx_opts,
packet.data.serialize(),
)

if v != TXStatus.SUCCESS:
raise zigpy.exceptions.DeliveryError(
f"Failed to deliver packet: {v!r}", status=v
)
try:
v = await asyncio.wait_for(send_req, timeout=TIMEOUT_TX_STATUS)
except asyncio.TimeoutError:
raise zigpy.exceptions.DeliveryError(
"Timeout waiting for ACK", status=TXStatus.NETWORK_ACK_FAILURE
)

if v != TXStatus.SUCCESS:
raise zigpy.exceptions.DeliveryError(
f"Failed to deliver packet: {v!r}", status=v
)

@zigpy.util.retryable_request()
def remote_at_command(
Expand Down

0 comments on commit 2b1b21f

Please sign in to comment.