diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 3ab16f69676..b21ae391e2a 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -954,25 +954,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager): Handler key is the domain of the component that we want to set up. """ - try: - integration = await loader.async_get_integration(self.hass, handler_key) - except loader.IntegrationNotFound as err: - _LOGGER.error("Cannot find integration %s", handler_key) - raise data_entry_flow.UnknownHandler from err - - # Make sure requirements and dependencies of component are resolved - await async_process_deps_reqs(self.hass, self._hass_config, integration) - - try: - integration.get_platform("config_flow") - except ImportError as err: - _LOGGER.error( - "Error occurred loading configuration flow for integration %s: %s", - handler_key, - err, - ) - raise data_entry_flow.UnknownHandler - + await _load_integration(self.hass, handler_key, self._hass_config) if (handler := HANDLERS.get(handler_key)) is None: raise data_entry_flow.UnknownHandler @@ -1842,6 +1824,8 @@ class OptionsFlowManager(data_entry_flow.FlowManager): if entry is None: raise UnknownEntry(handler_key) + await _load_integration(self.hass, entry.domain, {}) + if entry.domain not in HANDLERS: raise data_entry_flow.UnknownHandler @@ -2006,3 +1990,26 @@ async def support_remove_from_device(hass: HomeAssistant, domain: str) -> bool: integration = await loader.async_get_integration(hass, domain) component = integration.get_component() return hasattr(component, "async_remove_config_entry_device") + + +async def _load_integration( + hass: HomeAssistant, domain: str, hass_config: ConfigType +) -> None: + try: + integration = await loader.async_get_integration(hass, domain) + except loader.IntegrationNotFound as err: + _LOGGER.error("Cannot find integration %s", domain) + raise data_entry_flow.UnknownHandler from err + + # Make sure requirements and dependencies of component are resolved + await async_process_deps_reqs(hass, hass_config, integration) + + try: + integration.get_platform("config_flow") + except ImportError as err: + _LOGGER.error( + "Error occurred loading flow for integration %s: %s", + domain, + err, + ) + raise data_entry_flow.UnknownHandler diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index cf8df6aef68..f861d887b99 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -793,6 +793,8 @@ async def test_options_flow(hass: HomeAssistant, client) -> None: return OptionsFlowHandler() + mock_integration(hass, MockModule("test")) + mock_entity_platform(hass, "config_flow.test", None) MockConfigEntry( domain="test", entry_id="test1", @@ -824,6 +826,7 @@ async def test_two_step_options_flow(hass: HomeAssistant, client) -> None: mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) + mock_entity_platform(hass, "config_flow.test", None) class TestFlow(core_ce.ConfigFlow): @staticmethod @@ -889,6 +892,7 @@ async def test_options_flow_with_invalid_data(hass: HomeAssistant, client) -> No mock_integration( hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True)) ) + mock_entity_platform(hass, "config_flow.test", None) class TestFlow(core_ce.ConfigFlow): @staticmethod diff --git a/tests/components/homeassistant_sky_connect/test_config_flow.py b/tests/components/homeassistant_sky_connect/test_config_flow.py index 6ef3d13636e..c74adbf32ea 100644 --- a/tests/components/homeassistant_sky_connect/test_config_flow.py +++ b/tests/components/homeassistant_sky_connect/test_config_flow.py @@ -11,6 +11,7 @@ from homeassistant.components.zha.core.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, MockModule, mock_integration @@ -159,6 +160,7 @@ async def test_option_flow_install_multi_pan_addon( start_addon, ) -> None: """Test installing the multi pan addon.""" + assert await async_setup_component(hass, "usb", {}) mock_integration(hass, MockModule("hassio")) # Setup the config entry @@ -253,6 +255,7 @@ async def test_option_flow_install_multi_pan_addon_zha( start_addon, ) -> None: """Test installing the multi pan addon when a zha config entry exists.""" + assert await async_setup_component(hass, "usb", {}) mock_integration(hass, MockModule("hassio")) # Setup the config entry diff --git a/tests/helpers/test_schema_config_entry_flow.py b/tests/helpers/test_schema_config_entry_flow.py index 9919a53839e..0bc8e0f1ff3 100644 --- a/tests/helpers/test_schema_config_entry_flow.py +++ b/tests/helpers/test_schema_config_entry_flow.py @@ -23,7 +23,13 @@ from homeassistant.helpers.schema_config_entry_flow import ( ) from homeassistant.util.decorator import Registry -from tests.common import MockConfigEntry, mock_platform +from tests.common import ( + MockConfigEntry, + MockModule, + mock_entity_platform, + mock_integration, + mock_platform, +) TEST_DOMAIN = "test" @@ -226,6 +232,8 @@ async def test_options_flow_advanced_option( config_flow = {} options_flow = OPTIONS_FLOW + mock_integration(hass, MockModule("test")) + mock_entity_platform(hass, "config_flow.test", None) config_entry = MockConfigEntry( data={}, domain="test", @@ -513,6 +521,8 @@ async def test_suggested_values( config_flow = {} options_flow = OPTIONS_FLOW + mock_integration(hass, MockModule("test")) + mock_entity_platform(hass, "config_flow.test", None) config_entry = MockConfigEntry( data={}, domain="test", @@ -624,6 +634,8 @@ async def test_options_flow_state(hass: HomeAssistant) -> None: config_flow = {} options_flow = OPTIONS_FLOW + mock_integration(hass, MockModule("test")) + mock_entity_platform(hass, "config_flow.test", None) config_entry = MockConfigEntry( data={}, domain="test", diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 29041730da2..c8cdc561985 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -1101,6 +1101,8 @@ async def test_entry_options( hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can set options on an entry.""" + mock_integration(hass, MockModule("test")) + mock_entity_platform(hass, "config_flow.test", None) entry = MockConfigEntry(domain="test", data={"first": True}, options=None) entry.add_to_manager(manager) @@ -1137,6 +1139,8 @@ async def test_entry_options_abort( hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: """Test that we can abort options flow.""" + mock_integration(hass, MockModule("test")) + mock_entity_platform(hass, "config_flow.test", None) entry = MockConfigEntry(domain="test", data={"first": True}, options=None) entry.add_to_manager(manager)