mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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:
parent
a277d0c4b5
commit
946572e382
@ -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]:
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user