Update async_matching_config_entries to use async_get_integrations (#88527)

* Update async_matching_config_entries to use async_get_integrations

* Update homeassistant/components/config/config_entries.py

* Update homeassistant/components/config/config_entries.py
This commit is contained in:
J. Nick Koston 2023-02-21 20:17:18 -06:00 committed by GitHub
parent 5bc0636905
commit e38836b6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -1,7 +1,6 @@
"""Http views to control the config manager."""
from __future__ import annotations
import asyncio
from http import HTTPStatus
from typing import Any
@ -26,6 +25,7 @@ from homeassistant.loader import (
IntegrationNotFound,
async_get_config_flows,
async_get_integration,
async_get_integrations,
)
@ -493,14 +493,12 @@ async def async_matching_config_entries(
integrations = {}
# Fetch all the integrations so we can check their type
tasks = (
async_get_integration(hass, domain)
for domain in {entry.domain for entry in entries}
)
results = await asyncio.gather(*tasks, return_exceptions=True)
for integration_or_exc in results:
domains = {entry.domain for entry in entries}
for domain_key, integration_or_exc in (
await async_get_integrations(hass, domains)
).items():
if isinstance(integration_or_exc, Integration):
integrations[integration_or_exc.domain] = integration_or_exc
integrations[domain_key] = integration_or_exc
elif not isinstance(integration_or_exc, IntegrationNotFound):
raise integration_or_exc

View File

@ -1446,8 +1446,8 @@ async def test_get_entries_ws(
# Verify we skip broken integrations
with patch(
"homeassistant.components.config.config_entries.async_get_integration",
side_effect=IntegrationNotFound("any"),
"homeassistant.components.config.config_entries.async_get_integrations",
return_value={"any": IntegrationNotFound("any")},
):
await ws_client.send_json(
{
@ -1534,8 +1534,8 @@ async def test_get_entries_ws(
# Verify we don't send config entries when only helpers are requested
with patch(
"homeassistant.components.config.config_entries.async_get_integration",
side_effect=IntegrationNotFound("any"),
"homeassistant.components.config.config_entries.async_get_integrations",
return_value={"any": IntegrationNotFound("any")},
):
await ws_client.send_json(
{
@ -1552,8 +1552,8 @@ async def test_get_entries_ws(
# Verify we raise if something really goes wrong
with patch(
"homeassistant.components.config.config_entries.async_get_integration",
side_effect=Exception,
"homeassistant.components.config.config_entries.async_get_integrations",
return_value={"any": Exception()},
):
await ws_client.send_json(
{