mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add unique id to DHCP step in Config Flow for Overkiz (#62847)
This commit is contained in:
parent
1cfeb404b6
commit
b9ce82f79c
@ -19,7 +19,6 @@ from homeassistant import config_entries
|
|||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import device_registry as dr
|
|
||||||
|
|
||||||
from .const import CONF_HUB, DEFAULT_HUB, DOMAIN
|
from .const import CONF_HUB, DEFAULT_HUB, DOMAIN
|
||||||
|
|
||||||
@ -94,17 +93,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
_LOGGER.debug("DHCP discovery detected gateway %s", obfuscate_id(gateway_id))
|
_LOGGER.debug("DHCP discovery detected gateway %s", obfuscate_id(gateway_id))
|
||||||
|
|
||||||
if self._gateway_already_configured(gateway_id):
|
await self.async_set_unique_id(gateway_id)
|
||||||
_LOGGER.debug("Gateway %s is already configured", obfuscate_id(gateway_id))
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
def _gateway_already_configured(self, gateway_id: str) -> bool:
|
|
||||||
"""See if we already have a gateway matching the id."""
|
|
||||||
device_registry = dr.async_get(self.hass)
|
|
||||||
return bool(
|
|
||||||
device_registry.async_get_device(
|
|
||||||
identifiers={(DOMAIN, gateway_id)}, connections=set()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.components import dhcp
|
|||||||
from homeassistant.components.overkiz.const import DOMAIN
|
from homeassistant.components.overkiz.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, mock_device_registry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
TEST_EMAIL = "test@testdomain.com"
|
TEST_EMAIL = "test@testdomain.com"
|
||||||
TEST_EMAIL2 = "test@testdomain.nl"
|
TEST_EMAIL2 = "test@testdomain.nl"
|
||||||
@ -120,7 +120,7 @@ async def test_allow_multiple_unique_entries(hass: HomeAssistant) -> None:
|
|||||||
"""Test config flow allows Config Flow unique entries."""
|
"""Test config flow allows Config Flow unique entries."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id="test2@testdomain.com",
|
unique_id=TEST_GATEWAY_ID2,
|
||||||
data={"username": "test2@testdomain.com", "password": TEST_PASSWORD},
|
data={"username": "test2@testdomain.com", "password": TEST_PASSWORD},
|
||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
|
||||||
@ -166,17 +166,11 @@ async def test_dhcp_flow_already_configured(hass: HomeAssistant) -> None:
|
|||||||
"""Test that DHCP doesn't setup already configured gateways."""
|
"""Test that DHCP doesn't setup already configured gateways."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id=TEST_EMAIL,
|
unique_id=TEST_GATEWAY_ID,
|
||||||
data={"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB},
|
data={"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB},
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
device_registry = mock_device_registry(hass)
|
|
||||||
device_registry.async_get_or_create(
|
|
||||||
config_entry_id=config_entry.entry_id,
|
|
||||||
identifiers={(DOMAIN, "1234-5678-9123")},
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
data=dhcp.DhcpServiceInfo(
|
data=dhcp.DhcpServiceInfo(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user