2019-01-28 23:52:42 +00:00
|
|
|
"""Test device_registry API."""
|
2018-09-14 09:57:18 +00:00
|
|
|
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(
|
2018-09-17 11:39:30 +00:00
|
|
|
config_entry_id='1234',
|
2018-09-14 09:57:18 +00:00
|
|
|
connections={('ethernet', '12:34:56:78:90:AB:CD:EF')},
|
|
|
|
identifiers={('bridgeid', '0123')},
|
|
|
|
manufacturer='manufacturer', model='model')
|
|
|
|
registry.async_get_or_create(
|
2018-09-17 11:39:30 +00:00
|
|
|
config_entry_id='1234',
|
2018-09-14 09:57:18 +00:00
|
|
|
identifiers={('bridgeid', '1234')},
|
2018-09-17 11:39:30 +00:00
|
|
|
manufacturer='manufacturer', model='model',
|
2019-06-10 16:10:44 +00:00
|
|
|
via_device=('bridgeid', '0123'))
|
2018-09-14 09:57:18 +00:00
|
|
|
|
|
|
|
await client.send_json({
|
|
|
|
'id': 5,
|
|
|
|
'type': 'config/device_registry/list',
|
|
|
|
})
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
2018-09-17 11:39:30 +00:00
|
|
|
dev1, dev2 = [entry.pop('id') for entry in msg['result']]
|
2018-09-14 09:57:18 +00:00
|
|
|
|
|
|
|
assert msg['result'] == [
|
|
|
|
{
|
|
|
|
'config_entries': ['1234'],
|
|
|
|
'connections': [['ethernet', '12:34:56:78:90:AB:CD:EF']],
|
|
|
|
'manufacturer': 'manufacturer',
|
|
|
|
'model': 'model',
|
|
|
|
'name': None,
|
2018-09-17 11:39:30 +00:00
|
|
|
'sw_version': None,
|
2019-06-10 16:10:44 +00:00
|
|
|
'via_device_id': None,
|
2019-01-28 23:52:42 +00:00
|
|
|
'area_id': None,
|
2019-02-26 20:20:16 +00:00
|
|
|
'name_by_user': None,
|
2018-09-14 09:57:18 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'config_entries': ['1234'],
|
|
|
|
'connections': [],
|
|
|
|
'manufacturer': 'manufacturer',
|
|
|
|
'model': 'model',
|
|
|
|
'name': None,
|
2018-09-17 11:39:30 +00:00
|
|
|
'sw_version': None,
|
2019-06-10 16:10:44 +00:00
|
|
|
'via_device_id': dev1,
|
2019-01-28 23:52:42 +00:00
|
|
|
'area_id': None,
|
2019-02-26 20:20:16 +00:00
|
|
|
'name_by_user': None,
|
2018-09-14 09:57:18 +00:00
|
|
|
}
|
|
|
|
]
|
2019-01-28 23:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_update_device(hass, client, registry):
|
|
|
|
"""Test update entry."""
|
|
|
|
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')
|
|
|
|
|
|
|
|
assert not device.area_id
|
2019-02-26 20:20:16 +00:00
|
|
|
assert not device.name_by_user
|
2019-01-28 23:52:42 +00:00
|
|
|
|
|
|
|
await client.send_json({
|
|
|
|
'id': 1,
|
|
|
|
'device_id': device.id,
|
|
|
|
'area_id': '12345A',
|
2019-02-26 20:20:16 +00:00
|
|
|
'name_by_user': 'Test Friendly Name',
|
2019-01-28 23:52:42 +00:00
|
|
|
'type': 'config/device_registry/update',
|
|
|
|
})
|
|
|
|
|
|
|
|
msg = await client.receive_json()
|
|
|
|
|
|
|
|
assert msg['result']['id'] == device.id
|
|
|
|
assert msg['result']['area_id'] == '12345A'
|
2019-02-26 20:20:16 +00:00
|
|
|
assert msg['result']['name_by_user'] == 'Test Friendly Name'
|
2019-01-28 23:52:42 +00:00
|
|
|
assert len(registry.devices) == 1
|