Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Mar 31, 2024
1 parent 10099e7 commit 89fd3cd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ async def test_check_available_success(
zha_gateway: Gateway,
device_with_basic_cluster_handler: ZigpyDevice, # pylint: disable=redefined-outer-name
device_joined: Callable[[ZigpyDevice], Awaitable[Device]],
caplog: pytest.LogCaptureFixture,
) -> None:
"""Check device availability success on 1st try."""
zha_device = await device_joined(device_with_basic_cluster_handler)
basic_ch = device_with_basic_cluster_handler.endpoints[3].basic

assert not zha_device.is_coordinator
assert not zha_device.is_active_coordinator

basic_ch.read_attributes.reset_mock()
device_with_basic_cluster_handler.last_seen = None
assert zha_device.available is True
Expand Down Expand Up @@ -180,6 +184,23 @@ def _update_last_seen(*args, **kwargs): # pylint: disable=unused-argument
assert zha_device.available is True
assert zha_device.on_network is True

assert "Device is not on the network, marking unavailable" not in caplog.text
zha_device.on_network = False

assert zha_device.available is False
assert zha_device.on_network is False

sleep_time = max(
zha_gateway.global_updater.__polling_interval,
zha_gateway._device_availability_checker.__polling_interval,
)
sleep_time += 2

await asyncio.sleep(sleep_time)
await zha_gateway.async_block_till_done(wait_background_tasks=True)

assert "Device is not on the network, marking unavailable" in caplog.text


@patch(
"zha.zigbee.cluster_handlers.general.BasicClusterHandler.async_initialize",
Expand Down
27 changes: 27 additions & 0 deletions tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,30 @@ async def test_pollers_skip(

assert "Global updater interval skipped" in caplog.text
assert "Device availability checker interval skipped" in caplog.text


async def test_gateway_handle_message(
zha_gateway: Gateway,
zha_dev_basic: Device, # pylint: disable=redefined-outer-name
) -> None:
"""Test handle message."""

assert zha_dev_basic.available is True
assert zha_dev_basic.on_network is True

zha_dev_basic.on_network = False

assert zha_dev_basic.available is False
assert zha_dev_basic.on_network is False

zha_gateway.handle_message(
zha_dev_basic.device,
zha.PROFILE_ID,
general.Basic.cluster_id,
1,
1,
b"",
)

assert zha_dev_basic.available is True
assert zha_dev_basic.on_network is True

0 comments on commit 89fd3cd

Please sign in to comment.