mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 22:18:40 +00:00
Add WS command config/entity_registry/list_for_display (#87787)
* Add WS command config/entity_registry/list_for_display * Make more keys in the display dict optional * Move disabled_by check to ws command handler * Hide hidden_by if not hidden * Use send_json_auto_id in the new test * Don't include entities which have no data needed for display * Include platform for entries with translation_key
This commit is contained in:
@@ -3,7 +3,7 @@ import pytest
|
||||
from pytest_unordered import unordered
|
||||
|
||||
from homeassistant.components.config import entity_registry
|
||||
from homeassistant.const import ATTR_ICON
|
||||
from homeassistant.const import ATTR_ICON, EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceEntryDisabler
|
||||
@@ -22,13 +22,16 @@ from tests.common import (
|
||||
mock_device_registry,
|
||||
mock_registry,
|
||||
)
|
||||
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(hass, hass_ws_client):
|
||||
async def client(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> MockHAClientWebSocket:
|
||||
"""Fixture that can interact with the config manager API."""
|
||||
hass.loop.run_until_complete(entity_registry.async_setup(hass))
|
||||
return hass.loop.run_until_complete(hass_ws_client(hass))
|
||||
await entity_registry.async_setup(hass)
|
||||
return await hass_ws_client(hass)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -144,6 +147,160 @@ async def test_list_entities(hass: HomeAssistant, client) -> None:
|
||||
]
|
||||
|
||||
|
||||
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,
|
||||
},
|
||||
{
|
||||
"ai": "area52",
|
||||
"di": "device123",
|
||||
"ei": "test_domain.renamed",
|
||||
},
|
||||
{
|
||||
"ei": "test_domain.hidden",
|
||||
"hb": True,
|
||||
},
|
||||
{
|
||||
"dp": 0,
|
||||
"ei": "sensor.default_precision",
|
||||
},
|
||||
{
|
||||
"dp": 0,
|
||||
"ei": "sensor.user_precision",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
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",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
async def test_get_entity(hass: HomeAssistant, client) -> None:
|
||||
"""Test get entry."""
|
||||
mock_registry(
|
||||
|
||||
Reference in New Issue
Block a user