Remove _next_refresh variable in update coordinator (#100323)

* Remove _next_refresh variable

* Adjust tomorrowio
pull/100406/head
Joakim Plate 2023-09-14 22:32:50 +02:00 committed by GitHub
parent df74ed0d40
commit 5f20725fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -221,7 +221,6 @@ class TomorrowioDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
await self.async_refresh()
self.update_interval = async_set_update_interval(self.hass, self._api)
self._next_refresh = None
self._async_unsub_refresh()
if self._listeners:
self._schedule_refresh()

View File

@ -81,7 +81,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
self._shutdown_requested = False
self.config_entry = config_entries.current_entry.get()
self.always_update = always_update
self._next_refresh: float | None = None
# It's None before the first successful update.
# 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."""
self._async_unsub_refresh()
self._debounced_refresh.async_cancel()
self._next_refresh = None
def async_contexts(self) -> Generator[Any, None, None]:
"""Return all registered contexts."""
@ -220,13 +218,13 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
# We use event.async_call_at because DataUpdateCoordinator does
# not need an exact update interval.
now = self.hass.loop.time()
if self._next_refresh is None or self._next_refresh <= now:
self._next_refresh = int(now) + self._microsecond
self._next_refresh += self.update_interval.total_seconds()
next_refresh = int(now) + self._microsecond
next_refresh += self.update_interval.total_seconds()
self._unsub_refresh = event.async_call_at(
self.hass,
self._job,
self._next_refresh,
next_refresh,
)
async def _handle_refresh_interval(self, _now: datetime) -> None:
@ -265,7 +263,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
async def async_refresh(self) -> None:
"""Refresh data and log errors."""
self._next_refresh = None
await self._async_refresh(log_failures=True)
async def _async_refresh( # noqa: C901
@ -405,7 +402,6 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
"""Manually update data, notify listeners and reset refresh interval."""
self._async_unsub_refresh()
self._debounced_refresh.async_cancel()
self._next_refresh = None
self.data = data
self.last_update_success = True