mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
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:
parent
d59142a595
commit
4c11cb78c8
@ -8,6 +8,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import ADVANTAGE_AIR_RETRY, DOMAIN
|
from .const import ADVANTAGE_AIR_RETRY, DOMAIN
|
||||||
@ -26,6 +27,7 @@ PLATFORMS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
REQUEST_REFRESH_DELAY = 0.5
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
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",
|
name="Advantage Air",
|
||||||
update_method=async_get,
|
update_method=async_get,
|
||||||
update_interval=timedelta(seconds=ADVANTAGE_AIR_SYNC_INTERVAL),
|
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()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
@ -30,7 +30,7 @@ class AdvantageAirEntity(CoordinatorEntity):
|
|||||||
async def update_handle(*values):
|
async def update_handle(*values):
|
||||||
try:
|
try:
|
||||||
if await func(*keys, *values):
|
if await func(*keys, *values):
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
except ApiError as err:
|
except ApiError as err:
|
||||||
raise HomeAssistantError(err) from err
|
raise HomeAssistantError(err) from err
|
||||||
|
|
||||||
|
@ -109,6 +109,14 @@ async def test_sensor_platform(
|
|||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "uniqueid-ac1-z02-signal"
|
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)
|
# Test First Zone Temp Sensor (disabled by default)
|
||||||
entity_id = "sensor.myzone_zone_open_with_sensor_temperature"
|
entity_id = "sensor.myzone_zone_open_with_sensor_temperature"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user