Migrate Nexia unique id to str (#126911)
This commit is contained in:
parent
9f2ba6bc2c
commit
308f25fe4c
4 changed files with 45 additions and 2 deletions
|
@ -86,3 +86,21 @@ async def async_remove_config_entry_device(
|
||||||
if zone_id in dev_ids:
|
if zone_id in dev_ids:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def async_migrate_entry(hass: HomeAssistant, entry: NexiaConfigEntry) -> bool:
|
||||||
|
"""Migrate entry."""
|
||||||
|
|
||||||
|
_LOGGER.debug("Migrating from version %s", entry.version)
|
||||||
|
|
||||||
|
if entry.version == 1:
|
||||||
|
# 1 -> 2: Unique ID from integer to string
|
||||||
|
if entry.minor_version == 1:
|
||||||
|
minor_version = 2
|
||||||
|
hass.config_entries.async_update_entry(
|
||||||
|
entry, unique_id=str(entry.unique_id), minor_version=minor_version
|
||||||
|
)
|
||||||
|
|
||||||
|
_LOGGER.debug("Migration successful")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
|
@ -81,6 +81,7 @@ class NexiaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Nexia."""
|
"""Handle a config flow for Nexia."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
MINOR_VERSION = 2
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
@ -99,7 +100,7 @@ class NexiaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
|
|
||||||
if "base" not in errors:
|
if "base" not in errors:
|
||||||
await self.async_set_unique_id(info["house_id"])
|
await self.async_set_unique_id(str(info["house_id"]))
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(title=info["title"], data=user_input)
|
return self.async_create_entry(title=info["title"], data=user_input)
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
"""The init tests for the nexia platform."""
|
"""The init tests for the nexia platform."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from homeassistant.components.nexia.const import DOMAIN
|
from homeassistant.components.nexia.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .util import async_init_integration
|
from .util import async_init_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
from tests.typing import WebSocketGenerator
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,3 +52,20 @@ async def test_device_remove_devices(
|
||||||
)
|
)
|
||||||
response = await client.remove_device(dead_device_entry.id, entry_id)
|
response = await client.remove_device(dead_device_entry.id, entry_id)
|
||||||
assert response["success"]
|
assert response["success"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_migrate_entry_minor_version_1_2(hass: HomeAssistant) -> None:
|
||||||
|
"""Test migrating a 1.1 config entry to 1.2."""
|
||||||
|
with patch("homeassistant.components.nexia.async_setup_entry", return_value=True):
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"},
|
||||||
|
version=1,
|
||||||
|
minor_version=1,
|
||||||
|
unique_id=123456,
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
assert entry.version == 1
|
||||||
|
assert entry.minor_version == 2
|
||||||
|
assert entry.unique_id == "123456"
|
||||||
|
|
|
@ -54,7 +54,10 @@ async def async_init_integration(
|
||||||
text=load_fixture(set_fan_speed_fixture),
|
text=load_fixture(set_fan_speed_fixture),
|
||||||
)
|
)
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"}
|
domain=DOMAIN,
|
||||||
|
data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"},
|
||||||
|
minor_version=2,
|
||||||
|
unique_id="123456",
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue