mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove duplicate code in update coordinator (#91573)
This commit is contained in:
parent
c6b4c88355
commit
28652345bd
@ -144,10 +144,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_T]):
|
|||||||
@callback
|
@callback
|
||||||
def _unschedule_refresh(self) -> None:
|
def _unschedule_refresh(self) -> None:
|
||||||
"""Unschedule any pending refresh since there is no longer any listeners."""
|
"""Unschedule any pending refresh since there is no longer any listeners."""
|
||||||
if self._unsub_refresh:
|
self._async_unsub_refresh()
|
||||||
self._unsub_refresh()
|
|
||||||
self._unsub_refresh = None
|
|
||||||
|
|
||||||
self._debounced_refresh.async_cancel()
|
self._debounced_refresh.async_cancel()
|
||||||
|
|
||||||
def async_contexts(self) -> Generator[Any, None, None]:
|
def async_contexts(self) -> Generator[Any, None, None]:
|
||||||
@ -156,6 +153,12 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_T]):
|
|||||||
context for _, context in self._listeners.values() if context is not None
|
context for _, context in self._listeners.values() if context is not None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _async_unsub_refresh(self) -> None:
|
||||||
|
"""Cancel any scheduled call."""
|
||||||
|
if self._unsub_refresh:
|
||||||
|
self._unsub_refresh()
|
||||||
|
self._unsub_refresh = None
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _schedule_refresh(self) -> None:
|
def _schedule_refresh(self) -> None:
|
||||||
"""Schedule a refresh."""
|
"""Schedule a refresh."""
|
||||||
@ -167,9 +170,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_T]):
|
|||||||
|
|
||||||
# We do not cancel the debouncer here. If the refresh interval is shorter
|
# We do not cancel the debouncer here. If the refresh interval is shorter
|
||||||
# than the debouncer cooldown, this would cause the debounce to never be called
|
# than the debouncer cooldown, this would cause the debounce to never be called
|
||||||
if self._unsub_refresh:
|
self._async_unsub_refresh()
|
||||||
self._unsub_refresh()
|
|
||||||
self._unsub_refresh = None
|
|
||||||
|
|
||||||
# We _floor_ utcnow to create a schedule on a rounded second,
|
# We _floor_ utcnow to create a schedule on a rounded second,
|
||||||
# minimizing the time between the point and the real activation.
|
# minimizing the time between the point and the real activation.
|
||||||
@ -233,10 +234,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_T]):
|
|||||||
raise_on_entry_error: bool = False,
|
raise_on_entry_error: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Refresh data."""
|
"""Refresh data."""
|
||||||
if self._unsub_refresh:
|
self._async_unsub_refresh()
|
||||||
self._unsub_refresh()
|
|
||||||
self._unsub_refresh = None
|
|
||||||
|
|
||||||
self._debounced_refresh.async_cancel()
|
self._debounced_refresh.async_cancel()
|
||||||
|
|
||||||
if scheduled and self.hass.is_stopping:
|
if scheduled and self.hass.is_stopping:
|
||||||
@ -352,10 +350,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_T]):
|
|||||||
@callback
|
@callback
|
||||||
def async_set_updated_data(self, data: _T) -> None:
|
def async_set_updated_data(self, data: _T) -> None:
|
||||||
"""Manually update data, notify listeners and reset refresh interval."""
|
"""Manually update data, notify listeners and reset refresh interval."""
|
||||||
if self._unsub_refresh:
|
self._async_unsub_refresh()
|
||||||
self._unsub_refresh()
|
|
||||||
self._unsub_refresh = None
|
|
||||||
|
|
||||||
self._debounced_refresh.async_cancel()
|
self._debounced_refresh.async_cancel()
|
||||||
|
|
||||||
self.data = data
|
self.data = data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user