Skip to content

Commit

Permalink
Add delay to manual refresh in Advantage Air (home-assistant#104918)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Bre77 and gjohansson-ST authored Dec 25, 2023
1 parent d59142a commit 4c11cb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions homeassistant/components/advantage_air/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand All @@ -26,6 +27,7 @@
]

_LOGGER = logging.getLogger(__name__)
REQUEST_REFRESH_DELAY = 0.5


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand All @@ -51,6 +53,9 @@ async def async_get():
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()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/advantage_air/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def update_handle_factory(self, func, *keys):
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

Expand Down
8 changes: 8 additions & 0 deletions tests/components/advantage_air/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 4c11cb7

Please sign in to comment.