From 37897ee3849b2e7217da36d8f809085f80f5e44d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 16 Feb 2024 00:55:12 -0600 Subject: [PATCH] Move late import of config flows in loader to load time (#110688) * Move late import of config flows in loader to load time There does not seem to be any reason to import the generated flows late. Import them at load time with the rest of the generated files * tests --- homeassistant/loader.py | 4 +--- tests/components/config/test_config_entries.py | 5 ++--- tests/helpers/test_translation.py | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 60075f38ea2..4abcd8f2c06 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -28,6 +28,7 @@ from . import generated from .core import HomeAssistant, callback from .generated.application_credentials import APPLICATION_CREDENTIALS from .generated.bluetooth import BLUETOOTH +from .generated.config_flows import FLOWS from .generated.dhcp import DHCP from .generated.mqtt import MQTT from .generated.ssdp import SSDP @@ -260,9 +261,6 @@ async def async_get_config_flows( type_filter: Literal["device", "helper", "hub", "service"] | None = None, ) -> set[str]: """Return cached list of config flows.""" - # pylint: disable-next=import-outside-toplevel - from .generated.config_flows import FLOWS - integrations = await async_get_custom_components(hass) flows: set[str] = set() diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 84afee245a6..dbdc113e9e3 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -6,12 +6,11 @@ from unittest.mock import ANY, AsyncMock, patch import pytest import voluptuous as vol -from homeassistant import config_entries as core_ce, data_entry_flow +from homeassistant import config_entries as core_ce, data_entry_flow, loader from homeassistant.components.config import config_entries from homeassistant.config_entries import HANDLERS, ConfigFlow from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS from homeassistant.core import HomeAssistant, callback -from homeassistant.generated import config_flows from homeassistant.helpers import config_entry_flow, config_validation as cv from homeassistant.loader import IntegrationNotFound from homeassistant.setup import async_setup_component @@ -334,7 +333,7 @@ async def test_available_flows( ) -> None: """Test querying the available flows.""" with patch.object( - config_flows, + loader, "FLOWS", {"integration": ["hello", "another"], "helper": ["world"]}, ): diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 40d40e7b534..c4cd615239c 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -6,9 +6,9 @@ from unittest.mock import Mock, call, patch import pytest +from homeassistant import loader from homeassistant.const import EVENT_COMPONENT_LOADED, EVENT_CORE_CONFIG_UPDATE from homeassistant.core import HomeAssistant -from homeassistant.generated import config_flows from homeassistant.helpers import translation from homeassistant.loader import async_get_integration from homeassistant.setup import async_setup_component @@ -18,7 +18,7 @@ from homeassistant.setup import async_setup_component def mock_config_flows(): """Mock the config flows.""" flows = {"integration": [], "helper": {}} - with patch.object(config_flows, "FLOWS", flows): + with patch.object(loader, "FLOWS", flows): yield flows