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