From 4251389c12945590648c598188497bdb2fbf4b9d Mon Sep 17 00:00:00 2001 From: Duco Sebel <74970928+DCSBL@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:33:53 +0200 Subject: [PATCH] Remove ExternalDevice 'invalid ID' migration in HomeWizard (#128634) --- homeassistant/components/homewizard/sensor.py | 14 ----- tests/components/homewizard/test_init.py | 61 ------------------- 2 files changed, 75 deletions(-) diff --git a/homeassistant/components/homewizard/sensor.py b/homeassistant/components/homewizard/sensor.py index 9bb61a467cb..57071875edb 100644 --- a/homeassistant/components/homewizard/sensor.py +++ b/homeassistant/components/homewizard/sensor.py @@ -19,7 +19,6 @@ from homeassistant.const import ( ATTR_VIA_DEVICE, PERCENTAGE, EntityCategory, - Platform, UnitOfApparentPower, UnitOfElectricCurrent, UnitOfElectricPotential, @@ -30,7 +29,6 @@ from homeassistant.const import ( UnitOfVolume, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry as er from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -625,7 +623,6 @@ async def async_setup_entry( ) -> None: """Initialize sensors.""" - ent_reg = er.async_get(hass) data = entry.runtime_data.data.data # Initialize default sensors @@ -639,17 +636,6 @@ async def async_setup_entry( if data.external_devices is not None: for unique_id, device in data.external_devices.items(): if description := EXTERNAL_SENSORS.get(device.meter_type): - # Migrate external devices to new unique_id - # This is to ensure that devices with same id but different type are unique - # Migration can be removed after 2024.11.0 - if entity_id := ent_reg.async_get_entity_id( - Platform.SENSOR, DOMAIN, f"{DOMAIN}_{device.unique_id}" - ): - ent_reg.async_update_entity( - entity_id, - new_unique_id=f"{DOMAIN}_{unique_id}", - ) - # Add external device entities.append( HomeWizardExternalSensorEntity( diff --git a/tests/components/homewizard/test_init.py b/tests/components/homewizard/test_init.py index 33412900677..77275276cc9 100644 --- a/tests/components/homewizard/test_init.py +++ b/tests/components/homewizard/test_init.py @@ -7,9 +7,7 @@ import pytest 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 @@ -95,62 +93,3 @@ async def test_load_removes_reauth_flow( # Flow should be removed flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN) assert len(flows) == 0 - - -@pytest.mark.parametrize( - ("device_fixture", "old_unique_id", "new_unique_id"), - [ - ( - "HWE-P1", - "homewizard_G001", - "homewizard_gas_meter_G001", - ), - ( - "HWE-P1", - "homewizard_W001", - "homewizard_water_meter_W001", - ), - ( - "HWE-P1", - "homewizard_WW001", - "homewizard_warm_water_meter_WW001", - ), - ( - "HWE-P1", - "homewizard_H001", - "homewizard_heat_meter_H001", - ), - ( - "HWE-P1", - "homewizard_IH001", - "homewizard_inlet_heat_meter_IH001", - ), - ], -) -@pytest.mark.usefixtures("mock_homewizardenergy") -async def test_external_sensor_migration( - hass: HomeAssistant, - entity_registry: er.EntityRegistry, - mock_config_entry: MockConfigEntry, - old_unique_id: str, - new_unique_id: str, -) -> None: - """Test unique ID or External 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