From 946572e382fe3f10646bd7949982329bfef17a85 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 5 Mar 2024 05:02:23 -1000 Subject: [PATCH] Simplify loader preload logic for config_flows (#112290) We previously checked Integration.config_flow to see if we should pre-import the config flow, but this is now always set for some integration like `homeassistant_green`, `hassio`, etc. Instead we can add it to the rest of the platforms since we already know which files exist. This simplifies the logic and ensures the pre-import still happens if the file is there even if its not listed in the manifest `2024-03-04 22:54:31.906 DEBUG (MainThread) [homeassistant.loader] Importing platforms for homeassistant_green executor=[config_flow] loop=[] took 2.74s` --- homeassistant/loader.py | 10 +--------- tests/test_loader.py | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 95b00547fb8..ac1d71a632c 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -67,6 +67,7 @@ _LOGGER = logging.getLogger(__name__) # BASE_PRELOAD_PLATFORMS = [ "config", + "config_flow", "diagnostics", "energy", "group", @@ -1006,15 +1007,6 @@ class Integration: with suppress(ImportError): self.get_platform(platform_name) - if self.config_flow: - # If there is a config flow, we will cache it as well since - # config entry setup always has to load the flow to get the - # major/minor version for migrations. Since we may be running - # in the executor we will use this opportunity to cache the - # config_flow as well. - with suppress(ImportError): - self.get_platform("config_flow") - return cache[domain] def _load_platforms(self, platform_names: Iterable[str]) -> dict[str, ModuleType]: diff --git a/tests/test_loader.py b/tests/test_loader.py index 8be7cf09b2c..22379b340d4 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1117,7 +1117,7 @@ async def test_async_get_component_preloads_config_and_config_flow( await executor_import_integration.async_get_component() assert len(platform_exists_calls[0]) == len(loader.BASE_PRELOAD_PLATFORMS) - assert mock_import.call_count == 2 + len(loader.BASE_PRELOAD_PLATFORMS) + assert mock_import.call_count == 1 + len(loader.BASE_PRELOAD_PLATFORMS) assert ( mock_import.call_args_list[0][0][0] == "homeassistant.components.executor_import"