mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Try to load integration before starting option flow (#90111)
* Try to load integration before starting option flow * Adjust tests
This commit is contained in:
parent
6db8867b81
commit
3931e11fd9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user