mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Remove old update of number unique id in deCONZ (#113524)
This commit is contained in:
parent
e90388afd1
commit
9c2c7f1a45
@ -21,12 +21,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
import homeassistant.helpers.entity_registry as er
|
|
||||||
|
|
||||||
from .const import DOMAIN as DECONZ_DOMAIN
|
|
||||||
from .deconz_device import DeconzDevice
|
from .deconz_device import DeconzDevice
|
||||||
from .hub import DeconzHub, get_gateway_from_config_entry
|
from .hub import DeconzHub, get_gateway_from_config_entry
|
||||||
from .util import serial_from_unique_id
|
|
||||||
|
|
||||||
T = TypeVar("T", Presence, PydeconzSensorBase)
|
T = TypeVar("T", Presence, PydeconzSensorBase)
|
||||||
|
|
||||||
@ -70,25 +67,6 @@ ENTITY_DESCRIPTIONS: tuple[DeconzNumberDescription, ...] = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_update_unique_id(
|
|
||||||
hass: HomeAssistant, unique_id: str, description: DeconzNumberDescription
|
|
||||||
) -> None:
|
|
||||||
"""Update unique ID base to be on full unique ID rather than device serial.
|
|
||||||
|
|
||||||
Introduced with release 2022.11.
|
|
||||||
"""
|
|
||||||
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
|
|
||||||
|
|
||||||
unique_id = f"{serial_from_unique_id(unique_id)}-{description.key}"
|
|
||||||
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@ -109,8 +87,6 @@ async def async_setup_entry(
|
|||||||
or description.value_fn(sensor) is None
|
or description.value_fn(sensor) is None
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
if description.key == "delay":
|
|
||||||
async_update_unique_id(hass, sensor.unique_id, description)
|
|
||||||
async_add_entities([DeconzNumber(sensor, gateway, description)])
|
async_add_entities([DeconzNumber(sensor, gateway, description)])
|
||||||
|
|
||||||
gateway.register_platform_add_device_callback(
|
gateway.register_platform_add_device_callback(
|
||||||
|
@ -4,7 +4,6 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.deconz.const import DOMAIN as DECONZ_DOMAIN
|
|
||||||
from homeassistant.components.number import (
|
from homeassistant.components.number import (
|
||||||
ATTR_VALUE,
|
ATTR_VALUE,
|
||||||
DOMAIN as NUMBER_DOMAIN,
|
DOMAIN as NUMBER_DOMAIN,
|
||||||
@ -50,7 +49,6 @@ TEST_DATA = [
|
|||||||
"device_count": 3,
|
"device_count": 3,
|
||||||
"entity_id": "number.presence_sensor_delay",
|
"entity_id": "number.presence_sensor_delay",
|
||||||
"unique_id": "00:00:00:00:00:00:00:00-00-delay",
|
"unique_id": "00:00:00:00:00:00:00:00-00-delay",
|
||||||
"old_unique_id": "00:00:00:00:00:00:00:00-delay",
|
|
||||||
"state": "0",
|
"state": "0",
|
||||||
"entity_category": EntityCategory.CONFIG,
|
"entity_category": EntityCategory.CONFIG,
|
||||||
"attributes": {
|
"attributes": {
|
||||||
@ -120,15 +118,6 @@ async def test_number_entities(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test successful creation of number entities."""
|
"""Test successful creation of number entities."""
|
||||||
|
|
||||||
# Create entity entry to migrate to new unique ID
|
|
||||||
if "old_unique_id" in expected:
|
|
||||||
entity_registry.async_get_or_create(
|
|
||||||
NUMBER_DOMAIN,
|
|
||||||
DECONZ_DOMAIN,
|
|
||||||
expected["old_unique_id"],
|
|
||||||
suggested_object_id=expected["entity_id"].replace("number.", ""),
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch.dict(DECONZ_WEB_REQUEST, {"sensors": {"0": sensor_data}}):
|
with patch.dict(DECONZ_WEB_REQUEST, {"sensors": {"0": sensor_data}}):
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user