mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Set the unique ID for discovered deCONZ bridges (#185263)
This commit is contained in:
@@ -92,6 +92,11 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self.bridge_id = bridge["id"]
|
||||
self.host = bridge[CONF_HOST]
|
||||
self.port = bridge[CONF_PORT]
|
||||
await self.async_set_unique_id(self.bridge_id)
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_HOST: self.host, CONF_PORT: self.port},
|
||||
reload_on_update=False,
|
||||
)
|
||||
return await self.async_step_link()
|
||||
|
||||
session = aiohttp_client.async_get_clientsession(self.hass)
|
||||
|
||||
@@ -76,7 +76,6 @@ async def test_flow_discovered_bridges(
|
||||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
# pylint: disable-next=home-assistant-tests-config-flow-unique-id
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == BRIDGE_ID
|
||||
assert result["data"] == {
|
||||
@@ -84,6 +83,35 @@ async def test_flow_discovered_bridges(
|
||||
CONF_PORT: 80,
|
||||
CONF_API_KEY: API_KEY,
|
||||
}
|
||||
assert result["result"].unique_id == BRIDGE_ID
|
||||
|
||||
|
||||
async def test_flow_discovered_bridge_already_configured(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
config_entry_setup: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test that a discovered bridge updates an existing config entry."""
|
||||
aioclient_mock.get(
|
||||
pydeconz.utils.URL_DISCOVER,
|
||||
json=[{"id": BRIDGE_ID, "internalipaddress": "2.3.4.5", "internalport": 80}],
|
||||
headers={"content-type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={CONF_HOST: "2.3.4.5"}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert config_entry_setup.data[CONF_HOST] == "2.3.4.5"
|
||||
|
||||
|
||||
async def test_flow_manual_configuration_decision(
|
||||
|
||||
Reference in New Issue
Block a user