Preload config flow if it exists when loading a component (#112145)
Since config_entries always requires the config_flow to be loaded to check for migrations, load it if we know it exists when loading the underlying integrationpull/112151/head^2
parent
d50b4ccd62
commit
f1eab3f11f
|
@ -908,6 +908,15 @@ class Integration:
|
|||
with suppress(ImportError):
|
||||
self.get_platform("config")
|
||||
|
||||
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[self.domain]
|
||||
|
||||
async def async_get_platform(self, platform_name: str) -> ModuleType:
|
||||
|
|
|
@ -1038,10 +1038,10 @@ async def test_hass_components_use_reported(
|
|||
) in caplog.text
|
||||
|
||||
|
||||
async def test_async_get_component_preloads_config(
|
||||
async def test_async_get_component_preloads_config_and_config_flow(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Verify async_get_component will try to preload the config platform."""
|
||||
"""Verify async_get_component will try to preload the config and config_flow platform."""
|
||||
executor_import_integration = _get_test_integration(
|
||||
hass, "executor_import", True, import_executor=True
|
||||
)
|
||||
|
@ -1058,7 +1058,7 @@ async def test_async_get_component_preloads_config(
|
|||
await executor_import_integration.async_get_component()
|
||||
|
||||
assert mock_platform_exists.call_count == 1
|
||||
assert mock_import.call_count == 2
|
||||
assert mock_import.call_count == 3
|
||||
assert (
|
||||
mock_import.call_args_list[0][0][0]
|
||||
== "homeassistant.components.executor_import"
|
||||
|
@ -1067,6 +1067,10 @@ async def test_async_get_component_preloads_config(
|
|||
mock_import.call_args_list[1][0][0]
|
||||
== "homeassistant.components.executor_import.config"
|
||||
)
|
||||
assert (
|
||||
mock_import.call_args_list[2][0][0]
|
||||
== "homeassistant.components.executor_import.config_flow"
|
||||
)
|
||||
|
||||
|
||||
async def test_async_get_component_deadlock_fallback(
|
||||
|
|
Loading…
Reference in New Issue