mirror of
https://github.com/home-assistant/core.git
synced 2026-01-25 00:52:39 +01:00
Add WS command to help reset custom entity_id
This commit is contained in:
@@ -669,6 +669,7 @@ class RegistryEntryWithDefaults(er.RegistryEntry):
|
||||
original_device_class: str | None = attr.ib(default=None)
|
||||
original_icon: str | None = attr.ib(default=None)
|
||||
original_name: str | None = attr.ib(default=None)
|
||||
suggested_object_id: str | None = attr.ib(default=None)
|
||||
supported_features: int = attr.ib(default=0)
|
||||
translation_key: str | None = attr.ib(default=None)
|
||||
unit_of_measurement: str | None = attr.ib(default=None)
|
||||
|
||||
@@ -1288,3 +1288,58 @@ async def test_remove_non_existing_entity(
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert not msg["success"]
|
||||
|
||||
|
||||
async def test_get_automatic_entity_ids(
|
||||
hass: HomeAssistant, client: MockHAClientWebSocket
|
||||
) -> None:
|
||||
"""Test get_automatic_entity_ids."""
|
||||
mock_registry(
|
||||
hass,
|
||||
{
|
||||
"test_domain.test_1": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.test_1",
|
||||
unique_id="uniq1",
|
||||
platform="test_platform",
|
||||
),
|
||||
"test_domain.test_2": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.test_2",
|
||||
unique_id="uniq2",
|
||||
platform="test_platform",
|
||||
suggested_object_id="blabla",
|
||||
),
|
||||
"test_domain.test_3": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.test_3",
|
||||
unique_id="uniq3",
|
||||
platform="test_platform",
|
||||
suggested_object_id="collision",
|
||||
),
|
||||
"test_domain.collision": RegistryEntryWithDefaults(
|
||||
entity_id="test_domain.collision",
|
||||
unique_id="uniq_collision",
|
||||
platform="test_platform",
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
"type": "config/entity_registry/get_automatic_entity_ids",
|
||||
"entity_ids": [
|
||||
"test_domain.test_1",
|
||||
"test_domain.test_2",
|
||||
"test_domain.test_3",
|
||||
"test_domain.unknown",
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["success"]
|
||||
assert msg["result"] == {
|
||||
"test_domain.test_1": "test_domain.test_platform_uniq1", # platform + unique_id
|
||||
"test_domain.test_2": "test_domain.blabla", # suggested_object_id
|
||||
"test_domain.test_3": "test_domain.collision_2", # suggested_object_id + _2
|
||||
"test_domain.unknown": None, # no test_domain.unknown in registry
|
||||
}
|
||||
|
||||
@@ -1550,6 +1550,7 @@ async def test_entity_info_added_to_entity_registry(
|
||||
original_icon="nice:icon",
|
||||
original_name="best name",
|
||||
options=None,
|
||||
suggested_object_id="best name",
|
||||
supported_features=5,
|
||||
translation_key="my_translation_key",
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
|
||||
@@ -144,6 +144,7 @@ def test_get_or_create_updates_data(
|
||||
original_device_class="mock-device-class",
|
||||
original_icon="initial-original_icon",
|
||||
original_name="initial-original_name",
|
||||
suggested_object_id=None,
|
||||
supported_features=5,
|
||||
translation_key="initial-translation_key",
|
||||
unit_of_measurement="initial-unit_of_measurement",
|
||||
@@ -202,6 +203,7 @@ def test_get_or_create_updates_data(
|
||||
original_device_class="new-mock-device-class",
|
||||
original_icon="updated-original_icon",
|
||||
original_name="updated-original_name",
|
||||
suggested_object_id=None,
|
||||
supported_features=10,
|
||||
translation_key="updated-translation_key",
|
||||
unit_of_measurement="updated-unit_of_measurement",
|
||||
@@ -254,6 +256,7 @@ def test_get_or_create_updates_data(
|
||||
original_device_class=None,
|
||||
original_icon=None,
|
||||
original_name=None,
|
||||
suggested_object_id=None,
|
||||
supported_features=0, # supported_features is stored as an int
|
||||
translation_key=None,
|
||||
unit_of_measurement=None,
|
||||
@@ -537,6 +540,7 @@ async def test_load_bad_data(
|
||||
"original_name": None,
|
||||
"platform": "super_platform",
|
||||
"previous_unique_id": None,
|
||||
"suggested_object_id": None,
|
||||
"supported_features": 0,
|
||||
"translation_key": None,
|
||||
"unique_id": 123, # Should trigger warning
|
||||
@@ -568,6 +572,7 @@ async def test_load_bad_data(
|
||||
"original_name": None,
|
||||
"platform": "super_platform",
|
||||
"previous_unique_id": None,
|
||||
"suggested_object_id": None,
|
||||
"supported_features": 0,
|
||||
"translation_key": None,
|
||||
"unique_id": ["not", "valid"], # Should not load
|
||||
@@ -922,6 +927,7 @@ async def test_migration_1_1(hass: HomeAssistant, hass_storage: dict[str, Any])
|
||||
"original_name": None,
|
||||
"platform": "super_platform",
|
||||
"previous_unique_id": None,
|
||||
"suggested_object_id": None,
|
||||
"supported_features": 0,
|
||||
"translation_key": None,
|
||||
"unique_id": "very_unique",
|
||||
@@ -1101,6 +1107,7 @@ async def test_migration_1_11(
|
||||
"original_name": None,
|
||||
"platform": "super_platform",
|
||||
"previous_unique_id": None,
|
||||
"suggested_object_id": None,
|
||||
"supported_features": 0,
|
||||
"translation_key": None,
|
||||
"unique_id": "very_unique",
|
||||
|
||||
Reference in New Issue
Block a user