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 <goran.johansson@shiftit.se>
This commit is contained in:
Brett Adams 2023-12-25 21:01:59 +10:00 committed by GitHub
parent d59142a595
commit 4c11cb78c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -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()

View File

@ -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

View File

@ -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"