Fix race reloading homekit_controller (#112790)

If the subscribe task was still running during the reload we
would not cancel it. Make it a config entry task so it gets
cancelled at unload
This commit is contained in:
J. Nick Koston 2024-03-08 17:27:08 -10:00 committed by GitHub
parent 65358c129a
commit 5b2a24b1bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -197,13 +197,19 @@ class HKDevice:
self._subscribe_timer()
self._subscribe_timer = None
async def _async_subscribe(self, _now: datetime) -> None:
@callback
def _async_subscribe(self, _now: datetime) -> None:
"""Subscribe to characteristics."""
self._subscribe_timer = None
if self._pending_subscribes:
subscribes = self._pending_subscribes.copy()
self._pending_subscribes.clear()
await self.pairing.subscribe(subscribes)
self.config_entry.async_create_task(
self.hass,
self.pairing.subscribe(subscribes),
name=f"hkc subscriptions {self.unique_id}",
eager_start=True,
)
def remove_watchable_characteristics(
self, characteristics: list[tuple[int, int]]