Revert "Avoid pre-importing config_flows if the integration does not … (#113553)

Revert "Avoid pre-importing config_flows if the integration does not support …"

This reverts commit 9940f51b95.
This commit is contained in:
G Johansson
2024-03-15 23:15:36 +01:00
committed by GitHub
parent 77a94ea515
commit e8de1a7031
7 changed files with 42 additions and 89 deletions

View File

@@ -1204,21 +1204,31 @@ async def test_async_get_component_loads_loop_if_already_in_sys_modules(
assert "test_package_loaded_executor" not in hass.config.components
assert "test_package_loaded_executor.config_flow" not in hass.config.components
module_mock = object()
config_flow_module_name = f"{integration.pkg_path}.config_flow"
module_mock = MagicMock(__file__="__init__.py")
config_flow_module_mock = MagicMock(__file__="config_flow.py")
def import_module(name: str) -> Any:
if name == integration.pkg_path:
return module_mock
if name == config_flow_module_name:
return config_flow_module_mock
raise ImportError
modules_without_config_flow = {
k: v for k, v in sys.modules.items() if k != config_flow_module_name
}
with patch.dict(
"sys.modules",
{**sys.modules, integration.pkg_path: module_mock},
{**modules_without_config_flow, integration.pkg_path: module_mock},
clear=True,
), patch("homeassistant.loader.importlib.import_module", import_module):
module = await integration.async_get_component()
assert "loaded_executor=False" in caplog.text
# The config flow is missing so we should load
# in the executor
assert "loaded_executor=True" in caplog.text
assert "loaded_executor=False" not in caplog.text
assert module is module_mock
caplog.clear()
@@ -1226,6 +1236,7 @@ async def test_async_get_component_loads_loop_if_already_in_sys_modules(
"sys.modules",
{
integration.pkg_path: module_mock,
config_flow_module_name: config_flow_module_mock,
},
), patch("homeassistant.loader.importlib.import_module", import_module):
module = await integration.async_get_component()
@@ -1235,10 +1246,6 @@ async def test_async_get_component_loads_loop_if_already_in_sys_modules(
assert "loaded_executor" not in caplog.text
assert module is module_mock
# The integration does not implement async_migrate_entry so it
# should not be preloaded
assert integration.get_platform_cached("config_flow") is None
async def test_async_get_component_concurrent_loads(
hass: HomeAssistant,