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

View File

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