From dafd99ca584fa45fbd8ac6488ec9c5879926316f Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 27 Sep 2026 14:13:17 +0200 Subject: [PATCH] Cancel nordpool listener update timer on unload (#183304) Co-authored-by: Claude --- homeassistant/components/nordpool/coordinator.py | 8 ++++++++ tests/components/nordpool/test_init.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/homeassistant/components/nordpool/coordinator.py b/homeassistant/components/nordpool/coordinator.py index 84056bdd6faf..31345de77725 100644 --- a/homeassistant/components/nordpool/coordinator.py +++ b/homeassistant/components/nordpool/coordinator.py @@ -74,6 +74,14 @@ class NordPoolDataUpdateCoordinator(DataUpdateCoordinator[DeliveryPeriodsData]): ) self.async_update_listeners() + @override + async def async_shutdown(self) -> None: + """Cancel the listener update timer and shut down the coordinator.""" + if self.listener_unsub: + self.listener_unsub() + self.listener_unsub = None + await super().async_shutdown() + @override async def _async_setup(self) -> None: """Set up the coordinator.""" diff --git a/tests/components/nordpool/test_init.py b/tests/components/nordpool/test_init.py index db893715e83f..da7b874ac30a 100644 --- a/tests/components/nordpool/test_init.py +++ b/tests/components/nordpool/test_init.py @@ -40,9 +40,12 @@ async def test_unload_entry(hass: HomeAssistant, get_client: NordPoolClient) -> await hass.async_block_till_done(wait_background_tasks=True) assert entry.state is ConfigEntryState.LOADED + coordinator = entry.runtime_data + assert coordinator.listener_unsub is not None assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() assert entry.state is ConfigEntryState.NOT_LOADED + assert coordinator.listener_unsub is None @pytest.mark.parametrize(