From b9ce82f79c81b014fb050a3e04d85b4902862e65 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Mon, 27 Dec 2021 13:28:18 -0800 Subject: [PATCH] Add unique id to DHCP step in Config Flow for Overkiz (#62847) --- homeassistant/components/overkiz/config_flow.py | 15 ++------------- tests/components/overkiz/test_config_flow.py | 12 +++--------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/overkiz/config_flow.py b/homeassistant/components/overkiz/config_flow.py index 673a946d35f..c4748b82751 100644 --- a/homeassistant/components/overkiz/config_flow.py +++ b/homeassistant/components/overkiz/config_flow.py @@ -19,7 +19,6 @@ from homeassistant import config_entries from homeassistant.components import dhcp from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers import device_registry as dr 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)) - if self._gateway_already_configured(gateway_id): - _LOGGER.debug("Gateway %s is already configured", obfuscate_id(gateway_id)) - return self.async_abort(reason="already_configured") + await self.async_set_unique_id(gateway_id) + self._abort_if_unique_id_configured() 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() - ) - ) diff --git a/tests/components/overkiz/test_config_flow.py b/tests/components/overkiz/test_config_flow.py index c9c745c9665..9de94eab36c 100644 --- a/tests/components/overkiz/test_config_flow.py +++ b/tests/components/overkiz/test_config_flow.py @@ -16,7 +16,7 @@ from homeassistant.components import dhcp from homeassistant.components.overkiz.const import DOMAIN from homeassistant.core import HomeAssistant -from tests.common import MockConfigEntry, mock_device_registry +from tests.common import MockConfigEntry TEST_EMAIL = "test@testdomain.com" 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.""" MockConfigEntry( domain=DOMAIN, - unique_id="test2@testdomain.com", + unique_id=TEST_GATEWAY_ID2, data={"username": "test2@testdomain.com", "password": TEST_PASSWORD}, ).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.""" config_entry = MockConfigEntry( domain=DOMAIN, - unique_id=TEST_EMAIL, + unique_id=TEST_GATEWAY_ID, data={"username": TEST_EMAIL, "password": TEST_PASSWORD, "hub": TEST_HUB}, ) 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( DOMAIN, data=dhcp.DhcpServiceInfo(