Remove old update of sensor unique id in deCONZ (#113527)
This commit is contained in:
parent
b7f7bed46c
commit
e90388afd1
2 changed files with 2 additions and 54 deletions
|
@ -48,14 +48,12 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
import homeassistant.helpers.entity_registry as er
|
||||
from homeassistant.helpers.typing import StateType
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import ATTR_DARK, ATTR_ON, DOMAIN as DECONZ_DOMAIN
|
||||
from .const import ATTR_DARK, ATTR_ON
|
||||
from .deconz_device import DeconzDevice
|
||||
from .hub import DeconzHub, get_gateway_from_config_entry
|
||||
from .util import serial_from_unique_id
|
||||
|
||||
PROVIDES_EXTRA_ATTRIBUTES = (
|
||||
"battery",
|
||||
|
@ -291,29 +289,6 @@ ENTITY_DESCRIPTIONS: tuple[DeconzSensorDescription, ...] = (
|
|||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_update_unique_id(
|
||||
hass: HomeAssistant, unique_id: str, description: DeconzSensorDescription
|
||||
) -> None:
|
||||
"""Update unique ID to always have a suffix.
|
||||
|
||||
Introduced with release 2022.9.
|
||||
"""
|
||||
ent_reg = er.async_get(hass)
|
||||
|
||||
new_unique_id = f"{unique_id}-{description.key}"
|
||||
if ent_reg.async_get_entity_id(DOMAIN, DECONZ_DOMAIN, new_unique_id):
|
||||
return
|
||||
|
||||
if description.old_unique_id_suffix:
|
||||
unique_id = (
|
||||
f"{serial_from_unique_id(unique_id)}-{description.old_unique_id_suffix}"
|
||||
)
|
||||
|
||||
if entity_id := ent_reg.async_get_entity_id(DOMAIN, DECONZ_DOMAIN, unique_id):
|
||||
ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
|
@ -357,7 +332,6 @@ async def async_setup_entry(
|
|||
continue
|
||||
known_device_entities[description.key].add(unique_id)
|
||||
if no_sensor_data and description.key == "battery":
|
||||
async_update_unique_id(hass, sensor.unique_id, description)
|
||||
DeconzBatteryTracker(
|
||||
sensor_id, gateway, description, async_add_entities
|
||||
)
|
||||
|
@ -366,7 +340,6 @@ async def async_setup_entry(
|
|||
if no_sensor_data:
|
||||
continue
|
||||
|
||||
async_update_unique_id(hass, sensor.unique_id, description)
|
||||
entities.append(DeconzSensor(sensor, gateway, description))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -5,10 +5,7 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.deconz.const import (
|
||||
CONF_ALLOW_CLIP_SENSOR,
|
||||
DOMAIN as DECONZ_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.deconz.const import CONF_ALLOW_CLIP_SENSOR
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
SensorDeviceClass,
|
||||
|
@ -68,7 +65,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.bosch_air_quality_sensor",
|
||||
"unique_id": "00:12:4b:00:14:4d:00:07-02-fdef-air_quality",
|
||||
"old_unique_id": "00:12:4b:00:14:4d:00:07-02-fdef",
|
||||
"state": "poor",
|
||||
"entity_category": None,
|
||||
"device_class": None,
|
||||
|
@ -106,7 +102,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.bosch_air_quality_sensor_ppb",
|
||||
"unique_id": "00:12:4b:00:14:4d:00:07-02-fdef-air_quality_ppb",
|
||||
"old_unique_id": "00:12:4b:00:14:4d:00:07-ppb",
|
||||
"state": "809",
|
||||
"entity_category": None,
|
||||
"device_class": None,
|
||||
|
@ -265,7 +260,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.fyrtur_block_out_roller_blind_battery",
|
||||
"unique_id": "00:0d:6f:ff:fe:01:23:45-01-0001-battery",
|
||||
"old_unique_id": "00:0d:6f:ff:fe:01:23:45-battery",
|
||||
"state": "100",
|
||||
"entity_category": EntityCategory.DIAGNOSTIC,
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
|
@ -302,7 +296,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.consumption_15",
|
||||
"unique_id": "00:0d:6f:00:0b:7a:64:29-01-0702-consumption",
|
||||
"old_unique_id": "00:0d:6f:00:0b:7a:64:29-01-0702",
|
||||
"state": "11.342",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.ENERGY,
|
||||
|
@ -384,7 +377,6 @@ TEST_DATA = [
|
|||
"device_count": 2,
|
||||
"entity_id": "sensor.fsm_state_motion_stair",
|
||||
"unique_id": "fsm-state-1520195376277-status",
|
||||
"old_unique_id": "fsm-state-1520195376277",
|
||||
"state": "0",
|
||||
"entity_category": None,
|
||||
"device_class": None,
|
||||
|
@ -423,7 +415,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.mi_temperature_1",
|
||||
"unique_id": "00:15:8d:00:02:45:dc:53-01-0405-humidity",
|
||||
"old_unique_id": "00:15:8d:00:02:45:dc:53-01-0405",
|
||||
"state": "35.55",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.HUMIDITY,
|
||||
|
@ -513,7 +504,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.motion_sensor_4",
|
||||
"unique_id": "00:17:88:01:03:28:8c:9b-02-0400-light_level",
|
||||
"old_unique_id": "00:17:88:01:03:28:8c:9b-02-0400",
|
||||
"state": "5.0",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.ILLUMINANCE,
|
||||
|
@ -605,7 +595,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.power_16",
|
||||
"unique_id": "00:0d:6f:00:0b:7a:64:29-01-0b04-power",
|
||||
"old_unique_id": "00:0d:6f:00:0b:7a:64:29-01-0b04",
|
||||
"state": "64",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.POWER,
|
||||
|
@ -648,7 +637,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.mi_temperature_1",
|
||||
"unique_id": "00:15:8d:00:02:45:dc:53-01-0403-pressure",
|
||||
"old_unique_id": "00:15:8d:00:02:45:dc:53-01-0403",
|
||||
"state": "1010",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.PRESSURE,
|
||||
|
@ -690,7 +678,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.mi_temperature_1",
|
||||
"unique_id": "00:15:8d:00:02:45:dc:53-01-0402-temperature",
|
||||
"old_unique_id": "00:15:8d:00:02:45:dc:53-01-0402",
|
||||
"state": "21.82",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.TEMPERATURE,
|
||||
|
@ -737,7 +724,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.etrv_sejour",
|
||||
"unique_id": "cc:cc:cc:ff:fe:38:4d:b3-01-000a-last_set",
|
||||
"old_unique_id": "cc:cc:cc:ff:fe:38:4d:b3-01-000a",
|
||||
"state": "2020-11-19T08:07:08+00:00",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.TIMESTAMP,
|
||||
|
@ -777,7 +763,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.alarm_10_temperature",
|
||||
"unique_id": "00:15:8d:00:02:b5:d1:80-01-0500-internal_temperature",
|
||||
"old_unique_id": "00:15:8d:00:02:b5:d1:80-temperature",
|
||||
"state": "26.0",
|
||||
"entity_category": None,
|
||||
"device_class": SensorDeviceClass.TEMPERATURE,
|
||||
|
@ -819,7 +804,6 @@ TEST_DATA = [
|
|||
"device_count": 3,
|
||||
"entity_id": "sensor.dimmer_switch_3_battery",
|
||||
"unique_id": "00:17:88:01:02:0e:32:a3-02-fc00-battery",
|
||||
"old_unique_id": "00:17:88:01:02:0e:32:a3-battery",
|
||||
"state": "90",
|
||||
"entity_category": EntityCategory.DIAGNOSTIC,
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
|
@ -851,15 +835,6 @@ async def test_sensors(
|
|||
) -> None:
|
||||
"""Test successful creation of sensor entities."""
|
||||
|
||||
# Create entity entry to migrate to new unique ID
|
||||
if "old_unique_id" in expected:
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DECONZ_DOMAIN,
|
||||
expected["old_unique_id"],
|
||||
suggested_object_id=expected["entity_id"].replace("sensor.", ""),
|
||||
)
|
||||
|
||||
with patch.dict(DECONZ_WEB_REQUEST, {"sensors": {"1": sensor_data}}):
|
||||
config_entry = await setup_deconz_integration(
|
||||
hass, aioclient_mock, options={CONF_ALLOW_CLIP_SENSOR: True}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue