Drop < 0.97 Huawei LTE sensor unique id migration workaround (#29060)

This commit is contained in:
Ville Skyttä 2019-11-25 17:06:10 +02:00 committed by Pascal Vizeli
parent 9dc63419c4
commit f504ac8c65

View File

@ -11,7 +11,6 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_SIGNAL_STRENGTH,
DOMAIN as SENSOR_DOMAIN,
)
from homeassistant.helpers import entity_registry
from . import HuaweiLteBaseEntity
from .const import (
@ -170,23 +169,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
HuaweiLteSensor(router, key, item, SENSOR_META.get((key, item), {}))
)
# Pre-0.97 unique id migration. Old ones used the device serial number
# (see comments in HuaweiLteData._setup_lte for more info), as well as
# had a bug that joined the path str with periods, not the path components,
# resulting e.g. *_device_signal.sinr to end up as
# *_d.e.v.i.c.e._.s.i.g.n.a.l...s.i.n.r
entreg = await entity_registry.async_get_registry(hass)
for entid, ent in entreg.entities.items():
if ent.platform != DOMAIN:
continue
for sensor in sensors:
oldsuf = ".".join(f"{sensor.key}.{sensor.item}")
if ent.unique_id.endswith(f"_{oldsuf}"):
entreg.async_update_entity(entid, new_unique_id=sensor.unique_id)
_LOGGER.debug(
"Updated entity %s unique id to %s", entid, sensor.unique_id
)
async_add_entities(sensors, True)