mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
add update schedule
This commit is contained in:
parent
f06b9ff0cf
commit
aa92de42da
3 changed files with 13 additions and 3 deletions
|
|
@ -43,7 +43,7 @@ async def async_setup_entry(
|
|||
entry=entry,
|
||||
logger=LOGGER,
|
||||
name=DOMAIN,
|
||||
update_interval=timedelta(hours=1),
|
||||
update_interval=timedelta(minutes=5),
|
||||
)
|
||||
entry.runtime_data = TibberPricesData(
|
||||
client=TibberPricesApiClient(
|
||||
|
|
@ -68,6 +68,7 @@ async def async_unload_entry(
|
|||
entry: TibberPricesConfigEntry,
|
||||
) -> bool:
|
||||
"""Handle unload of an entry."""
|
||||
await entry.runtime_data.coordinator.shutdown()
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,17 @@ class TibberPricesDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
self._last_price_update: datetime | None = None
|
||||
self._last_rating_update: datetime | None = None
|
||||
self._scheduled_price_update: asyncio.Task | None = None
|
||||
self._remove_update_listener = None
|
||||
|
||||
# Schedule additional updates at the start of every hour
|
||||
self._remove_update_listener = hass.helpers.event.async_track_time_change(
|
||||
self.async_request_refresh, minute=0, second=0
|
||||
)
|
||||
|
||||
async def shutdown(self) -> None:
|
||||
"""Clean up coordinator on shutdown."""
|
||||
if self._remove_update_listener:
|
||||
self._remove_update_listener()
|
||||
|
||||
async def _async_initialize(self) -> None:
|
||||
"""Load stored data."""
|
||||
|
|
|
|||
|
|
@ -58,10 +58,8 @@ class TibberPricesSwitch(TibberPricesEntity, SwitchEntity):
|
|||
|
||||
async def async_turn_on(self, **_: Any) -> None:
|
||||
"""Turn on the switch."""
|
||||
await self.coordinator.config_entry.runtime_data.client.async_set_title("bar")
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
async def async_turn_off(self, **_: Any) -> None:
|
||||
"""Turn off the switch."""
|
||||
await self.coordinator.config_entry.runtime_data.client.async_set_title("foo")
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
|
|
|||
Loading…
Reference in a new issue