From dc14b832494bbb2bd24bf310cd8c8348a57575c2 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 24 May 2023 09:38:29 +0200 Subject: [PATCH] Add ability to unload demo integration (#92515) * Add unload to demo integration * Adjust config tests to use kitchen_sink * Use async_unload_platforms --- homeassistant/components/demo/__init__.py | 8 ++++++++ tests/components/config/test_config_entries.py | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/demo/__init__.py b/homeassistant/components/demo/__init__.py index 85f7b89483f..b941d31898c 100644 --- a/homeassistant/components/demo/__init__.py +++ b/homeassistant/components/demo/__init__.py @@ -188,6 +188,14 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b return True +async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: + """Unload a config entry.""" + await hass.config_entries.async_unload_platforms( + config_entry, COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM + ) + return True + + async def finish_setup(hass: HomeAssistant, config: ConfigType) -> None: """Finish set up once demo platforms are set up.""" switches: list[str] | None = None diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index d54abe77276..bbc6ce210cb 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -216,7 +216,9 @@ async def test_get_entries(hass: HomeAssistant, client, clear_handlers) -> None: async def test_remove_entry(hass: HomeAssistant, client) -> None: """Test removing an entry via the API.""" - entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) + entry = MockConfigEntry( + domain="kitchen_sink", state=core_ce.ConfigEntryState.LOADED + ) entry.add_to_hass(hass) resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}") assert resp.status == HTTPStatus.OK @@ -227,7 +229,9 @@ async def test_remove_entry(hass: HomeAssistant, client) -> None: async def test_reload_entry(hass: HomeAssistant, client) -> None: """Test reloading an entry via the API.""" - entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) + entry = MockConfigEntry( + domain="kitchen_sink", state=core_ce.ConfigEntryState.LOADED + ) entry.add_to_hass(hass) resp = await client.post( f"/api/config/config_entries/entry/{entry.entry_id}/reload" @@ -1021,7 +1025,9 @@ async def test_update_prefrences( assert await async_setup_component(hass, "config", {}) ws_client = await hass_ws_client(hass) - entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) + entry = MockConfigEntry( + domain="kitchen_sink", state=core_ce.ConfigEntryState.LOADED + ) entry.add_to_hass(hass) assert entry.pref_disable_new_entities is False @@ -1118,7 +1124,9 @@ async def test_disable_entry( assert await async_setup_component(hass, "config", {}) ws_client = await hass_ws_client(hass) - entry = MockConfigEntry(domain="demo", state=core_ce.ConfigEntryState.LOADED) + entry = MockConfigEntry( + domain="kitchen_sink", state=core_ce.ConfigEntryState.LOADED + ) entry.add_to_hass(hass) assert entry.disabled_by is None