mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 19:25:12 +02:00
Handle current entity id matches the automatic entity id
This commit is contained in:
@@ -9,13 +9,13 @@ import voluptuous as vol
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import websocket_api
|
from homeassistant.components import websocket_api
|
||||||
from homeassistant.components.websocket_api import ERR_NOT_FOUND, require_admin
|
from homeassistant.components.websocket_api import ERR_NOT_FOUND, require_admin
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback, split_entity_id
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
config_validation as cv,
|
config_validation as cv,
|
||||||
device_registry as dr,
|
device_registry as dr,
|
||||||
entity_component,
|
|
||||||
entity_registry as er,
|
entity_registry as er,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.entity_component import async_get_entity_suggested_object_id
|
||||||
from homeassistant.helpers.json import json_dumps
|
from homeassistant.helpers.json import json_dumps
|
||||||
|
|
||||||
|
|
||||||
@@ -344,10 +344,15 @@ def websocket_get_automatic_entity_ids(
|
|||||||
if not (entry := registry.entities.get(entity_id)):
|
if not (entry := registry.entities.get(entity_id)):
|
||||||
automatic_entity_ids[entity_id] = None
|
automatic_entity_ids[entity_id] = None
|
||||||
continue
|
continue
|
||||||
|
if (
|
||||||
|
suggested := async_get_entity_suggested_object_id(hass, entity_id)
|
||||||
|
) == split_entity_id(entry.entity_id)[1]:
|
||||||
|
# No need to generate a new entity ID
|
||||||
|
automatic_entity_ids[entity_id] = None
|
||||||
|
continue
|
||||||
automatic_entity_ids[entity_id] = registry.async_generate_entity_id(
|
automatic_entity_ids[entity_id] = registry.async_generate_entity_id(
|
||||||
entry.domain,
|
entry.domain,
|
||||||
entity_component.async_get_entity_suggested_object_id(hass, entity_id)
|
suggested or f"{entry.platform}_{entry.unique_id}",
|
||||||
or f"{entry.platform}_{entry.unique_id}",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
connection.send_message(
|
connection.send_message(
|
||||||
|
@@ -1361,6 +1361,12 @@ async def test_get_automatic_entity_ids(
|
|||||||
unique_id="uniq9",
|
unique_id="uniq9",
|
||||||
platform="test_domain",
|
platform="test_domain",
|
||||||
),
|
),
|
||||||
|
"test_domain.test_10": RegistryEntryWithDefaults(
|
||||||
|
entity_id="test_domain.test_10",
|
||||||
|
unique_id="uniq10",
|
||||||
|
platform="test_domain",
|
||||||
|
suggested_object_id="test_10",
|
||||||
|
),
|
||||||
"test_domain.collision": RegistryEntryWithDefaults(
|
"test_domain.collision": RegistryEntryWithDefaults(
|
||||||
entity_id="test_domain.collision",
|
entity_id="test_domain.collision",
|
||||||
unique_id="uniq_collision",
|
unique_id="uniq_collision",
|
||||||
@@ -1390,6 +1396,7 @@ async def test_get_automatic_entity_ids(
|
|||||||
"test_domain.test_7",
|
"test_domain.test_7",
|
||||||
"test_domain.test_8",
|
"test_domain.test_8",
|
||||||
"test_domain.test_9",
|
"test_domain.test_9",
|
||||||
|
"test_domain.test_10",
|
||||||
"test_domain.unknown",
|
"test_domain.unknown",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -1408,5 +1415,6 @@ async def test_get_automatic_entity_ids(
|
|||||||
"test_domain.test_7": "test_domain.entity_name_7", # entity name property
|
"test_domain.test_7": "test_domain.entity_name_7", # entity name property
|
||||||
"test_domain.test_8": "test_domain.suggested_8", # suggested_object_id
|
"test_domain.test_8": "test_domain.suggested_8", # suggested_object_id
|
||||||
"test_domain.test_9": "test_domain.name_by_user_9", # name by user in registry
|
"test_domain.test_9": "test_domain.name_by_user_9", # name by user in registry
|
||||||
|
"test_domain.test_10": None, # automatic entity id matches current entity id
|
||||||
"test_domain.unknown": None, # no test_domain.unknown in registry
|
"test_domain.unknown": None, # no test_domain.unknown in registry
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user