From 2033dbdd9016fed910f636cc2234d11257d923a7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 12 Feb 2025 09:22:35 +0100 Subject: [PATCH] Use entry.async_on_unload in fireservicerota (#138360) --- homeassistant/components/fireservicerota/__init__.py | 5 +---- homeassistant/components/fireservicerota/coordinator.py | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/fireservicerota/__init__.py b/homeassistant/components/fireservicerota/__init__.py index bf5385b6f2a..6f48dcfc4bc 100644 --- a/homeassistant/components/fireservicerota/__init__.py +++ b/homeassistant/components/fireservicerota/__init__.py @@ -27,6 +27,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if client.token_refresh_failure: return False + entry.async_on_unload(client.async_stop_listener) coordinator = FireServiceUpdateCoordinator(hass, client, entry) await coordinator.async_config_entry_first_refresh() @@ -43,10 +44,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload FireServiceRota config entry.""" - - await hass.async_add_executor_job( - hass.data[DOMAIN][entry.entry_id][DATA_CLIENT].websocket.stop_listener - ) unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: del hass.data[DOMAIN][entry.entry_id] diff --git a/homeassistant/components/fireservicerota/coordinator.py b/homeassistant/components/fireservicerota/coordinator.py index 14a8c40e469..c452421d57b 100644 --- a/homeassistant/components/fireservicerota/coordinator.py +++ b/homeassistant/components/fireservicerota/coordinator.py @@ -213,3 +213,7 @@ class FireServiceRotaClient: ) await self.update_call(self.fsr.set_incident_response, self.incident_id, value) + + async def async_stop_listener(self) -> None: + """Stop listener.""" + await self._hass.async_add_executor_job(self.websocket.stop_listener)