mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Allow manually setting up the Thread integration (#86087)
This commit is contained in:
parent
65c4e63e30
commit
cf68d081ca
@ -1,8 +1,11 @@
|
|||||||
"""Config flow for the Open Thread Border Router integration."""
|
"""Config flow for the Open Thread Border Router integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.hassio import HassioServiceInfo
|
from homeassistant.components.hassio import HassioServiceInfo
|
||||||
from homeassistant.config_entries import ConfigFlow
|
from homeassistant.config_entries import ConfigFlow
|
||||||
|
from homeassistant.const import CONF_URL
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -13,6 +16,22 @@ class OTBRConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
|
"""Set up by user."""
|
||||||
|
if self._async_current_entries():
|
||||||
|
return self.async_abort(reason="single_instance_allowed")
|
||||||
|
|
||||||
|
if user_input is not None:
|
||||||
|
return self.async_create_entry(
|
||||||
|
title="Thread",
|
||||||
|
data={"url": user_input[CONF_URL]},
|
||||||
|
)
|
||||||
|
|
||||||
|
data_schema = vol.Schema({CONF_URL: str})
|
||||||
|
return self.async_show_form(step_id="user", data_schema=data_schema)
|
||||||
|
|
||||||
async def async_step_hassio(self, discovery_info: HassioServiceInfo) -> FlowResult:
|
async def async_step_hassio(self, discovery_info: HassioServiceInfo) -> FlowResult:
|
||||||
"""Handle hassio discovery."""
|
"""Handle hassio discovery."""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
|
15
homeassistant/components/otbr/strings.json
Normal file
15
homeassistant/components/otbr/strings.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"step": {
|
||||||
|
"user": {
|
||||||
|
"data": {
|
||||||
|
"url": "[%key:common::config_flow::data::url%]"
|
||||||
|
},
|
||||||
|
"description": "Provide URL for the Open Thread Border Router's REST API"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"abort": {
|
||||||
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,40 @@ HASSIO_DATA = hassio.HassioServiceInfo(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||||
|
"""Test the user flow."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
otbr.DOMAIN, context={"source": "user"}
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_data = {"url": "http://custom_url:1234"}
|
||||||
|
|
||||||
|
assert result["type"] == FlowResultType.FORM
|
||||||
|
assert result["errors"] is None
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.otbr.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry:
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{
|
||||||
|
"url": "http://custom_url:1234",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||||
|
assert result["title"] == "Thread"
|
||||||
|
assert result["data"] == expected_data
|
||||||
|
assert result["options"] == {}
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
config_entry = hass.config_entries.async_entries(otbr.DOMAIN)[0]
|
||||||
|
assert config_entry.data == expected_data
|
||||||
|
assert config_entry.options == {}
|
||||||
|
assert config_entry.title == "Thread"
|
||||||
|
assert config_entry.unique_id is None
|
||||||
|
|
||||||
|
|
||||||
async def test_hassio_discovery_flow(hass: HomeAssistant) -> None:
|
async def test_hassio_discovery_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test the hassio discovery flow."""
|
"""Test the hassio discovery flow."""
|
||||||
with patch(
|
with patch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user