From 822c6814b6efb31ec8a03980bc343a6068b2bbc1 Mon Sep 17 00:00:00 2001 From: Marc Billow Date: Fri, 31 Jul 2026 01:58:04 +0000 Subject: [PATCH] fix(coordinator): don't let subpolls delay HA startup/shutdown (#207) _run_subpolls is a self-limiting background loop the coordinator already cancels and recreates every refresh cycle, but scheduling it with async_create_task ties it into HA's startup/shutdown task tracking anyway. A subpoll cycle in flight (up to ~27s) then delays both. async_create_background_task is HA's supported API for exactly this case -- a task the integration owns and manages the lifecycle of. --- custom_components/localthings/coordinator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/localthings/coordinator.py b/custom_components/localthings/coordinator.py index 2e35948..e895904 100644 --- a/custom_components/localthings/coordinator.py +++ b/custom_components/localthings/coordinator.py @@ -917,9 +917,15 @@ class LocalThingsCoordinator(DataUpdateCoordinator[dict[str, Any]]): # Schedule sub-polls for hot/warm hrefs between summary polls # (no-op in observe-primary mode unless this cycle's sweep found a - # mismatch; _run_subpolls checks the mode/force). + # mismatch; _run_subpolls checks the mode/force). A background task, + # not async_create_task: this loop is self-limiting (cancelled and + # recreated every refresh cycle, see the cancel() above) and owned + # entirely by the coordinator, so it has no business being tracked by + # HA's own startup/shutdown sequencing -- async_create_task ties it + # in regardless, so a subpoll cycle in flight (up to ~27s, + # _SUBPOLL_STEP_S x 9 slots) delays both (issue #207). if self._hot_hrefs or self._warm_hrefs: - self._subpoll_task = self.hass.async_create_task( + self._subpoll_task = self.hass.async_create_background_task( self._run_subpolls(force=sweep_mismatch), name="localthings_subpoll" )