From 2eb265f28b6907964a6761542e6e2e37d8ab51a5 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 18 Sep 2022 12:17:28 +0200 Subject: [PATCH] Remove mDNS iteration from Plugwise unique ID (#78680) * Remove mDNS iteration from Plugwise unique ID * Add iteration to tests --- homeassistant/components/plugwise/config_flow.py | 2 +- tests/components/plugwise/test_config_flow.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/plugwise/config_flow.py b/homeassistant/components/plugwise/config_flow.py index 3fee1445758d..8cf2456c0b44 100644 --- a/homeassistant/components/plugwise/config_flow.py +++ b/homeassistant/components/plugwise/config_flow.py @@ -91,7 +91,7 @@ class PlugwiseConfigFlow(ConfigFlow, domain=DOMAIN): self.discovery_info = discovery_info _properties = discovery_info.properties - unique_id = discovery_info.hostname.split(".")[0] + unique_id = discovery_info.hostname.split(".")[0].split("-")[0] if config_entry := await self.async_set_unique_id(unique_id): try: await validate_gw_input( diff --git a/tests/components/plugwise/test_config_flow.py b/tests/components/plugwise/test_config_flow.py index 4dbe1d2615ff..84d2335b16f8 100644 --- a/tests/components/plugwise/test_config_flow.py +++ b/tests/components/plugwise/test_config_flow.py @@ -36,7 +36,8 @@ TEST_USERNAME2 = "stretch" TEST_DISCOVERY = ZeroconfServiceInfo( host=TEST_HOST, addresses=[TEST_HOST], - hostname=f"{TEST_HOSTNAME}.local.", + # The added `-2` is to simulate mDNS collision + hostname=f"{TEST_HOSTNAME}-2.local.", name="mock_name", port=DEFAULT_PORT, properties={