From 7a1291b217de54593e3ff685af6781ee1ddc3c89 Mon Sep 17 00:00:00 2001 From: Duco Sebel <74970928+DCSBL@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:36:30 +0000 Subject: [PATCH 1/4] Add migration for total_power_t1 to total_power sensors for HWE-SKT --- homeassistant/components/homewizard/sensor.py | 57 ++++++++++++++++- .../homewizard/test_sensor_migration.py | 64 +++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tests/components/homewizard/test_sensor_migration.py diff --git a/homeassistant/components/homewizard/sensor.py b/homeassistant/components/homewizard/sensor.py index 78cee9ee6fec9..688a0c155e902 100644 --- a/homeassistant/components/homewizard/sensor.py +++ b/homeassistant/components/homewizard/sensor.py @@ -3,6 +3,7 @@ from collections.abc import Callable from dataclasses import dataclass +import logging from typing import Final from homewizard_energy.models import Data @@ -24,7 +25,8 @@ UnitOfPower, UnitOfVolume, ) -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -33,6 +35,7 @@ from .entity import HomeWizardEntity PARALLEL_UPDATES = 1 +_LOGGER = logging.getLogger(__name__) @dataclass(kw_only=True) @@ -431,12 +434,64 @@ class HomeWizardSensorEntityDescription(SensorEntityDescription): ) +async def _async_migrate_entries( + hass: HomeAssistant, config_entry: ConfigEntry +) -> bool: + """Migrate old entry. + + The HWE-SKT had no total_power_*_kwh in 2023.11, in 2023.12 it does. + But simultaneously, the total_power_*_t1_kwh was removed for HWE-SKT. + + This migration migrates the old unique_id to the new one, if possible. + + Migration can be removed after 2023.6 + """ + entity_registry = er.async_get(hass) + + @callback + def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None: + replacements = { + "total_power_import_t1_kwh": "total_power_import_kwh", + "total_power_export_t1_kwh": "total_power_export_kwh", + } + + for old_id, new_id in replacements.items(): + if entry.unique_id.endswith(old_id): + new_unique_id = entry.unique_id.replace(old_id, new_id) + _LOGGER.debug( + "Migrating entity '%s' unique_id from '%s' to '%s'", + entry.entity_id, + entry.unique_id, + new_unique_id, + ) + if existing_entity_id := entity_registry.async_get_entity_id( + entry.domain, entry.platform, new_unique_id + ): + _LOGGER.debug( + "Cannot migrate to unique_id '%s', already exists for '%s'", + new_unique_id, + existing_entity_id, + ) + return None + return { + "new_unique_id": new_unique_id, + } + + return None + + await er.async_migrate_entries(hass, config_entry.entry_id, update_unique_id) + + return True + + async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Initialize sensors.""" coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + await _async_migrate_entries(hass, entry) + async_add_entities( HomeWizardSensorEntity(coordinator, description) for description in SENSORS diff --git a/tests/components/homewizard/test_sensor_migration.py b/tests/components/homewizard/test_sensor_migration.py new file mode 100644 index 0000000000000..1c1275f75ebd4 --- /dev/null +++ b/tests/components/homewizard/test_sensor_migration.py @@ -0,0 +1,64 @@ +"""Test sensor entity migration for HomeWizard.""" + + +import pytest + +from homeassistant.components.homewizard.const import DOMAIN +from homeassistant.const import Platform +from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er + +from tests.common import MockConfigEntry + + +@pytest.mark.parametrize( + ("device_fixture", "entitydata", "old_unique_id", "new_unique_id"), + [ + ( + "HWE-SKT", + { + "domain": Platform.SENSOR, + "platform": DOMAIN, + "unique_id": "aabbccddeeff_total_power_import_t1_kwh", + }, + "aabbccddeeff_total_power_import_t1_kwh", + "aabbccddeeff_total_power_import_kwh", + ), + ( + "HWE-SKT", + { + "domain": Platform.SENSOR, + "platform": DOMAIN, + "unique_id": "aabbccddeeff_total_power_export_t1_kwh", + }, + "aabbccddeeff_total_power_export_t1_kwh", + "aabbccddeeff_total_power_export_kwh", + ), + ], +) +@pytest.mark.usefixtures("mock_homewizardenergy") +async def test_sensor_migration( + hass: HomeAssistant, + entitydata: dict, + old_unique_id: str, + new_unique_id: str, + entity_registry: er.EntityRegistry, + mock_config_entry: MockConfigEntry, +) -> None: + """Test total power T1 sensors are migrated.""" + mock_config_entry.add_to_hass(hass) + + entity: er.RegistryEntry = entity_registry.async_get_or_create( + **entitydata, + config_entry=mock_config_entry, + ) + + assert entity.unique_id == old_unique_id + + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + entity_migrated = entity_registry.async_get(entity.entity_id) + assert entity_migrated + assert entity_migrated.unique_id == new_unique_id + assert entity_migrated.previous_unique_id == old_unique_id From 275f669124cce7ccbb8a16ebbe6a4a18cc9277c3 Mon Sep 17 00:00:00 2001 From: Duco Sebel <74970928+DCSBL@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:43:00 +0000 Subject: [PATCH 2/4] Add test to make sure migration does not happend when non-T1 sensor already exists --- .../homewizard/test_sensor_migration.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/components/homewizard/test_sensor_migration.py b/tests/components/homewizard/test_sensor_migration.py index 1c1275f75ebd4..21589258941d8 100644 --- a/tests/components/homewizard/test_sensor_migration.py +++ b/tests/components/homewizard/test_sensor_migration.py @@ -62,3 +62,60 @@ async def test_sensor_migration( assert entity_migrated assert entity_migrated.unique_id == new_unique_id assert entity_migrated.previous_unique_id == old_unique_id + + +@pytest.mark.parametrize( + ("device_fixture", "old_unique_id", "new_unique_id"), + [ + ( + "HWE-SKT", + "aabbccddeeff_total_power_import_t1_kwh", + "aabbccddeeff_total_power_import_kwh", + ), + ( + "HWE-SKT", + "aabbccddeeff_total_power_export_t1_kwh", + "aabbccddeeff_total_power_export_kwh", + ), + ], +) +@pytest.mark.usefixtures("mock_homewizardenergy") +async def test_sensor_migration_does_not_trigger( + hass: HomeAssistant, + old_unique_id: str, + new_unique_id: str, + entity_registry: er.EntityRegistry, + mock_config_entry: MockConfigEntry, +) -> None: + """Test total power T1 sensors are not migrated when not needed.""" + mock_config_entry.add_to_hass(hass) + + old_entity: er.RegistryEntry = entity_registry.async_get_or_create( + domain=Platform.SENSOR, + platform=DOMAIN, + unique_id=old_unique_id, + config_entry=mock_config_entry, + ) + + new_entity: er.RegistryEntry = entity_registry.async_get_or_create( + domain=Platform.SENSOR, + platform=DOMAIN, + unique_id=new_unique_id, + config_entry=mock_config_entry, + ) + + assert old_entity.unique_id == old_unique_id + assert new_entity.unique_id == new_unique_id + + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + entity = entity_registry.async_get(old_entity.entity_id) + assert entity + assert entity.unique_id == old_unique_id + assert entity.previous_unique_id is None + + entity = entity_registry.async_get(new_entity.entity_id) + assert entity + assert entity.unique_id == new_unique_id + assert entity.previous_unique_id is None From 1722df134c9dd70801f43ee5bc225540c6d28d3e Mon Sep 17 00:00:00 2001 From: Duco Sebel <74970928+DCSBL@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:44:56 +0000 Subject: [PATCH 3/4] Simplify test --- .../homewizard/test_sensor_migration.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/components/homewizard/test_sensor_migration.py b/tests/components/homewizard/test_sensor_migration.py index 21589258941d8..d51c2d8c5b8c8 100644 --- a/tests/components/homewizard/test_sensor_migration.py +++ b/tests/components/homewizard/test_sensor_migration.py @@ -12,25 +12,15 @@ @pytest.mark.parametrize( - ("device_fixture", "entitydata", "old_unique_id", "new_unique_id"), + ("device_fixture", "old_unique_id", "new_unique_id"), [ ( "HWE-SKT", - { - "domain": Platform.SENSOR, - "platform": DOMAIN, - "unique_id": "aabbccddeeff_total_power_import_t1_kwh", - }, "aabbccddeeff_total_power_import_t1_kwh", "aabbccddeeff_total_power_import_kwh", ), ( "HWE-SKT", - { - "domain": Platform.SENSOR, - "platform": DOMAIN, - "unique_id": "aabbccddeeff_total_power_export_t1_kwh", - }, "aabbccddeeff_total_power_export_t1_kwh", "aabbccddeeff_total_power_export_kwh", ), @@ -39,7 +29,6 @@ @pytest.mark.usefixtures("mock_homewizardenergy") async def test_sensor_migration( hass: HomeAssistant, - entitydata: dict, old_unique_id: str, new_unique_id: str, entity_registry: er.EntityRegistry, @@ -49,7 +38,9 @@ async def test_sensor_migration( mock_config_entry.add_to_hass(hass) entity: er.RegistryEntry = entity_registry.async_get_or_create( - **entitydata, + domain=Platform.SENSOR, + platform=DOMAIN, + unique_id=old_unique_id, config_entry=mock_config_entry, ) @@ -87,7 +78,7 @@ async def test_sensor_migration_does_not_trigger( entity_registry: er.EntityRegistry, mock_config_entry: MockConfigEntry, ) -> None: - """Test total power T1 sensors are not migrated when not needed.""" + """Test total power T1 sensors are not migrated when not possible.""" mock_config_entry.add_to_hass(hass) old_entity: er.RegistryEntry = entity_registry.async_get_or_create( From bd0eba2c049560b204ff39b71ced5ae94785826d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 8 Dec 2023 09:18:55 +0100 Subject: [PATCH 4/4] Little bit of re-organization --- .../components/homewizard/__init__.py | 55 ++++++++- homeassistant/components/homewizard/const.py | 3 + homeassistant/components/homewizard/sensor.py | 58 +-------- tests/components/homewizard/test_init.py | 103 ++++++++++++++++ .../homewizard/test_sensor_migration.py | 112 ------------------ 5 files changed, 160 insertions(+), 171 deletions(-) delete mode 100644 tests/components/homewizard/test_sensor_migration.py diff --git a/homeassistant/components/homewizard/__init__.py b/homeassistant/components/homewizard/__init__.py index 036f6c077daff..35b303a62e3f4 100644 --- a/homeassistant/components/homewizard/__init__.py +++ b/homeassistant/components/homewizard/__init__.py @@ -1,12 +1,61 @@ """The Homewizard integration.""" from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers import entity_registry as er -from .const import DOMAIN, PLATFORMS +from .const import DOMAIN, LOGGER, PLATFORMS from .coordinator import HWEnergyDeviceUpdateCoordinator as Coordinator +async def _async_migrate_entries( + hass: HomeAssistant, config_entry: ConfigEntry +) -> None: + """Migrate old entry. + + The HWE-SKT had no total_power_*_kwh in 2023.11, in 2023.12 it does. + But simultaneously, the total_power_*_t1_kwh was removed for HWE-SKT. + + This migration migrates the old unique_id to the new one, if possible. + + Migration can be removed after 2024.6 + """ + entity_registry = er.async_get(hass) + + @callback + def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None: + replacements = { + "total_power_import_t1_kwh": "total_power_import_kwh", + "total_power_export_t1_kwh": "total_power_export_kwh", + } + + for old_id, new_id in replacements.items(): + if entry.unique_id.endswith(old_id): + new_unique_id = entry.unique_id.replace(old_id, new_id) + if existing_entity_id := entity_registry.async_get_entity_id( + entry.domain, entry.platform, new_unique_id + ): + LOGGER.debug( + "Cannot migrate to unique_id '%s', already exists for '%s'", + new_unique_id, + existing_entity_id, + ) + return None + LOGGER.debug( + "Migrating entity '%s' unique_id from '%s' to '%s'", + entry.entity_id, + entry.unique_id, + new_unique_id, + ) + return { + "new_unique_id": new_unique_id, + } + + return None + + await er.async_migrate_entries(hass, config_entry.entry_id, update_unique_id) + + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Homewizard from a config entry.""" coordinator = Coordinator(hass) @@ -21,6 +70,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: raise + await _async_migrate_entries(hass, entry) + hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator # Abort reauth config flow if active diff --git a/homeassistant/components/homewizard/const.py b/homeassistant/components/homewizard/const.py index ff0655922832e..d4692ee8bf07f 100644 --- a/homeassistant/components/homewizard/const.py +++ b/homeassistant/components/homewizard/const.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from datetime import timedelta +import logging from homewizard_energy.models import Data, Device, State, System @@ -11,6 +12,8 @@ DOMAIN = "homewizard" PLATFORMS = [Platform.BUTTON, Platform.NUMBER, Platform.SENSOR, Platform.SWITCH] +LOGGER = logging.getLogger(__package__) + # Platform config. CONF_API_ENABLED = "api_enabled" CONF_DATA = "data" diff --git a/homeassistant/components/homewizard/sensor.py b/homeassistant/components/homewizard/sensor.py index 688a0c155e902..d980e66e0e4cb 100644 --- a/homeassistant/components/homewizard/sensor.py +++ b/homeassistant/components/homewizard/sensor.py @@ -3,7 +3,6 @@ from collections.abc import Callable from dataclasses import dataclass -import logging from typing import Final from homewizard_energy.models import Data @@ -25,8 +24,7 @@ UnitOfPower, UnitOfVolume, ) -from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import entity_registry as er +from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -35,7 +33,6 @@ from .entity import HomeWizardEntity PARALLEL_UPDATES = 1 -_LOGGER = logging.getLogger(__name__) @dataclass(kw_only=True) @@ -434,64 +431,11 @@ class HomeWizardSensorEntityDescription(SensorEntityDescription): ) -async def _async_migrate_entries( - hass: HomeAssistant, config_entry: ConfigEntry -) -> bool: - """Migrate old entry. - - The HWE-SKT had no total_power_*_kwh in 2023.11, in 2023.12 it does. - But simultaneously, the total_power_*_t1_kwh was removed for HWE-SKT. - - This migration migrates the old unique_id to the new one, if possible. - - Migration can be removed after 2023.6 - """ - entity_registry = er.async_get(hass) - - @callback - def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None: - replacements = { - "total_power_import_t1_kwh": "total_power_import_kwh", - "total_power_export_t1_kwh": "total_power_export_kwh", - } - - for old_id, new_id in replacements.items(): - if entry.unique_id.endswith(old_id): - new_unique_id = entry.unique_id.replace(old_id, new_id) - _LOGGER.debug( - "Migrating entity '%s' unique_id from '%s' to '%s'", - entry.entity_id, - entry.unique_id, - new_unique_id, - ) - if existing_entity_id := entity_registry.async_get_entity_id( - entry.domain, entry.platform, new_unique_id - ): - _LOGGER.debug( - "Cannot migrate to unique_id '%s', already exists for '%s'", - new_unique_id, - existing_entity_id, - ) - return None - return { - "new_unique_id": new_unique_id, - } - - return None - - await er.async_migrate_entries(hass, config_entry.entry_id, update_unique_id) - - return True - - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Initialize sensors.""" coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - - await _async_migrate_entries(hass, entry) - async_add_entities( HomeWizardSensorEntity(coordinator, description) for description in SENSORS diff --git a/tests/components/homewizard/test_init.py b/tests/components/homewizard/test_init.py index 7dab8cfbb06d4..a4893c77f42f4 100644 --- a/tests/components/homewizard/test_init.py +++ b/tests/components/homewizard/test_init.py @@ -7,7 +7,9 @@ from homeassistant.components.homewizard.const import DOMAIN from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState +from homeassistant.const import Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry @@ -118,3 +120,104 @@ async def test_load_handles_homewizardenergy_exception( ConfigEntryState.SETUP_RETRY, ConfigEntryState.SETUP_ERROR, ) + + +@pytest.mark.parametrize( + ("device_fixture", "old_unique_id", "new_unique_id"), + [ + ( + "HWE-SKT", + "aabbccddeeff_total_power_import_t1_kwh", + "aabbccddeeff_total_power_import_kwh", + ), + ( + "HWE-SKT", + "aabbccddeeff_total_power_export_t1_kwh", + "aabbccddeeff_total_power_export_kwh", + ), + ], +) +@pytest.mark.usefixtures("mock_homewizardenergy") +async def test_sensor_migration( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_config_entry: MockConfigEntry, + old_unique_id: str, + new_unique_id: str, +) -> None: + """Test total power T1 sensors are migrated.""" + mock_config_entry.add_to_hass(hass) + + entity: er.RegistryEntry = entity_registry.async_get_or_create( + domain=Platform.SENSOR, + platform=DOMAIN, + unique_id=old_unique_id, + config_entry=mock_config_entry, + ) + + assert entity.unique_id == old_unique_id + + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + entity_migrated = entity_registry.async_get(entity.entity_id) + assert entity_migrated + assert entity_migrated.unique_id == new_unique_id + assert entity_migrated.previous_unique_id == old_unique_id + + +@pytest.mark.parametrize( + ("device_fixture", "old_unique_id", "new_unique_id"), + [ + ( + "HWE-SKT", + "aabbccddeeff_total_power_import_t1_kwh", + "aabbccddeeff_total_power_import_kwh", + ), + ( + "HWE-SKT", + "aabbccddeeff_total_power_export_t1_kwh", + "aabbccddeeff_total_power_export_kwh", + ), + ], +) +@pytest.mark.usefixtures("mock_homewizardenergy") +async def test_sensor_migration_does_not_trigger( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_config_entry: MockConfigEntry, + old_unique_id: str, + new_unique_id: str, +) -> None: + """Test total power T1 sensors are not migrated when not possible.""" + mock_config_entry.add_to_hass(hass) + + old_entity: er.RegistryEntry = entity_registry.async_get_or_create( + domain=Platform.SENSOR, + platform=DOMAIN, + unique_id=old_unique_id, + config_entry=mock_config_entry, + ) + + new_entity: er.RegistryEntry = entity_registry.async_get_or_create( + domain=Platform.SENSOR, + platform=DOMAIN, + unique_id=new_unique_id, + config_entry=mock_config_entry, + ) + + assert old_entity.unique_id == old_unique_id + assert new_entity.unique_id == new_unique_id + + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + entity = entity_registry.async_get(old_entity.entity_id) + assert entity + assert entity.unique_id == old_unique_id + assert entity.previous_unique_id is None + + entity = entity_registry.async_get(new_entity.entity_id) + assert entity + assert entity.unique_id == new_unique_id + assert entity.previous_unique_id is None diff --git a/tests/components/homewizard/test_sensor_migration.py b/tests/components/homewizard/test_sensor_migration.py deleted file mode 100644 index d51c2d8c5b8c8..0000000000000 --- a/tests/components/homewizard/test_sensor_migration.py +++ /dev/null @@ -1,112 +0,0 @@ -"""Test sensor entity migration for HomeWizard.""" - - -import pytest - -from homeassistant.components.homewizard.const import DOMAIN -from homeassistant.const import Platform -from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry as er - -from tests.common import MockConfigEntry - - -@pytest.mark.parametrize( - ("device_fixture", "old_unique_id", "new_unique_id"), - [ - ( - "HWE-SKT", - "aabbccddeeff_total_power_import_t1_kwh", - "aabbccddeeff_total_power_import_kwh", - ), - ( - "HWE-SKT", - "aabbccddeeff_total_power_export_t1_kwh", - "aabbccddeeff_total_power_export_kwh", - ), - ], -) -@pytest.mark.usefixtures("mock_homewizardenergy") -async def test_sensor_migration( - hass: HomeAssistant, - old_unique_id: str, - new_unique_id: str, - entity_registry: er.EntityRegistry, - mock_config_entry: MockConfigEntry, -) -> None: - """Test total power T1 sensors are migrated.""" - mock_config_entry.add_to_hass(hass) - - entity: er.RegistryEntry = entity_registry.async_get_or_create( - domain=Platform.SENSOR, - platform=DOMAIN, - unique_id=old_unique_id, - config_entry=mock_config_entry, - ) - - assert entity.unique_id == old_unique_id - - assert await hass.config_entries.async_setup(mock_config_entry.entry_id) - await hass.async_block_till_done() - - entity_migrated = entity_registry.async_get(entity.entity_id) - assert entity_migrated - assert entity_migrated.unique_id == new_unique_id - assert entity_migrated.previous_unique_id == old_unique_id - - -@pytest.mark.parametrize( - ("device_fixture", "old_unique_id", "new_unique_id"), - [ - ( - "HWE-SKT", - "aabbccddeeff_total_power_import_t1_kwh", - "aabbccddeeff_total_power_import_kwh", - ), - ( - "HWE-SKT", - "aabbccddeeff_total_power_export_t1_kwh", - "aabbccddeeff_total_power_export_kwh", - ), - ], -) -@pytest.mark.usefixtures("mock_homewizardenergy") -async def test_sensor_migration_does_not_trigger( - hass: HomeAssistant, - old_unique_id: str, - new_unique_id: str, - entity_registry: er.EntityRegistry, - mock_config_entry: MockConfigEntry, -) -> None: - """Test total power T1 sensors are not migrated when not possible.""" - mock_config_entry.add_to_hass(hass) - - old_entity: er.RegistryEntry = entity_registry.async_get_or_create( - domain=Platform.SENSOR, - platform=DOMAIN, - unique_id=old_unique_id, - config_entry=mock_config_entry, - ) - - new_entity: er.RegistryEntry = entity_registry.async_get_or_create( - domain=Platform.SENSOR, - platform=DOMAIN, - unique_id=new_unique_id, - config_entry=mock_config_entry, - ) - - assert old_entity.unique_id == old_unique_id - assert new_entity.unique_id == new_unique_id - - assert await hass.config_entries.async_setup(mock_config_entry.entry_id) - await hass.async_block_till_done() - - entity = entity_registry.async_get(old_entity.entity_id) - assert entity - assert entity.unique_id == old_unique_id - assert entity.previous_unique_id is None - - entity = entity_registry.async_get(new_entity.entity_id) - assert entity - assert entity.unique_id == new_unique_id - assert entity.previous_unique_id is None