Remove ExternalDevice migration in HomeWizard (#125197)

pull/125246/head
Duco Sebel 2024-09-04 18:32:57 +02:00 committed by GitHub
parent af51241c0d
commit 186c9aa33b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 100 deletions

View File

@ -625,26 +625,8 @@ async def async_setup_entry(
) -> None:
"""Initialize sensors."""
# Migrate original gas meter sensor to ExternalDevice
# This is sensor that was directly linked to the P1 Meter
# Migration can be removed after 2024.8.0
ent_reg = er.async_get(hass)
data = entry.runtime_data.data.data
if (
entity_id := ent_reg.async_get_entity_id(
Platform.SENSOR, DOMAIN, f"{entry.unique_id}_total_gas_m3"
)
) and data.gas_unique_id is not None:
ent_reg.async_update_entity(
entity_id,
new_unique_id=f"{DOMAIN}_gas_meter_{data.gas_unique_id}",
)
# Remove old gas_unique_id sensor
if entity_id := ent_reg.async_get_entity_id(
Platform.SENSOR, DOMAIN, f"{entry.unique_id}_gas_unique_id"
):
ent_reg.async_remove(entity_id)
# Initialize default sensors
entities: list = [

View File

@ -1,37 +1,4 @@
# serializer version: 1
# name: test_gas_meter_migrated[sensor.homewizard_aabbccddeeff_total_gas_m3:entity-registry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.homewizard_aabbccddeeff_total_gas_m3',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'homewizard',
'previous_unique_id': 'aabbccddeeff_total_gas_m3',
'supported_features': 0,
'translation_key': None,
'unique_id': 'homewizard_gas_meter_01FFEEDDCCBBAA99887766554433221100',
'unit_of_measurement': None,
})
# ---
# name: test_sensors[HWE-KWH1-entity_ids7][sensor.device_apparent_power:device-registry]
DeviceRegistryEntrySnapshot({
'area_id': None,

View File

@ -7,14 +7,13 @@ from homewizard_energy.models import Data
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.homewizard import DOMAIN
from homeassistant.components.homewizard.const import UPDATE_INTERVAL
from homeassistant.const import STATE_UNAVAILABLE, Platform
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
import homeassistant.util.dt as dt_util
from tests.common import MockConfigEntry, async_fire_time_changed
from tests.common import async_fire_time_changed
pytestmark = [
pytest.mark.usefixtures("init_integration"),
@ -815,49 +814,3 @@ async def test_entities_not_created_for_device(
"""Ensures entities for a specific device are not created."""
for entity_id in entity_ids:
assert not hass.states.get(entity_id)
async def test_gas_meter_migrated(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test old gas meter sensor is migrated."""
entity_registry.async_get_or_create(
Platform.SENSOR,
DOMAIN,
"aabbccddeeff_total_gas_m3",
)
await hass.config_entries.async_reload(init_integration.entry_id)
await hass.async_block_till_done()
entity_id = "sensor.homewizard_aabbccddeeff_total_gas_m3"
assert (entity_entry := entity_registry.async_get(entity_id))
assert snapshot(name=f"{entity_id}:entity-registry") == entity_entry
# Make really sure this happens
assert entity_entry.previous_unique_id == "aabbccddeeff_total_gas_m3"
async def test_gas_unique_id_removed(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test old gas meter id sensor is removed."""
entity_registry.async_get_or_create(
Platform.SENSOR,
DOMAIN,
"aabbccddeeff_gas_unique_id",
)
await hass.config_entries.async_reload(init_integration.entry_id)
await hass.async_block_till_done()
entity_id = "sensor.homewizard_aabbccddeeff_gas_unique_id"
assert not entity_registry.async_get(entity_id)