Use an eager task in the update coordinator scheduled refresh (#111570)
* Use an eager task in the update coordinator scheduled refresh We have a lot of places that will not suspend because the refresh function decides it does not need to update. Currently these have to be scheduled on the event loop even though they are a noop. Since _handle_refresh_interval is subclassed in some integrations, I created a dunder wrapper function to avoid integraions subclassing it * fix time fires outside of patch
This commit is contained in:
parent
b692f30c33
commit
d5e1934942
4 changed files with 15 additions and 7 deletions
|
@ -112,9 +112,9 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
|||
if entry := self.config_entry:
|
||||
job_name += f" {entry.title} {entry.domain} {entry.entry_id}"
|
||||
self._job = HassJob(
|
||||
self._handle_refresh_interval,
|
||||
self.__wrap_handle_refresh_interval,
|
||||
job_name,
|
||||
job_type=HassJobType.Coroutinefunction,
|
||||
job_type=HassJobType.Callback,
|
||||
)
|
||||
self._unsub_refresh: CALLBACK_TYPE | None = None
|
||||
self._unsub_shutdown: CALLBACK_TYPE | None = None
|
||||
|
@ -250,6 +250,11 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
|||
next_refresh, hass.async_run_hass_job, self._job
|
||||
).cancel
|
||||
|
||||
@callback
|
||||
def __wrap_handle_refresh_interval(self) -> None:
|
||||
"""Handle a refresh interval occurrence."""
|
||||
self.hass.async_create_task(self._handle_refresh_interval(), eager_start=True)
|
||||
|
||||
async def _handle_refresh_interval(self, _now: datetime | None = None) -> None:
|
||||
"""Handle a refresh interval occurrence."""
|
||||
self._unsub_refresh = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue