From 89daf4f96b1168fcb3ff8b0ffec3bb181f977cea Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 30 Mar 2022 23:35:12 +0200 Subject: [PATCH] Handle config entries of integrations that are removed (#68928) --- .../components/config/config_entries.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index f3a239b5822..64151c7d90d 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -18,7 +18,7 @@ from homeassistant.helpers.data_entry_flow import ( FlowManagerIndexView, FlowManagerResourceView, ) -from homeassistant.loader import async_get_config_flows +from homeassistant.loader import Integration, async_get_config_flows async def async_setup(hass): @@ -63,19 +63,33 @@ class ConfigManagerEntryIndexView(HomeAssistantView): integrations = {} type_filter = request.query["type"] + async def load_integration( + hass: HomeAssistant, domain: str + ) -> Integration | None: + """Load integration.""" + try: + return await loader.async_get_integration(hass, domain) + except loader.IntegrationNotFound: + return None + # Fetch all the integrations so we can check their type for integration in await asyncio.gather( *( - loader.async_get_integration(hass, domain) + load_integration(hass, domain) for domain in {entry.domain for entry in entries} ) ): - integrations[integration.domain] = integration + if integration: + integrations[integration.domain] = integration entries = [ entry for entry in entries - if integrations[entry.domain].integration_type == type_filter + if (type_filter != "helper" and entry.domain not in integrations) + or ( + entry.domain in integrations + and integrations[entry.domain].integration_type == type_filter + ) ] return self.json([entry_json(entry) for entry in entries])