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
37 changes: 0 additions & 37 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,43 +628,6 @@ async def test_aps_data_request_relays(relays, api, mock_command_rsp):
assert "has non-trailing optional argument" in str(exc.value)


@patch(
"zigpy_deconz.api.REQUEST_RETRY_DELAYS",
[None if v is None else 0 for v in deconz_api.REQUEST_RETRY_DELAYS],
)
async def test_aps_data_request_retries_busy(api, mock_command_rsp):
await api.connect()

mock_rsp = mock_command_rsp(
command_id=deconz_api.CommandId.aps_data_request,
params={},
rsp={
"status": deconz_api.Status.BUSY,
"frame_length": t.uint16_t(9),
"payload_length": t.uint16_t(2),
"device_state": deconz_api.DeviceState(
network_state=deconz_api.NetworkState2.CONNECTED,
device_state=(
deconz_api.DeviceStateFlags.APSDE_DATA_REQUEST_FREE_SLOTS_AVAILABLE
),
),
"request_id": t.uint8_t(0x00),
},
)

with pytest.raises(deconz_api.CommandError):
await api.aps_data_request(
req_id=0x00,
dst_addr_ep=t.DeconzAddressEndpoint.deserialize(b"\x02\xaa\x55\x01")[0],
profile=0x0104,
cluster=0x0007,
src_ep=1,
aps_payload=b"aps payload",
)

assert len(mock_rsp.mock_calls) == 4


async def test_aps_data_request_retries_failure(api, mock_command_rsp):
await api.connect()

Expand Down
49 changes: 19 additions & 30 deletions zigpy_deconz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
MISMATCHED_RESPONSE_TIMEOUT = 0.5
COMMAND_TIMEOUT = 1.8
PROBE_TIMEOUT = 2
REQUEST_RETRY_DELAYS = (0.5, 1.0, 1.5, None)

FRAME_LENGTH = object()
PAYLOAD_LENGTH = object()
Expand Down Expand Up @@ -582,7 +581,7 @@

try:
LOGGER.debug("Sending %s%s (seq=%s)", cmd, kwargs, seq)
self._uart.send(command.replace(seq=seq).serialize())

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.10.8

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.10.8

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.10.8

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.10.8

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.9.15

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.9.15

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.9.15

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.9.15

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.12.9

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.12.9

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.12.9

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.12.9

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.13.2

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.13.2

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.13.2

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.13.2

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.11.0

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.11.0

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.11.0

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Check warning on line 584 in zigpy_deconz/api.py

View workflow job for this annotation

GitHub Actions / shared-ci / Run tests Python 3.11.0

coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

async with asyncio_timeout(COMMAND_TIMEOUT):
return await fut
Expand Down Expand Up @@ -872,37 +871,27 @@
assert len(relays) <= 9
flags |= t.DeconzSendDataFlags.RELAYS

for delay in REQUEST_RETRY_DELAYS:
if not self._free_slots_available_event.is_set():
LOGGER.debug("Waiting for free slots to become available")
await self._free_slots_available_event.wait()
if not self._free_slots_available_event.is_set():
LOGGER.debug("Waiting for free slots to become available")
await self._free_slots_available_event.wait()

try:
rsp = await self.send_command(
CommandId.aps_data_request,
request_id=req_id,
flags=flags,
dst=dst_addr_ep,
profile_id=profile,
cluster_id=cluster,
src_ep=src_ep,
asdu=aps_payload,
tx_options=tx_options,
radius=radius,
relays=relays,
)
except CommandError as ex:
LOGGER.debug("'aps_data_request' failure: %s", ex)
if delay is None or ex.status != Status.BUSY:
raise
rsp = await self.send_command(
CommandId.aps_data_request,
request_id=req_id,
flags=flags,
dst=dst_addr_ep,
profile_id=profile,
cluster_id=cluster,
src_ep=src_ep,
asdu=aps_payload,
tx_options=tx_options,
radius=radius,
relays=relays,
)

LOGGER.debug("retrying 'aps_data_request' in %ss", delay)
await asyncio.sleep(delay)
else:
self._handle_device_state_changed(
status=rsp["status"], device_state=rsp["device_state"]
)
return
self._handle_device_state_changed(
status=rsp["status"], device_state=rsp["device_state"]
)

async def get_device_state(self) -> DeviceState:
rsp = await self.send_command(CommandId.device_state)
Expand Down