mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add websocket list APIs for the registries (#16597)
* Add websocket list APIs for the registries * Remove identifiers * Fix tests * Use ordered dict
This commit is contained in:
60
tests/components/config/test_device_registry.py
Normal file
60
tests/components/config/test_device_registry.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""Test entity_registry API."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.config import device_registry
|
||||
from tests.common import mock_device_registry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(hass, hass_ws_client):
|
||||
"""Fixture that can interact with the config manager API."""
|
||||
hass.loop.run_until_complete(device_registry.async_setup(hass))
|
||||
yield hass.loop.run_until_complete(hass_ws_client(hass))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registry(hass):
|
||||
"""Return an empty, loaded, registry."""
|
||||
return mock_device_registry(hass)
|
||||
|
||||
|
||||
async def test_list_devices(hass, client, registry):
|
||||
"""Test list entries."""
|
||||
registry.async_get_or_create(
|
||||
config_entry='1234',
|
||||
connections={('ethernet', '12:34:56:78:90:AB:CD:EF')},
|
||||
identifiers={('bridgeid', '0123')},
|
||||
manufacturer='manufacturer', model='model')
|
||||
registry.async_get_or_create(
|
||||
config_entry='1234',
|
||||
connections={},
|
||||
identifiers={('bridgeid', '1234')},
|
||||
manufacturer='manufacturer', model='model')
|
||||
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'config/device_registry/list',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
for entry in msg['result']:
|
||||
entry.pop('id')
|
||||
|
||||
assert msg['result'] == [
|
||||
{
|
||||
'config_entries': ['1234'],
|
||||
'connections': [['ethernet', '12:34:56:78:90:AB:CD:EF']],
|
||||
'manufacturer': 'manufacturer',
|
||||
'model': 'model',
|
||||
'name': None,
|
||||
'sw_version': None
|
||||
},
|
||||
{
|
||||
'config_entries': ['1234'],
|
||||
'connections': [],
|
||||
'manufacturer': 'manufacturer',
|
||||
'model': 'model',
|
||||
'name': None,
|
||||
'sw_version': None
|
||||
}
|
||||
]
|
||||
@@ -1,4 +1,6 @@
|
||||
"""Test entity_registry API."""
|
||||
from collections import OrderedDict
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.helpers.entity_registry import RegistryEntry
|
||||
@@ -13,6 +15,49 @@ def client(hass, hass_ws_client):
|
||||
yield hass.loop.run_until_complete(hass_ws_client(hass))
|
||||
|
||||
|
||||
async def test_list_entities(hass, client):
|
||||
"""Test list entries."""
|
||||
entities = OrderedDict()
|
||||
entities['test_domain.name'] = RegistryEntry(
|
||||
entity_id='test_domain.name',
|
||||
unique_id='1234',
|
||||
platform='test_platform',
|
||||
name='Hello World'
|
||||
)
|
||||
entities['test_domain.no_name'] = RegistryEntry(
|
||||
entity_id='test_domain.no_name',
|
||||
unique_id='6789',
|
||||
platform='test_platform',
|
||||
)
|
||||
|
||||
mock_registry(hass, entities)
|
||||
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': 'config/entity_registry/list',
|
||||
})
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg['result'] == [
|
||||
{
|
||||
'config_entry_id': None,
|
||||
'device_id': None,
|
||||
'disabled_by': None,
|
||||
'entity_id': 'test_domain.name',
|
||||
'name': 'Hello World',
|
||||
'platform': 'test_platform',
|
||||
},
|
||||
{
|
||||
'config_entry_id': None,
|
||||
'device_id': None,
|
||||
'disabled_by': None,
|
||||
'entity_id': 'test_domain.no_name',
|
||||
'name': None,
|
||||
'platform': 'test_platform',
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
async def test_get_entity(hass, client):
|
||||
"""Test get entry."""
|
||||
mock_registry(hass, {
|
||||
|
||||
Reference in New Issue
Block a user