From f874d28853c2692498c646772e03256a15590693 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Mon, 5 Oct 2026 15:03:17 +0800 Subject: [PATCH 1/2] fix: unsubscribe config-entry listener on unload --- custom_components/adaptive_lighting/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/__init__.py b/custom_components/adaptive_lighting/__init__.py index 0ac9ef71..83db6fd7 100644 --- a/custom_components/adaptive_lighting/__init__.py +++ b/custom_components/adaptive_lighting/__init__.py @@ -106,7 +106,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b # This will reload any changes the user made to any YAML configurations. # Called during 'quick reload' or hass.reload_config_entry - hass.bus.async_listen("hass.config.entry_updated", reload_configuration_yaml) + config_entry.async_on_unload( + hass.bus.async_listen("hass.config.entry_updated", reload_configuration_yaml), + ) undo_listener = config_entry.add_update_listener(async_update_options) data[config_entry.entry_id] = {UNDO_UPDATE_LISTENER: undo_listener} From 8aa0c9bd863d3ddc301f20d8d4ebf478dd20fa39 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Mon, 5 Oct 2026 17:42:46 +0800 Subject: [PATCH 2/2] test: ensure entry update listener unloads --- tests/test_init.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_init.py b/tests/test_init.py index aaf23851..68b56f1a 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -18,7 +18,7 @@ from homeassistant.exceptions import ServiceValidationError from homeassistant.helpers import service from homeassistant.setup import async_setup_component -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, async_mock_service async def test_setup_with_config(hass): @@ -64,6 +64,29 @@ async def test_unload_entry(hass): assert adaptive_lighting.DOMAIN not in hass.data +async def test_config_entry_updated_listener_removed_on_unload(hass): + """Test config entry updates stop reloading YAML after the entry unloads.""" + entry = MockConfigEntry( + domain=adaptive_lighting.DOMAIN, + data={CONF_NAME: DEFAULT_NAME}, + ) + entry.add_to_hass(hass) + calls = async_mock_service(hass, "homeassistant", "check_config") + + assert await hass.config_entries.async_setup(entry.entry_id) + + hass.bus.async_fire("hass.config.entry_updated", {"hass": hass}) + await hass.async_block_till_done() + assert len(calls) == 1 + + assert await hass.config_entries.async_unload(entry.entry_id) + await hass.async_block_till_done() + + hass.bus.async_fire("hass.config.entry_updated", {"hass": hass}) + await hass.async_block_till_done() + assert len(calls) == 1 + + async def test_services_survive_entry_unload_and_reload(hass): """Test integration services remain registered across entry lifecycle.""" assert await async_setup_component(hass, adaptive_lighting.DOMAIN, {})