Skip to content

Commit

Permalink
fix[updater]: make it compatible with HA 2024.04
Browse files Browse the repository at this point in the history
  • Loading branch information
IATkachenko committed Mar 30, 2024
1 parent cc5a1a4 commit 8ebdc69
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions custom_components/yandex_weather/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ATTR_FORECAST_WIND_BEARING,
Forecast,
)
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
Expand Down Expand Up @@ -335,9 +335,27 @@ def schedule_refresh(self, offset: timedelta):
int(self.hass.loop.time()) + self._microsecond + offset.total_seconds()
)
self._unsub_refresh = self.hass.loop.call_at(
next_refresh, self.hass.async_run_hass_job, self._job
next_refresh, self.__wrap_handle_refresh_interval
).cancel

@callback
def __wrap_handle_refresh_interval(self) -> None:
"""Handle a refresh interval occurrence."""
# We need this private callback from parent class
if self.config_entry:
self.config_entry.async_create_background_task(
self.hass,
self._handle_refresh_interval(),
name=f"{self.name} - {self.config_entry.title} - refresh",
eager_start=True,
)
else:
self.hass.async_create_background_task(
self._handle_refresh_interval(),
name=f"{self.name} - refresh",
eager_start=True,
)

@property
def device_id(self) -> str:
"""Device ID."""
Expand Down

0 comments on commit 8ebdc69

Please sign in to comment.