Skip to content

Commit

Permalink
Remove _next_refresh variable in update coordinator (#100323)
Browse files Browse the repository at this point in the history
* Remove _next_refresh variable

* Adjust tomorrowio
  • Loading branch information
elupus authored Sep 14, 2023
1 parent df74ed0 commit 5f20725
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 0 additions & 1 deletion homeassistant/components/tomorrowio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ async def async_setup_entry(self, entry: ConfigEntry) -> None:
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()
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/helpers/update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def __init__(
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
Expand Down Expand Up @@ -184,7 +183,6 @@ def _unschedule_refresh(self) -> None:
"""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."""
Expand Down Expand Up @@ -220,13 +218,13 @@ def _schedule_refresh(self) -> None:
# 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:
Expand Down Expand Up @@ -265,7 +263,6 @@ async def async_config_entry_first_refresh(self) -> None:

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
Expand Down Expand Up @@ -405,7 +402,6 @@ def async_set_updated_data(self, data: _DataT) -> None:
"""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
Expand Down

0 comments on commit 5f20725

Please sign in to comment.