mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Remove unique id in dnsip (#169211)
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user