Automatically onboard DiscoveryFlows (#73841)
This commit is contained in:
parent
ec119ae718
commit
a8a033681f
2 changed files with 26 additions and 2 deletions
|
@ -6,7 +6,7 @@ import logging
|
||||||
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Union, cast
|
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Union, cast
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import dhcp, mqtt, ssdp, zeroconf
|
from homeassistant.components import dhcp, mqtt, onboarding, ssdp, zeroconf
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow, Generic[_R]):
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Confirm setup."""
|
"""Confirm setup."""
|
||||||
if user_input is None:
|
if user_input is None and onboarding.async_is_onboarded(self.hass):
|
||||||
self._set_confirm_only()
|
self._set_confirm_only()
|
||||||
return self.async_show_form(step_id="confirm")
|
return self.async_show_form(step_id="confirm")
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,30 @@ async def test_discovery_confirmation(hass, discovery_flow_conf, source):
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"source",
|
||||||
|
[
|
||||||
|
config_entries.SOURCE_DISCOVERY,
|
||||||
|
config_entries.SOURCE_MQTT,
|
||||||
|
config_entries.SOURCE_SSDP,
|
||||||
|
config_entries.SOURCE_ZEROCONF,
|
||||||
|
config_entries.SOURCE_DHCP,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_discovery_during_onboarding(hass, discovery_flow_conf, source):
|
||||||
|
"""Test we create config entry via discovery during onboarding."""
|
||||||
|
flow = config_entries.HANDLERS["test"]()
|
||||||
|
flow.hass = hass
|
||||||
|
flow.context = {"source": source}
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.onboarding.async_is_onboarded", return_value=False
|
||||||
|
):
|
||||||
|
result = await getattr(flow, f"async_step_{source}")({})
|
||||||
|
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_discoveries(hass, discovery_flow_conf):
|
async def test_multiple_discoveries(hass, discovery_flow_conf):
|
||||||
"""Test we only create one instance for multiple discoveries."""
|
"""Test we only create one instance for multiple discoveries."""
|
||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue