Skip to content

Commit

Permalink
Remove ExternalDevice 'invalid ID' migration in HomeWizard (home-assi…
Browse files Browse the repository at this point in the history
  • Loading branch information
DCSBL authored Oct 18, 2024
1 parent 6ff2ce1 commit 4251389
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 deletions.
14 changes: 0 additions & 14 deletions homeassistant/components/homewizard/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
ATTR_VIA_DEVICE,
PERCENTAGE,
EntityCategory,
Platform,
UnitOfApparentPower,
UnitOfElectricCurrent,
UnitOfElectricPotential,
Expand All @@ -30,7 +29,6 @@
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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
61 changes: 0 additions & 61 deletions tests/components/homewizard/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

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

Expand Down Expand Up @@ -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

0 comments on commit 4251389

Please sign in to comment.