Handle config entries of integrations that are removed (#68928)

pull/68937/head
Bram Kragten 2022-03-30 23:35:12 +02:00 committed by GitHub
parent 217d98e008
commit 89daf4f96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 4 deletions

View File

@ -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])