mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add confirm step to thread zeroconf flow (#88869)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
72c0526d87
commit
2112c66804
@ -1,7 +1,9 @@
|
|||||||
"""Config flow for the Thread integration."""
|
"""Config flow for the Thread integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components import zeroconf
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components import onboarding, zeroconf
|
||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
@ -32,4 +34,12 @@ class ThreadConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Set up because the user has border routers."""
|
"""Set up because the user has border routers."""
|
||||||
await self._async_handle_discovery_without_unique_id()
|
await self._async_handle_discovery_without_unique_id()
|
||||||
return self.async_create_entry(title="Thread", data={})
|
return await self.async_step_confirm()
|
||||||
|
|
||||||
|
async def async_step_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Confirm the setup."""
|
||||||
|
if user_input is not None or not onboarding.async_is_onboarded(self.hass):
|
||||||
|
return self.async_create_entry(title="Thread", data={})
|
||||||
|
return self.async_show_form(step_id="confirm")
|
||||||
|
9
homeassistant/components/thread/strings.json
Normal file
9
homeassistant/components/thread/strings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"step": {
|
||||||
|
"confirm": {
|
||||||
|
"description": "[%key:common::config_flow::description::confirm_setup%]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -103,14 +103,18 @@ async def test_user(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_zeroconf(hass: HomeAssistant) -> None:
|
async def test_zeroconf(hass: HomeAssistant) -> None:
|
||||||
"""Test the zeroconf flow."""
|
"""Test the zeroconf flow."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
thread.DOMAIN, context={"source": "zeroconf"}, data=TEST_ZEROCONF_RECORD
|
||||||
|
)
|
||||||
|
assert result["type"] == FlowResultType.FORM
|
||||||
|
assert result["errors"] is None
|
||||||
|
assert result["step_id"] == "confirm"
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.thread.async_setup_entry",
|
"homeassistant.components.thread.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||||
thread.DOMAIN, context={"source": "zeroconf"}, data=TEST_ZEROCONF_RECORD
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "Thread"
|
assert result["title"] == "Thread"
|
||||||
assert result["data"] == {}
|
assert result["data"] == {}
|
||||||
@ -124,16 +128,34 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
|
|||||||
assert config_entry.unique_id is None
|
assert config_entry.unique_id is None
|
||||||
|
|
||||||
|
|
||||||
async def test_zeroconf_then_import(hass: HomeAssistant) -> None:
|
async def test_zeroconf_setup_onboarding(hass: HomeAssistant) -> None:
|
||||||
"""Test the import flow."""
|
"""Test we automatically finish a zeroconf flow during onboarding."""
|
||||||
with patch(
|
with patch(
|
||||||
|
"homeassistant.components.onboarding.async_is_onboarded", return_value=False
|
||||||
|
), patch(
|
||||||
"homeassistant.components.thread.async_setup_entry",
|
"homeassistant.components.thread.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
thread.DOMAIN, context={"source": "zeroconf"}, data=TEST_ZEROCONF_RECORD
|
thread.DOMAIN, context={"source": "zeroconf"}, data=TEST_ZEROCONF_RECORD
|
||||||
)
|
)
|
||||||
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
assert result["title"] == "Thread"
|
||||||
|
assert result["data"] == {}
|
||||||
|
assert result["options"] == {}
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_then_import(hass: HomeAssistant) -> None:
|
||||||
|
"""Test the import flow."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
thread.DOMAIN, context={"source": "zeroconf"}, data=TEST_ZEROCONF_RECORD
|
||||||
|
)
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.thread.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user