Use constants in acmeda config flow (#58590)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d27c91b9fe
commit
d3bafce157
3 changed files with 13 additions and 10 deletions
|
@ -8,7 +8,8 @@ import aiopulse
|
||||||
import async_timeout
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries, data_entry_flow
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_ID
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
@ -27,9 +28,9 @@ class AcmedaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
if (
|
if (
|
||||||
user_input is not None
|
user_input is not None
|
||||||
and self.discovered_hubs is not None
|
and self.discovered_hubs is not None
|
||||||
and user_input["id"] in self.discovered_hubs
|
and user_input[CONF_ID] in self.discovered_hubs
|
||||||
):
|
):
|
||||||
return await self.async_create(self.discovered_hubs[user_input["id"]])
|
return await self.async_create(self.discovered_hubs[user_input[CONF_ID]])
|
||||||
|
|
||||||
# Already configured hosts
|
# Already configured hosts
|
||||||
already_configured = {
|
already_configured = {
|
||||||
|
@ -52,10 +53,10 @@ class AcmedaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self.discovered_hubs = {hub.id: hub for hub in hubs}
|
self.discovered_hubs = {hub.id: hub for hub in hubs}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id=data_entry_flow.STEP_ID_USER,
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required("id"): vol.In(
|
vol.Required(CONF_ID): vol.In(
|
||||||
{hub.id: f"{hub.id} {hub.host}" for hub in hubs}
|
{hub.id: f"{hub.id} {hub.host}" for hub in hubs}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -65,4 +66,4 @@ class AcmedaFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
async def async_create(self, hub):
|
async def async_create(self, hub):
|
||||||
"""Create the Acmeda Hub entry."""
|
"""Create the Acmeda Hub entry."""
|
||||||
await self.async_set_unique_id(hub.id, raise_on_progress=False)
|
await self.async_set_unique_id(hub.id, raise_on_progress=False)
|
||||||
return self.async_create_entry(title=hub.id, data={"host": hub.host})
|
return self.async_create_entry(title=hub.id, data={CONF_HOST: hub.host})
|
||||||
|
|
|
@ -5,7 +5,7 @@ import abc
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Iterable, Mapping
|
from collections.abc import Iterable, Mapping
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import Any, TypedDict
|
from typing import Any, Final, TypedDict
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -21,6 +21,8 @@ RESULT_TYPE_EXTERNAL_STEP_DONE = "external_done"
|
||||||
RESULT_TYPE_SHOW_PROGRESS = "progress"
|
RESULT_TYPE_SHOW_PROGRESS = "progress"
|
||||||
RESULT_TYPE_SHOW_PROGRESS_DONE = "progress_done"
|
RESULT_TYPE_SHOW_PROGRESS_DONE = "progress_done"
|
||||||
|
|
||||||
|
STEP_ID_USER: Final = "user"
|
||||||
|
|
||||||
# Event that is fired when a flow is progressed via external or progress source.
|
# Event that is fired when a flow is progressed via external or progress source.
|
||||||
EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed"
|
EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed"
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ async def test_show_form_one_hub(hass, mock_hub_discover, mock_hub_run):
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == dummy_hub_1.id
|
assert result["title"] == dummy_hub_1.id
|
||||||
assert result["result"].data == {
|
assert result["result"].data == {
|
||||||
"host": DUMMY_HOST1,
|
CONF_HOST: DUMMY_HOST1,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check we performed the discovery
|
# Check we performed the discovery
|
||||||
|
@ -92,7 +92,7 @@ async def test_show_form_two_hubs(hass, mock_hub_discover):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == data_entry_flow.STEP_ID_USER
|
||||||
|
|
||||||
# Check we performed the discovery
|
# Check we performed the discovery
|
||||||
assert len(mock_hub_discover.mock_calls) == 1
|
assert len(mock_hub_discover.mock_calls) == 1
|
||||||
|
@ -120,7 +120,7 @@ async def test_create_second_entry(hass, mock_hub_run, mock_hub_discover):
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == dummy_hub_2.id
|
assert result["title"] == dummy_hub_2.id
|
||||||
assert result["result"].data == {
|
assert result["result"].data == {
|
||||||
"host": DUMMY_HOST2,
|
CONF_HOST: DUMMY_HOST2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue