2018-02-24 10:53:59 -08:00
|
|
|
"""Test entity_registry API."""
|
|
|
|
import pytest
|
2022-12-20 12:10:46 +01:00
|
|
|
from pytest_unordered import unordered
|
2018-02-24 10:53:59 -08:00
|
|
|
|
|
|
|
from homeassistant.components.config import entity_registry
|
2023-02-21 20:40:39 +01:00
|
|
|
from homeassistant.const import ATTR_ICON, EntityCategory
|
2023-02-11 08:26:13 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers import device_registry as dr
|
2021-11-24 23:32:16 +02:00
|
|
|
from homeassistant.helpers.device_registry import DeviceEntryDisabler
|
2022-03-14 19:39:07 +01:00
|
|
|
from homeassistant.helpers.entity_registry import (
|
|
|
|
RegistryEntry,
|
|
|
|
RegistryEntryDisabler,
|
|
|
|
RegistryEntryHider,
|
2022-08-30 21:07:50 +02:00
|
|
|
async_get as async_get_entity_registry,
|
2022-03-14 19:39:07 +01:00
|
|
|
)
|
2019-12-08 17:57:28 +01:00
|
|
|
|
2020-12-02 21:20:14 +01:00
|
|
|
from tests.common import (
|
2022-12-20 08:20:42 +01:00
|
|
|
ANY,
|
2020-12-02 21:20:14 +01:00
|
|
|
MockConfigEntry,
|
|
|
|
MockEntity,
|
|
|
|
MockEntityPlatform,
|
|
|
|
mock_device_registry,
|
|
|
|
mock_registry,
|
|
|
|
)
|
2023-02-21 20:40:39 +01:00
|
|
|
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
2018-02-24 10:53:59 -08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-02-21 20:40:39 +01:00
|
|
|
async def client(
|
|
|
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
|
|
|
) -> MockHAClientWebSocket:
|
2018-02-24 10:53:59 -08:00
|
|
|
"""Fixture that can interact with the config manager API."""
|
2023-02-21 20:40:39 +01:00
|
|
|
await entity_registry.async_setup(hass)
|
|
|
|
return await hass_ws_client(hass)
|
2018-02-24 10:53:59 -08:00
|
|
|
|
|
|
|
|
2020-12-02 21:20:14 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def device_registry(hass):
|
|
|
|
"""Return an empty, loaded, registry."""
|
|
|
|
return mock_device_registry(hass)
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_list_entities(hass: HomeAssistant, client) -> None:
|
2018-09-14 11:57:18 +02:00
|
|
|
"""Test list entries."""
|
2021-10-14 10:04:26 +02:00
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.name": RegistryEntry(
|
|
|
|
entity_id="test_domain.name",
|
|
|
|
unique_id="1234",
|
|
|
|
platform="test_platform",
|
|
|
|
name="Hello World",
|
|
|
|
),
|
|
|
|
"test_domain.no_name": RegistryEntry(
|
|
|
|
entity_id="test_domain.no_name",
|
|
|
|
unique_id="6789",
|
|
|
|
platform="test_platform",
|
|
|
|
),
|
|
|
|
},
|
2018-09-14 11:57:18 +02:00
|
|
|
)
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json({"id": 5, "type": "config/entity_registry/list"})
|
2018-09-14 11:57:18 +02:00
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["result"] == [
|
2018-09-14 11:57:18 +02:00
|
|
|
{
|
2022-07-12 00:10:53 +02:00
|
|
|
"area_id": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"config_entry_id": None,
|
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2022-07-12 00:10:53 +02:00
|
|
|
"entity_category": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"entity_id": "test_domain.name",
|
2022-07-12 00:10:53 +02:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": None,
|
2020-02-11 09:40:50 -08:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2022-07-12 00:10:53 +02:00
|
|
|
"name": "Hello World",
|
2023-02-08 14:32:46 +01:00
|
|
|
"options": {},
|
2022-07-12 00:10:53 +02:00
|
|
|
"original_name": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
|
|
|
"unique_id": ANY,
|
2018-09-14 11:57:18 +02:00
|
|
|
},
|
|
|
|
{
|
2022-07-12 00:10:53 +02:00
|
|
|
"area_id": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"config_entry_id": None,
|
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2022-07-12 00:10:53 +02:00
|
|
|
"entity_category": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"entity_id": "test_domain.no_name",
|
2022-07-12 00:10:53 +02:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": None,
|
2020-02-11 09:40:50 -08:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2022-07-12 00:10:53 +02:00
|
|
|
"name": None,
|
2023-02-08 14:32:46 +01:00
|
|
|
"options": {},
|
2022-07-12 00:10:53 +02:00
|
|
|
"original_name": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
|
|
|
"unique_id": ANY,
|
2019-07-31 12:25:30 -07:00
|
|
|
},
|
2018-09-14 11:57:18 +02:00
|
|
|
]
|
|
|
|
|
2023-01-09 16:52:52 +01:00
|
|
|
class Unserializable:
|
|
|
|
"""Good luck serializing me."""
|
|
|
|
|
2022-07-05 23:11:51 -05:00
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.name": RegistryEntry(
|
|
|
|
entity_id="test_domain.name",
|
|
|
|
unique_id="1234",
|
|
|
|
platform="test_platform",
|
|
|
|
name="Hello World",
|
|
|
|
),
|
2023-01-09 16:52:52 +01:00
|
|
|
"test_domain.name_2": RegistryEntry(
|
|
|
|
entity_id="test_domain.name_2",
|
|
|
|
unique_id="6789",
|
|
|
|
platform="test_platform",
|
|
|
|
name=Unserializable(),
|
|
|
|
),
|
2022-07-05 23:11:51 -05:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json({"id": 6, "type": "config/entity_registry/list"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == [
|
|
|
|
{
|
2022-07-12 00:10:53 +02:00
|
|
|
"area_id": None,
|
2022-07-05 23:11:51 -05:00
|
|
|
"config_entry_id": None,
|
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2022-07-12 00:10:53 +02:00
|
|
|
"entity_category": None,
|
2022-07-05 23:11:51 -05:00
|
|
|
"entity_id": "test_domain.name",
|
2022-07-12 00:10:53 +02:00
|
|
|
"has_entity_name": False,
|
2022-07-05 23:11:51 -05:00
|
|
|
"hidden_by": None,
|
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2022-07-12 00:10:53 +02:00
|
|
|
"name": "Hello World",
|
2023-02-08 14:32:46 +01:00
|
|
|
"options": {},
|
2022-07-12 00:10:53 +02:00
|
|
|
"original_name": None,
|
2022-07-05 23:11:51 -05:00
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
|
|
|
"unique_id": ANY,
|
2022-07-05 23:11:51 -05:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2018-09-14 11:57:18 +02:00
|
|
|
|
2023-02-21 20:40:39 +01:00
|
|
|
async def test_list_entities_for_display(
|
|
|
|
hass: HomeAssistant, client: MockHAClientWebSocket
|
|
|
|
) -> None:
|
|
|
|
"""Test list entries."""
|
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.test": RegistryEntry(
|
|
|
|
area_id="area52",
|
|
|
|
device_id="device123",
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
entity_id="test_domain.test",
|
|
|
|
has_entity_name=True,
|
|
|
|
original_name="Hello World",
|
|
|
|
platform="test_platform",
|
|
|
|
translation_key="translations_galore",
|
|
|
|
unique_id="1234",
|
|
|
|
),
|
|
|
|
"test_domain.nameless": RegistryEntry(
|
|
|
|
area_id="area52",
|
|
|
|
device_id="device123",
|
|
|
|
entity_id="test_domain.nameless",
|
|
|
|
has_entity_name=True,
|
|
|
|
original_name=None,
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="2345",
|
|
|
|
),
|
|
|
|
"test_domain.renamed": RegistryEntry(
|
|
|
|
area_id="area52",
|
|
|
|
device_id="device123",
|
|
|
|
entity_id="test_domain.renamed",
|
|
|
|
has_entity_name=True,
|
|
|
|
name="User name",
|
|
|
|
original_name="Hello World",
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="3456",
|
|
|
|
),
|
|
|
|
"test_domain.boring": RegistryEntry(
|
|
|
|
entity_id="test_domain.boring",
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="4567",
|
|
|
|
),
|
|
|
|
"test_domain.disabled": RegistryEntry(
|
|
|
|
disabled_by=RegistryEntryDisabler.USER,
|
|
|
|
entity_id="test_domain.disabled",
|
|
|
|
hidden_by=RegistryEntryHider.USER,
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="789A",
|
|
|
|
),
|
|
|
|
"test_domain.hidden": RegistryEntry(
|
|
|
|
entity_id="test_domain.hidden",
|
|
|
|
hidden_by=RegistryEntryHider.USER,
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="89AB",
|
|
|
|
),
|
|
|
|
"sensor.default_precision": RegistryEntry(
|
|
|
|
entity_id="sensor.default_precision",
|
|
|
|
options={"sensor": {"suggested_display_precision": 0}},
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="9ABC",
|
|
|
|
),
|
|
|
|
"sensor.user_precision": RegistryEntry(
|
|
|
|
entity_id="sensor.user_precision",
|
|
|
|
options={
|
|
|
|
"sensor": {"display_precision": 0, "suggested_display_precision": 1}
|
|
|
|
},
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="ABCD",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json_auto_id({"type": "config/entity_registry/list_for_display"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == {
|
|
|
|
"entity_categories": {"0": "config", "1": "diagnostic"},
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
"ai": "area52",
|
|
|
|
"di": "device123",
|
|
|
|
"ec": 1,
|
|
|
|
"ei": "test_domain.test",
|
|
|
|
"en": "Hello World",
|
|
|
|
"pl": "test_platform",
|
|
|
|
"tk": "translations_galore",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"ai": "area52",
|
|
|
|
"di": "device123",
|
|
|
|
"ei": "test_domain.nameless",
|
|
|
|
"en": None,
|
2023-02-22 17:59:52 +01:00
|
|
|
"pl": "test_platform",
|
2023-02-21 20:40:39 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"ai": "area52",
|
|
|
|
"di": "device123",
|
|
|
|
"ei": "test_domain.renamed",
|
2023-02-22 17:59:52 +01:00
|
|
|
"pl": "test_platform",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"ei": "test_domain.boring",
|
|
|
|
"pl": "test_platform",
|
2023-02-21 20:40:39 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"ei": "test_domain.hidden",
|
|
|
|
"hb": True,
|
2023-02-22 17:59:52 +01:00
|
|
|
"pl": "test_platform",
|
2023-02-21 20:40:39 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"dp": 0,
|
|
|
|
"ei": "sensor.default_precision",
|
2023-02-22 17:59:52 +01:00
|
|
|
"pl": "test_platform",
|
2023-02-21 20:40:39 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"dp": 0,
|
|
|
|
"ei": "sensor.user_precision",
|
2023-02-22 17:59:52 +01:00
|
|
|
"pl": "test_platform",
|
2023-02-21 20:40:39 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
class Unserializable:
|
|
|
|
"""Good luck serializing me."""
|
|
|
|
|
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.test": RegistryEntry(
|
|
|
|
area_id="area52",
|
|
|
|
device_id="device123",
|
|
|
|
entity_id="test_domain.test",
|
|
|
|
has_entity_name=True,
|
|
|
|
original_name="Hello World",
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="1234",
|
|
|
|
),
|
|
|
|
"test_domain.name_2": RegistryEntry(
|
|
|
|
entity_id="test_domain.name_2",
|
|
|
|
has_entity_name=True,
|
|
|
|
original_name=Unserializable(),
|
|
|
|
platform="test_platform",
|
|
|
|
unique_id="6789",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json_auto_id({"type": "config/entity_registry/list_for_display"})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == {
|
|
|
|
"entity_categories": {"0": "config", "1": "diagnostic"},
|
|
|
|
"entities": [
|
|
|
|
{
|
|
|
|
"ai": "area52",
|
|
|
|
"di": "device123",
|
|
|
|
"ei": "test_domain.test",
|
|
|
|
"en": "Hello World",
|
2023-02-22 17:59:52 +01:00
|
|
|
"pl": "test_platform",
|
2023-02-21 20:40:39 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_get_entity(hass: HomeAssistant, client) -> None:
|
2018-02-24 10:53:59 -08:00
|
|
|
"""Test get entry."""
|
2019-07-31 12:25:30 -07:00
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.name": RegistryEntry(
|
|
|
|
entity_id="test_domain.name",
|
|
|
|
unique_id="1234",
|
|
|
|
platform="test_platform",
|
|
|
|
name="Hello World",
|
|
|
|
),
|
|
|
|
"test_domain.no_name": RegistryEntry(
|
|
|
|
entity_id="test_domain.no_name",
|
|
|
|
unique_id="6789",
|
|
|
|
platform="test_platform",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{"id": 5, "type": "config/entity_registry/get", "entity_id": "test_domain.name"}
|
|
|
|
)
|
2018-06-06 01:08:36 -07:00
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["result"] == {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": [],
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"config_entry_id": None,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"entity_id": "test_domain.name",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": None,
|
2020-02-11 09:40:50 -08:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": "Hello World",
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-02-11 09:40:50 -08:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-02-23 00:18:10 +01:00
|
|
|
"unique_id": "1234",
|
2018-02-24 10:53:59 -08:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/get",
|
|
|
|
"entity_id": "test_domain.no_name",
|
|
|
|
}
|
|
|
|
)
|
2018-06-06 01:08:36 -07:00
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["result"] == {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": [],
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"config_entry_id": None,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2019-07-31 12:25:30 -07:00
|
|
|
"entity_id": "test_domain.no_name",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": None,
|
2020-02-11 09:40:50 -08:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": None,
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-02-11 09:40:50 -08:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-02-23 00:18:10 +01:00
|
|
|
"unique_id": "6789",
|
2018-02-24 10:53:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_get_entities(hass: HomeAssistant, client) -> None:
|
2023-01-05 15:39:10 +01:00
|
|
|
"""Test get entry."""
|
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.name": RegistryEntry(
|
|
|
|
entity_id="test_domain.name",
|
|
|
|
unique_id="1234",
|
|
|
|
platform="test_platform",
|
|
|
|
name="Hello World",
|
|
|
|
),
|
|
|
|
"test_domain.no_name": RegistryEntry(
|
|
|
|
entity_id="test_domain.no_name",
|
|
|
|
unique_id="6789",
|
|
|
|
platform="test_platform",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 5,
|
|
|
|
"type": "config/entity_registry/get_entries",
|
|
|
|
"entity_ids": [
|
|
|
|
"test_domain.name",
|
|
|
|
"test_domain.no_name",
|
|
|
|
"test_domain.no_such_entity",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == {
|
|
|
|
"test_domain.name": {
|
|
|
|
"aliases": [],
|
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
|
|
|
"config_entry_id": None,
|
|
|
|
"device_class": None,
|
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
|
|
|
"entity_category": None,
|
|
|
|
"entity_id": "test_domain.name",
|
|
|
|
"has_entity_name": False,
|
|
|
|
"hidden_by": None,
|
|
|
|
"icon": None,
|
|
|
|
"id": ANY,
|
|
|
|
"name": "Hello World",
|
|
|
|
"options": {},
|
|
|
|
"original_device_class": None,
|
|
|
|
"original_icon": None,
|
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
|
|
|
"translation_key": None,
|
|
|
|
"unique_id": "1234",
|
|
|
|
},
|
|
|
|
"test_domain.no_name": {
|
|
|
|
"aliases": [],
|
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
|
|
|
"config_entry_id": None,
|
|
|
|
"device_class": None,
|
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
|
|
|
"entity_category": None,
|
|
|
|
"entity_id": "test_domain.no_name",
|
|
|
|
"has_entity_name": False,
|
|
|
|
"hidden_by": None,
|
|
|
|
"icon": None,
|
|
|
|
"id": ANY,
|
|
|
|
"name": None,
|
|
|
|
"options": {},
|
|
|
|
"original_device_class": None,
|
|
|
|
"original_icon": None,
|
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
|
|
|
"translation_key": None,
|
|
|
|
"unique_id": "6789",
|
|
|
|
},
|
|
|
|
"test_domain.no_such_entity": None,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_entity(hass: HomeAssistant, client) -> None:
|
2019-08-16 16:22:45 -07:00
|
|
|
"""Test updating entity."""
|
|
|
|
registry = mock_registry(
|
2019-07-31 12:25:30 -07:00
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.world": RegistryEntry(
|
|
|
|
entity_id="test_domain.world",
|
|
|
|
unique_id="1234",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
name="before update",
|
2020-02-11 09:40:50 -08:00
|
|
|
icon="icon:before update",
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
2018-02-24 10:53:59 -08:00
|
|
|
platform = MockEntityPlatform(hass)
|
2019-07-31 12:25:30 -07:00
|
|
|
entity = MockEntity(unique_id="1234")
|
2018-02-24 10:53:59 -08:00
|
|
|
await platform.async_add_entities([entity])
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("test_domain.world")
|
2018-02-24 10:53:59 -08:00
|
|
|
assert state is not None
|
2019-07-31 12:25:30 -07:00
|
|
|
assert state.name == "before update"
|
2020-09-22 00:03:39 +03:00
|
|
|
assert state.attributes[ATTR_ICON] == "icon:before update"
|
2018-02-24 10:53:59 -08:00
|
|
|
|
2022-03-14 19:39:07 +01:00
|
|
|
# UPDATE AREA, DEVICE_CLASS, HIDDEN_BY, ICON AND NAME
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": ["alias_1", "alias_2"],
|
2020-10-24 21:25:28 +02:00
|
|
|
"area_id": "mock-area-id",
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": "custom_device_class",
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": "user", # We exchange strings over the WS API, not enums
|
2021-11-22 17:38:06 +01:00
|
|
|
"icon": "icon:after update",
|
|
|
|
"name": "after update",
|
2019-07-31 12:25:30 -07:00
|
|
|
}
|
|
|
|
)
|
2018-06-06 01:08:36 -07:00
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["result"] == {
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_entry": {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": unordered(["alias_1", "alias_2"]),
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": "mock-area-id",
|
|
|
|
"capabilities": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"config_entry_id": None,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": "custom_device_class",
|
2020-11-09 19:47:45 +01:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_id": "test_domain.world",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": "user", # We exchange strings over the WS API, not enums
|
2020-11-09 19:47:45 +01:00
|
|
|
"icon": "icon:after update",
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": "after update",
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"unique_id": "1234",
|
|
|
|
}
|
2018-02-24 10:53:59 -08:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("test_domain.world")
|
|
|
|
assert state.name == "after update"
|
2020-09-22 00:03:39 +03:00
|
|
|
assert state.attributes[ATTR_ICON] == "icon:after update"
|
2018-02-24 10:53:59 -08:00
|
|
|
|
2022-03-14 19:39:07 +01:00
|
|
|
# UPDATE HIDDEN_BY TO ILLEGAL VALUE
|
2019-08-22 14:12:24 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 7,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": "ivy",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
assert not msg["success"]
|
|
|
|
|
|
|
|
assert registry.entities["test_domain.world"].hidden_by is RegistryEntryHider.USER
|
|
|
|
|
|
|
|
# UPDATE DISABLED_BY TO USER
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 8,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
2022-03-14 23:07:52 +01:00
|
|
|
"disabled_by": "user", # We exchange strings over the WS API, not enums
|
2019-08-22 14:12:24 -07:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
2022-03-14 19:39:07 +01:00
|
|
|
assert msg["success"]
|
2019-08-22 14:12:24 -07:00
|
|
|
|
2019-08-22 17:32:43 -07:00
|
|
|
assert hass.states.get("test_domain.world") is None
|
2021-12-15 23:25:40 +02:00
|
|
|
assert (
|
|
|
|
registry.entities["test_domain.world"].disabled_by is RegistryEntryDisabler.USER
|
|
|
|
)
|
2019-08-16 16:22:45 -07:00
|
|
|
|
2019-08-22 14:12:24 -07:00
|
|
|
# UPDATE DISABLED_BY TO NONE
|
2019-08-16 16:22:45 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
2022-03-14 19:39:07 +01:00
|
|
|
"id": 9,
|
2019-08-16 16:22:45 -07:00
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
"disabled_by": None,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == {
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_entry": {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": unordered(["alias_1", "alias_2"]),
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": "mock-area-id",
|
|
|
|
"capabilities": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"config_entry_id": None,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": "custom_device_class",
|
2020-11-09 19:47:45 +01:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_id": "test_domain.world",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": "user", # We exchange strings over the WS API, not enums
|
2020-11-09 19:47:45 +01:00
|
|
|
"icon": "icon:after update",
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": "after update",
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"unique_id": "1234",
|
|
|
|
},
|
2022-10-20 12:20:39 +02:00
|
|
|
"require_restart": True,
|
2020-11-09 19:47:45 +01:00
|
|
|
}
|
|
|
|
|
2022-03-30 15:43:04 +02:00
|
|
|
# UPDATE ENTITY OPTION
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 10,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
"options_domain": "sensor",
|
|
|
|
"options": {"unit_of_measurement": "beard_second"},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == {
|
|
|
|
"entity_entry": {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": unordered(["alias_1", "alias_2"]),
|
2022-03-30 15:43:04 +02:00
|
|
|
"area_id": "mock-area-id",
|
|
|
|
"capabilities": None,
|
|
|
|
"config_entry_id": None,
|
|
|
|
"device_class": "custom_device_class",
|
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
|
|
|
"entity_category": None,
|
|
|
|
"entity_id": "test_domain.world",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-30 15:43:04 +02:00
|
|
|
"hidden_by": "user", # We exchange strings over the WS API, not enums
|
|
|
|
"icon": "icon:after update",
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2022-03-30 15:43:04 +02:00
|
|
|
"name": "after update",
|
|
|
|
"options": {"sensor": {"unit_of_measurement": "beard_second"}},
|
|
|
|
"original_device_class": None,
|
|
|
|
"original_icon": None,
|
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2022-03-30 15:43:04 +02:00
|
|
|
"unique_id": "1234",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-11-09 19:47:45 +01:00
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_entity_require_restart(hass: HomeAssistant, client) -> None:
|
2020-11-09 19:47:45 +01:00
|
|
|
"""Test updating entity."""
|
2022-08-30 21:07:50 +02:00
|
|
|
entity_id = "test_domain.test_platform_1234"
|
2020-11-09 19:47:45 +01:00
|
|
|
config_entry = MockConfigEntry(domain="test_platform")
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
platform = MockEntityPlatform(hass)
|
2022-08-30 21:07:50 +02:00
|
|
|
platform.config_entry = config_entry
|
2020-11-09 19:47:45 +01:00
|
|
|
entity = MockEntity(unique_id="1234")
|
|
|
|
await platform.async_add_entities([entity])
|
|
|
|
|
2022-08-30 21:07:50 +02:00
|
|
|
state = hass.states.get(entity_id)
|
2020-11-09 19:47:45 +01:00
|
|
|
assert state is not None
|
|
|
|
|
|
|
|
# UPDATE DISABLED_BY TO NONE
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 8,
|
|
|
|
"type": "config/entity_registry/update",
|
2022-08-30 21:07:50 +02:00
|
|
|
"entity_id": entity_id,
|
2020-11-09 19:47:45 +01:00
|
|
|
"disabled_by": None,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg["result"] == {
|
|
|
|
"entity_entry": {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": [],
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"config_entry_id": config_entry.entry_id,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2022-08-30 21:07:50 +02:00
|
|
|
"entity_id": entity_id,
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
|
|
|
"hidden_by": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": None,
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"unique_id": "1234",
|
|
|
|
},
|
|
|
|
"require_restart": True,
|
2019-08-16 16:22:45 -07:00
|
|
|
}
|
|
|
|
|
2018-02-24 10:53:59 -08:00
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_enable_entity_disabled_device(
|
|
|
|
hass: HomeAssistant, client, device_registry: dr.DeviceRegistry
|
|
|
|
) -> None:
|
2020-12-02 21:20:14 +01:00
|
|
|
"""Test enabling entity of disabled device."""
|
2022-08-30 21:07:50 +02:00
|
|
|
entity_id = "test_domain.test_platform_1234"
|
2020-12-02 21:20:14 +01:00
|
|
|
config_entry = MockConfigEntry(domain="test_platform")
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
device = device_registry.async_get_or_create(
|
2023-08-10 18:22:12 +02:00
|
|
|
config_entry_id=config_entry.entry_id,
|
2020-12-02 21:20:14 +01:00
|
|
|
connections={("ethernet", "12:34:56:78:90:AB:CD:EF")},
|
|
|
|
identifiers={("bridgeid", "0123")},
|
|
|
|
manufacturer="manufacturer",
|
|
|
|
model="model",
|
2021-11-24 23:32:16 +02:00
|
|
|
disabled_by=DeviceEntryDisabler.USER,
|
2020-12-02 21:20:14 +01:00
|
|
|
)
|
2022-08-30 21:07:50 +02:00
|
|
|
device_info = {
|
|
|
|
"connections": {("ethernet", "12:34:56:78:90:AB:CD:EF")},
|
|
|
|
}
|
2020-12-02 21:20:14 +01:00
|
|
|
|
|
|
|
platform = MockEntityPlatform(hass)
|
2022-08-30 21:07:50 +02:00
|
|
|
platform.config_entry = config_entry
|
|
|
|
entity = MockEntity(unique_id="1234", device_info=device_info)
|
2020-12-02 21:20:14 +01:00
|
|
|
await platform.async_add_entities([entity])
|
|
|
|
|
2022-08-30 21:07:50 +02:00
|
|
|
state = hass.states.get(entity_id)
|
|
|
|
assert state is None
|
|
|
|
|
|
|
|
entity_reg = async_get_entity_registry(hass)
|
|
|
|
entity_entry = entity_reg.async_get(entity_id)
|
|
|
|
assert entity_entry.config_entry_id == config_entry.entry_id
|
|
|
|
assert entity_entry.device_id == device.id
|
|
|
|
assert entity_entry.disabled_by == RegistryEntryDisabler.DEVICE
|
2020-12-02 21:20:14 +01:00
|
|
|
|
|
|
|
# UPDATE DISABLED_BY TO NONE
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 8,
|
|
|
|
"type": "config/entity_registry/update",
|
2022-08-30 21:07:50 +02:00
|
|
|
"entity_id": entity_id,
|
2020-12-02 21:20:14 +01:00
|
|
|
"disabled_by": None,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert not msg["success"]
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_entity_no_changes(hass: HomeAssistant, client) -> None:
|
2018-07-24 14:12:53 +02:00
|
|
|
"""Test update entity with no changes."""
|
2019-07-31 12:25:30 -07:00
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.world": RegistryEntry(
|
|
|
|
entity_id="test_domain.world",
|
|
|
|
unique_id="1234",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
name="name of entity",
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
2018-02-24 10:53:59 -08:00
|
|
|
platform = MockEntityPlatform(hass)
|
2019-07-31 12:25:30 -07:00
|
|
|
entity = MockEntity(unique_id="1234")
|
2018-02-24 10:53:59 -08:00
|
|
|
await platform.async_add_entities([entity])
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("test_domain.world")
|
2018-02-24 10:53:59 -08:00
|
|
|
assert state is not None
|
2019-07-31 12:25:30 -07:00
|
|
|
assert state.name == "name of entity"
|
2018-02-24 10:53:59 -08:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
"name": "name of entity",
|
|
|
|
}
|
|
|
|
)
|
2018-06-06 01:08:36 -07:00
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["result"] == {
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_entry": {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": [],
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"config_entry_id": None,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_id": "test_domain.world",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": "name of entity",
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"unique_id": "1234",
|
|
|
|
}
|
2018-02-24 10:53:59 -08:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
state = hass.states.get("test_domain.world")
|
|
|
|
assert state.name == "name of entity"
|
2018-02-24 10:53:59 -08:00
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_get_nonexisting_entity(client) -> None:
|
2018-07-24 14:12:53 +02:00
|
|
|
"""Test get entry with nonexisting entity."""
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/get",
|
|
|
|
"entity_id": "test_domain.no_name",
|
|
|
|
}
|
|
|
|
)
|
2018-06-06 01:08:36 -07:00
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert not msg["success"]
|
2018-02-24 10:53:59 -08:00
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_nonexisting_entity(client) -> None:
|
2018-07-24 14:12:53 +02:00
|
|
|
"""Test update a nonexisting entity."""
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.no_name",
|
|
|
|
"name": "new-name",
|
|
|
|
}
|
|
|
|
)
|
2018-06-06 01:08:36 -07:00
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert not msg["success"]
|
2018-07-24 14:12:53 +02:00
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_entity_id(hass: HomeAssistant, client) -> None:
|
2018-07-24 14:12:53 +02:00
|
|
|
"""Test update entity id."""
|
2019-07-31 12:25:30 -07:00
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.world": RegistryEntry(
|
|
|
|
entity_id="test_domain.world",
|
|
|
|
unique_id="1234",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
2018-07-24 14:12:53 +02:00
|
|
|
platform = MockEntityPlatform(hass)
|
2019-07-31 12:25:30 -07:00
|
|
|
entity = MockEntity(unique_id="1234")
|
2018-07-24 14:12:53 +02:00
|
|
|
await platform.async_add_entities([entity])
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert hass.states.get("test_domain.world") is not None
|
2018-07-24 14:12:53 +02:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
"new_entity_id": "test_domain.planet",
|
|
|
|
}
|
|
|
|
)
|
2018-07-24 14:12:53 +02:00
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["result"] == {
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_entry": {
|
2022-12-20 12:10:46 +01:00
|
|
|
"aliases": [],
|
2021-11-22 10:24:37 +01:00
|
|
|
"area_id": None,
|
|
|
|
"capabilities": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"config_entry_id": None,
|
2021-11-22 17:38:06 +01:00
|
|
|
"device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"device_id": None,
|
|
|
|
"disabled_by": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"entity_category": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"entity_id": "test_domain.planet",
|
2022-12-01 09:34:09 +01:00
|
|
|
"has_entity_name": False,
|
2022-03-14 19:39:07 +01:00
|
|
|
"hidden_by": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"icon": None,
|
2022-09-01 17:51:27 +02:00
|
|
|
"id": ANY,
|
2021-11-22 10:24:37 +01:00
|
|
|
"name": None,
|
2022-03-30 15:43:04 +02:00
|
|
|
"options": {},
|
2021-11-22 17:38:06 +01:00
|
|
|
"original_device_class": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"original_icon": None,
|
2021-11-22 10:24:37 +01:00
|
|
|
"original_name": None,
|
|
|
|
"platform": "test_platform",
|
2022-12-01 09:34:09 +01:00
|
|
|
"translation_key": None,
|
2020-11-09 19:47:45 +01:00
|
|
|
"unique_id": "1234",
|
|
|
|
}
|
2018-07-24 14:12:53 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert hass.states.get("test_domain.world") is None
|
|
|
|
assert hass.states.get("test_domain.planet") is not None
|
2019-01-30 09:50:32 -08:00
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_existing_entity_id(hass: HomeAssistant, client) -> None:
|
2020-11-09 19:47:45 +01:00
|
|
|
"""Test update entity id to an already registered entity id."""
|
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.world": RegistryEntry(
|
|
|
|
entity_id="test_domain.world",
|
|
|
|
unique_id="1234",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
),
|
|
|
|
"test_domain.planet": RegistryEntry(
|
|
|
|
entity_id="test_domain.planet",
|
|
|
|
unique_id="2345",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
platform = MockEntityPlatform(hass)
|
|
|
|
entities = [MockEntity(unique_id="1234"), MockEntity(unique_id="2345")]
|
|
|
|
await platform.async_add_entities(entities)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
"new_entity_id": "test_domain.planet",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert not msg["success"]
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_update_invalid_entity_id(hass: HomeAssistant, client) -> None:
|
2020-11-09 19:47:45 +01:00
|
|
|
"""Test update entity id to an invalid entity id."""
|
|
|
|
mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.world": RegistryEntry(
|
|
|
|
entity_id="test_domain.world",
|
|
|
|
unique_id="1234",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
platform = MockEntityPlatform(hass)
|
|
|
|
entities = [MockEntity(unique_id="1234"), MockEntity(unique_id="2345")]
|
|
|
|
await platform.async_add_entities(entities)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/update",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
"new_entity_id": "another_domain.planet",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert not msg["success"]
|
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_remove_entity(hass: HomeAssistant, client) -> None:
|
2019-01-30 09:50:32 -08:00
|
|
|
"""Test removing entity."""
|
2019-07-31 12:25:30 -07:00
|
|
|
registry = mock_registry(
|
|
|
|
hass,
|
|
|
|
{
|
|
|
|
"test_domain.world": RegistryEntry(
|
|
|
|
entity_id="test_domain.world",
|
|
|
|
unique_id="1234",
|
|
|
|
# Using component.async_add_entities is equal to platform "domain"
|
|
|
|
platform="test_platform",
|
|
|
|
name="before update",
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/remove",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
}
|
|
|
|
)
|
2019-01-30 09:50:32 -08:00
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
assert msg["success"]
|
2019-01-30 09:50:32 -08:00
|
|
|
assert len(registry.entities) == 0
|
2020-11-09 19:47:45 +01:00
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_remove_non_existing_entity(hass: HomeAssistant, client) -> None:
|
2020-11-09 19:47:45 +01:00
|
|
|
"""Test removing non existing entity."""
|
|
|
|
mock_registry(hass, {})
|
|
|
|
|
|
|
|
await client.send_json(
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"type": "config/entity_registry/remove",
|
|
|
|
"entity_id": "test_domain.world",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert not msg["success"]
|