Compare commits

...

2 Commits

Author SHA1 Message Date
Franck Nijhof 937d1fcef0 Run cancel_fetch in executor to avoid event loop conflict 2026-06-01 20:51:19 +00:00
Franck Nijhof ede446b537 Cancel iCloud polling timer on config entry unload 2026-06-01 20:36:08 +00:00
2 changed files with 10 additions and 1 deletions
@@ -67,4 +67,5 @@ async def async_setup_entry(hass: HomeAssistant, entry: IcloudConfigEntry) -> bo
async def async_unload_entry(hass: HomeAssistant, entry: IcloudConfigEntry) -> bool:
"""Unload a config entry."""
await hass.async_add_executor_job(entry.runtime_data.cancel_fetch)
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
+9 -1
View File
@@ -92,6 +92,7 @@ class IcloudAccount:
self._retried_fetch = False
self._config_entry = config_entry
self._unsub_fetch: CALLBACK_TYPE | None = None
self.listeners: list[CALLBACK_TYPE] = []
def setup(self) -> None:
@@ -293,9 +294,16 @@ class IcloudAccount:
self._max_interval,
)
def cancel_fetch(self) -> None:
"""Cancel the scheduled fetch timer."""
if self._unsub_fetch is not None:
self._unsub_fetch()
self._unsub_fetch = None
def _schedule_next_fetch(self) -> None:
self.cancel_fetch()
if not self._config_entry.pref_disable_polling:
track_point_in_utc_time(
self._unsub_fetch = track_point_in_utc_time(
self.hass,
self.keep_alive,
utcnow() + timedelta(minutes=self._fetch_interval),