Remove _next_refresh variable in update coordinator (#100323)
* Remove _next_refresh variable * Adjust tomorrowiopull/100406/head
parent
df74ed0d40
commit
5f20725fd5
|
@ -221,7 +221,6 @@ class TomorrowioDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
await self.async_refresh()
|
await self.async_refresh()
|
||||||
|
|
||||||
self.update_interval = async_set_update_interval(self.hass, self._api)
|
self.update_interval = async_set_update_interval(self.hass, self._api)
|
||||||
self._next_refresh = None
|
|
||||||
self._async_unsub_refresh()
|
self._async_unsub_refresh()
|
||||||
if self._listeners:
|
if self._listeners:
|
||||||
self._schedule_refresh()
|
self._schedule_refresh()
|
||||||
|
|
|
@ -81,7 +81,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||||
self._shutdown_requested = False
|
self._shutdown_requested = False
|
||||||
self.config_entry = config_entries.current_entry.get()
|
self.config_entry = config_entries.current_entry.get()
|
||||||
self.always_update = always_update
|
self.always_update = always_update
|
||||||
self._next_refresh: float | None = None
|
|
||||||
|
|
||||||
# It's None before the first successful update.
|
# It's None before the first successful update.
|
||||||
# Components should call async_config_entry_first_refresh
|
# Components should call async_config_entry_first_refresh
|
||||||
|
@ -184,7 +183,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||||
"""Unschedule any pending refresh since there is no longer any listeners."""
|
"""Unschedule any pending refresh since there is no longer any listeners."""
|
||||||
self._async_unsub_refresh()
|
self._async_unsub_refresh()
|
||||||
self._debounced_refresh.async_cancel()
|
self._debounced_refresh.async_cancel()
|
||||||
self._next_refresh = None
|
|
||||||
|
|
||||||
def async_contexts(self) -> Generator[Any, None, None]:
|
def async_contexts(self) -> Generator[Any, None, None]:
|
||||||
"""Return all registered contexts."""
|
"""Return all registered contexts."""
|
||||||
|
@ -220,13 +218,13 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||||
# We use event.async_call_at because DataUpdateCoordinator does
|
# We use event.async_call_at because DataUpdateCoordinator does
|
||||||
# not need an exact update interval.
|
# not need an exact update interval.
|
||||||
now = self.hass.loop.time()
|
now = self.hass.loop.time()
|
||||||
if self._next_refresh is None or self._next_refresh <= now:
|
|
||||||
self._next_refresh = int(now) + self._microsecond
|
next_refresh = int(now) + self._microsecond
|
||||||
self._next_refresh += self.update_interval.total_seconds()
|
next_refresh += self.update_interval.total_seconds()
|
||||||
self._unsub_refresh = event.async_call_at(
|
self._unsub_refresh = event.async_call_at(
|
||||||
self.hass,
|
self.hass,
|
||||||
self._job,
|
self._job,
|
||||||
self._next_refresh,
|
next_refresh,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _handle_refresh_interval(self, _now: datetime) -> None:
|
async def _handle_refresh_interval(self, _now: datetime) -> None:
|
||||||
|
@ -265,7 +263,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||||
|
|
||||||
async def async_refresh(self) -> None:
|
async def async_refresh(self) -> None:
|
||||||
"""Refresh data and log errors."""
|
"""Refresh data and log errors."""
|
||||||
self._next_refresh = None
|
|
||||||
await self._async_refresh(log_failures=True)
|
await self._async_refresh(log_failures=True)
|
||||||
|
|
||||||
async def _async_refresh( # noqa: C901
|
async def _async_refresh( # noqa: C901
|
||||||
|
@ -405,7 +402,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
||||||
"""Manually update data, notify listeners and reset refresh interval."""
|
"""Manually update data, notify listeners and reset refresh interval."""
|
||||||
self._async_unsub_refresh()
|
self._async_unsub_refresh()
|
||||||
self._debounced_refresh.async_cancel()
|
self._debounced_refresh.async_cancel()
|
||||||
self._next_refresh = None
|
|
||||||
|
|
||||||
self.data = data
|
self.data = data
|
||||||
self.last_update_success = True
|
self.last_update_success = True
|
||||||
|
|
Loading…
Reference in New Issue