From 10099e741b026eaa31371ae29357a19b17e17de4 Mon Sep 17 00:00:00 2001 From: David Mulcahey Date: Sat, 30 Mar 2024 20:29:46 -0400 Subject: [PATCH] missing looptime and test coverage --- tests/test_device.py | 1 + tests/test_gateway.py | 29 +++++++++++++++++++++++++++++ zha/application/helpers.py | 10 +++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index d17870f1..63d8c3ce 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -178,6 +178,7 @@ def _update_last_seen(*args, **kwargs): # pylint: disable=unused-argument assert basic_ch.read_attributes.await_count == 2 assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"] assert zha_device.available is True + assert zha_device.on_network is True @patch( diff --git a/tests/test_gateway.py b/tests/test_gateway.py index 61621b5c..52e8a28d 100644 --- a/tests/test_gateway.py +++ b/tests/test_gateway.py @@ -173,6 +173,7 @@ async def test_device_left( zha_gateway.device_left(zigpy_dev_basic) await zha_gateway.async_block_till_done() assert zha_dev_basic.available is False + assert zha_dev_basic.on_network is False async def test_gateway_group_methods( @@ -390,6 +391,7 @@ async def test_gateway_force_multi_pan_channel( @pytest.mark.parametrize("radio_concurrency", [1, 2, 8]) +@pytest.mark.looptime async def test_startup_concurrency_limit( radio_concurrency: int, zigpy_app_controller: ControllerApplication, @@ -567,3 +569,30 @@ def test_gateway_raw_device_initialized( event="raw_device_initialized", ), ) + + +@pytest.mark.looptime +async def test_pollers_skip( + zha_gateway: Gateway, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test pollers skip when they should.""" + + assert "Global updater interval skipped" not in caplog.text + assert "Device availability checker interval skipped" not in caplog.text + + assert zha_gateway.config.allow_polling is True + zha_gateway.config.allow_polling = False + assert zha_gateway.config.allow_polling 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 "Global updater interval skipped" in caplog.text + assert "Device availability checker interval skipped" in caplog.text diff --git a/zha/application/helpers.py b/zha/application/helpers.py index e872738d..91e1e565 100644 --- a/zha/application/helpers.py +++ b/zha/application/helpers.py @@ -337,7 +337,7 @@ async def update_listeners(self): _LOGGER.debug("Global updater running update callback") listener() else: - _LOGGER.debug("Global updater pass skipped") + _LOGGER.debug("Global updater interval skipped") _LOGGER.debug("Global updater interval finished") @@ -378,9 +378,9 @@ def stop(self): @periodic(_REFRESH_INTERVAL) async def check_device_availability(self): """Check device availability.""" - _LOGGER.debug("Global updater device availability checker starting") + _LOGGER.debug("Device availability checker interval starting") if self._gateway.config.allow_polling: - _LOGGER.debug("Global updater checking device availability") + _LOGGER.debug("Checking device availability") # 20 because most devices will not make remote calls await gather_with_limited_concurrency( 20, @@ -390,6 +390,6 @@ async def check_device_availability(self): if not dev.is_coordinator ), ) - _LOGGER.debug("Global updater device availability checker finished") + _LOGGER.debug("Device availability checker interval finished") else: - _LOGGER.debug("Global updater device availability checker skipped") + _LOGGER.debug("Device availability checker interval skipped")