From 4c11cb78c855549230a1eeb5c769a525716882ee Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Mon, 25 Dec 2023 21:01:59 +1000 Subject: [PATCH] Add delay to manual refresh in Advantage Air (#104918) * Add debouncer * Avoid having 3 calls * Debounce causes extra refresh in reload window * Seperate disabled test to avoid latent refresh --------- Co-authored-by: G Johansson --- homeassistant/components/advantage_air/__init__.py | 5 +++++ homeassistant/components/advantage_air/entity.py | 2 +- tests/components/advantage_air/test_sensor.py | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/advantage_air/__init__.py b/homeassistant/components/advantage_air/__init__.py index 4dbc2edad8d..1383ea7c054 100644 --- a/homeassistant/components/advantage_air/__init__.py +++ b/homeassistant/components/advantage_air/__init__.py @@ -8,6 +8,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import ADVANTAGE_AIR_RETRY, DOMAIN @@ -26,6 +27,7 @@ PLATFORMS = [ ] _LOGGER = logging.getLogger(__name__) +REQUEST_REFRESH_DELAY = 0.5 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: @@ -51,6 +53,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: name="Advantage Air", update_method=async_get, update_interval=timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL), + request_refresh_debouncer=Debouncer( + hass, _LOGGER, cooldown=REQUEST_REFRESH_DELAY, immediate=False + ), ) await coordinator.async_config_entry_first_refresh() diff --git a/homeassistant/components/advantage_air/entity.py b/homeassistant/components/advantage_air/entity.py index 691db99769b..9079e69ae09 100644 --- a/homeassistant/components/advantage_air/entity.py +++ b/homeassistant/components/advantage_air/entity.py @@ -30,7 +30,7 @@ class AdvantageAirEntity(CoordinatorEntity): async def update_handle(*values): try: if await func(*keys, *values): - await self.coordinator.async_refresh() + await self.coordinator.async_request_refresh() except ApiError as err: raise HomeAssistantError(err) from err diff --git a/tests/components/advantage_air/test_sensor.py b/tests/components/advantage_air/test_sensor.py index a7483e680b3..0099e1844c6 100644 --- a/tests/components/advantage_air/test_sensor.py +++ b/tests/components/advantage_air/test_sensor.py @@ -109,6 +109,14 @@ async def test_sensor_platform( assert entry assert entry.unique_id == "uniqueid-ac1-z02-signal" + +async def test_sensor_platform_disabled_entity( + hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_get: AsyncMock +) -> None: + """Test sensor platform disabled entity.""" + + await add_mock_config(hass) + # Test First Zone Temp Sensor (disabled by default) entity_id = "sensor.myzone_zone_open_with_sensor_temperature"