From 392c46c028368f4d447f1c66702c748ca58284fb Mon Sep 17 00:00:00 2001 From: G Johansson Date: Mon, 27 Apr 2026 08:47:24 +0200 Subject: [PATCH] Remove unique id in dnsip (#169211) Co-authored-by: Copilot --- homeassistant/components/dnsip/__init__.py | 21 ++++++---- homeassistant/components/dnsip/config_flow.py | 7 +--- tests/components/dnsip/test_init.py | 42 ++++++++++++++++++- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/dnsip/__init__.py b/homeassistant/components/dnsip/__init__.py index 52d27e02c269..a2de27131c37 100644 --- a/homeassistant/components/dnsip/__init__.py +++ b/homeassistant/components/dnsip/__init__.py @@ -30,12 +30,10 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> return False if config_entry.version < 2 and config_entry.minor_version < 2: - version = config_entry.version - minor_version = config_entry.minor_version _LOGGER.debug( "Migrating configuration from version %s.%s", - version, - minor_version, + config_entry.version, + config_entry.minor_version, ) new_options = {**config_entry.options} @@ -46,10 +44,19 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> config_entry, options=new_options, minor_version=2 ) + _LOGGER.debug("Migration to configuration version %s.%s successful", 1, 2) + + if config_entry.version < 2 and config_entry.minor_version < 3: _LOGGER.debug( - "Migration to configuration version %s.%s successful", - 1, - 2, + "Migrating configuration from version %s.%s", + config_entry.version, + config_entry.minor_version, ) + hass.config_entries.async_update_entry( + config_entry, unique_id=None, minor_version=3 + ) + + _LOGGER.debug("Migration to configuration version %s.%s successful", 1, 3) + return True diff --git a/homeassistant/components/dnsip/config_flow.py b/homeassistant/components/dnsip/config_flow.py index 24c42408fd25..1e83c7743f24 100644 --- a/homeassistant/components/dnsip/config_flow.py +++ b/homeassistant/components/dnsip/config_flow.py @@ -93,7 +93,7 @@ class DnsIPConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for dnsip integration.""" VERSION = 1 - MINOR_VERSION = 2 + MINOR_VERSION = 3 @staticmethod @callback @@ -133,10 +133,7 @@ class DnsIPConfigFlow(ConfigFlow, domain=DOMAIN): ): errors["base"] = "invalid_hostname" else: - # Uses hostname as unique ID, which is no longer allowed - # pylint: disable-next=hass-unique-id-ip-based - await self.async_set_unique_id(hostname) - self._abort_if_unique_id_configured() + self._async_abort_entries_match({CONF_HOSTNAME: hostname}) return self.async_create_entry( title=name, diff --git a/tests/components/dnsip/test_init.py b/tests/components/dnsip/test_init.py index 8d408b82156a..ffaae3eaaee4 100644 --- a/tests/components/dnsip/test_init.py +++ b/tests/components/dnsip/test_init.py @@ -91,12 +91,52 @@ async def test_port_migration( await hass.async_block_till_done() assert entry.version == 1 - assert entry.minor_version == 2 + assert entry.minor_version == 3 assert entry.options[CONF_PORT] == DEFAULT_PORT assert entry.options[CONF_PORT_IPV6] == DEFAULT_PORT assert entry.state is ConfigEntryState.LOADED +async def test_remove_unique_id_migration( + hass: HomeAssistant, +) -> None: + """Test migration of the config entry removing the unique_id.""" + + entry = MockConfigEntry( + domain=DOMAIN, + source=SOURCE_USER, + data={ + CONF_HOSTNAME: "home-assistant.io", + CONF_NAME: "home-assistant.io", + CONF_IPV4: True, + CONF_IPV6: True, + }, + options={ + CONF_RESOLVER: "208.67.222.222", + CONF_RESOLVER_IPV6: "2620:119:53::53", + CONF_PORT: DEFAULT_PORT, + CONF_PORT_IPV6: DEFAULT_PORT, + }, + entry_id="1", + unique_id="home-assistant.io", + version=1, + minor_version=2, + ) + entry.add_to_hass(hass) + + with patch( + "homeassistant.components.dnsip.sensor.aiodns.DNSResolver", + return_value=RetrieveDNS(), + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert entry.version == 1 + assert entry.minor_version == 3 + assert entry.unique_id is None + assert entry.state is ConfigEntryState.LOADED + + async def test_migrate_error_from_future(hass: HomeAssistant) -> None: """Test a future version isn't migrated."""