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`
This commit is contained in:
J. Nick Koston 2024-03-05 05:02:23 -10:00 committed by GitHub
parent a277d0c4b5
commit 946572e382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 10 deletions

View File

@ -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]:

View File

@ -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"