mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Add thread user flow (#88842)
This commit is contained in:
parent
2c2489284b
commit
db1dd16ab0
@ -13,16 +13,23 @@ class ThreadConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_zeroconf(
|
|
||||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
|
||||||
) -> FlowResult:
|
|
||||||
"""Set up because the user has border routers."""
|
|
||||||
await self._async_handle_discovery_without_unique_id()
|
|
||||||
return self.async_create_entry(title="Thread", data={})
|
|
||||||
|
|
||||||
async def async_step_import(
|
async def async_step_import(
|
||||||
self, import_data: dict[str, str] | None = None
|
self, import_data: dict[str, str] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Set up by import from async_setup."""
|
"""Set up by import from async_setup."""
|
||||||
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 self.async_create_entry(title="Thread", data={})
|
||||||
|
|
||||||
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Set up by import from async_setup."""
|
||||||
|
await self._async_handle_discovery_without_unique_id()
|
||||||
|
return self.async_create_entry(title="Thread", data={})
|
||||||
|
|
||||||
|
async def async_step_zeroconf(
|
||||||
|
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Set up because the user has border routers."""
|
||||||
|
await self._async_handle_discovery_without_unique_id()
|
||||||
|
return self.async_create_entry(title="Thread", data={})
|
||||||
|
@ -78,6 +78,29 @@ async def test_import_then_zeroconf(hass: HomeAssistant) -> None:
|
|||||||
assert len(mock_setup_entry.mock_calls) == 0
|
assert len(mock_setup_entry.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user(hass: HomeAssistant) -> None:
|
||||||
|
"""Test the user flow."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.thread.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
thread.DOMAIN, context={"source": "user"}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
assert result["title"] == "Thread"
|
||||||
|
assert result["data"] == {}
|
||||||
|
assert result["options"] == {}
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
config_entry = hass.config_entries.async_entries(thread.DOMAIN)[0]
|
||||||
|
assert config_entry.data == {}
|
||||||
|
assert config_entry.options == {}
|
||||||
|
assert config_entry.title == "Thread"
|
||||||
|
assert config_entry.unique_id is None
|
||||||
|
|
||||||
|
|
||||||
async def test_zeroconf(hass: HomeAssistant) -> None:
|
async def test_zeroconf(hass: HomeAssistant) -> None:
|
||||||
"""Test the zeroconf flow."""
|
"""Test the zeroconf flow."""
|
||||||
with patch(
|
with patch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user