From e38836b6e1b9beeaf11a16c4274546c2701dd1a4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 21 Feb 2023 20:17:18 -0600 Subject: [PATCH] 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 --- homeassistant/components/config/config_entries.py | 14 ++++++-------- tests/components/config/test_config_entries.py | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index 39c5bce25cb..88715ab876e 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -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 diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 396962900b1..cf8df6aef68 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -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( {