1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Migrate entity registry to using websocket (#14830)

* Migrate to using websocket

* Lint
This commit is contained in:
Paulus Schoutsen
2018-06-06 01:08:36 -07:00
committed by Pascal Vizeli
parent 4bccb0d2a1
commit a6880c452f
2 changed files with 117 additions and 61 deletions

View File

@@ -1,18 +1,16 @@
"""Test entity_registry API."""
import pytest
from homeassistant.setup import async_setup_component
from homeassistant.helpers.entity_registry import RegistryEntry
from homeassistant.components.config import entity_registry
from tests.common import mock_registry, MockEntity, MockEntityPlatform
@pytest.fixture
def client(hass, aiohttp_client):
def client(hass, hass_ws_client):
"""Fixture that can interact with the config manager API."""
hass.loop.run_until_complete(async_setup_component(hass, 'http', {}))
hass.loop.run_until_complete(entity_registry.async_setup(hass))
yield hass.loop.run_until_complete(aiohttp_client(hass.http.app))
yield hass.loop.run_until_complete(hass_ws_client(hass))
async def test_get_entity(hass, client):
@@ -31,20 +29,26 @@ async def test_get_entity(hass, client):
),
})
resp = await client.get(
'/api/config/entity_registry/test_domain.name')
assert resp.status == 200
data = await resp.json()
assert data == {
await client.send_json({
'id': 5,
'type': 'config/entity_registry/get',
'entity_id': 'test_domain.name',
})
msg = await client.receive_json()
assert msg['result'] == {
'entity_id': 'test_domain.name',
'name': 'Hello World'
}
resp = await client.get(
'/api/config/entity_registry/test_domain.no_name')
assert resp.status == 200
data = await resp.json()
assert data == {
await client.send_json({
'id': 6,
'type': 'config/entity_registry/get',
'entity_id': 'test_domain.no_name',
})
msg = await client.receive_json()
assert msg['result'] == {
'entity_id': 'test_domain.no_name',
'name': None
}
@@ -69,13 +73,16 @@ async def test_update_entity(hass, client):
assert state is not None
assert state.name == 'before update'
resp = await client.post(
'/api/config/entity_registry/test_domain.world', json={
'name': 'after update'
})
assert resp.status == 200
data = await resp.json()
assert data == {
await client.send_json({
'id': 6,
'type': 'config/entity_registry/update',
'entity_id': 'test_domain.world',
'name': 'after update',
})
msg = await client.receive_json()
assert msg['result'] == {
'entity_id': 'test_domain.world',
'name': 'after update'
}
@@ -103,13 +110,16 @@ async def test_update_entity_no_changes(hass, client):
assert state is not None
assert state.name == 'name of entity'
resp = await client.post(
'/api/config/entity_registry/test_domain.world', json={
'name': 'name of entity'
})
assert resp.status == 200
data = await resp.json()
assert data == {
await client.send_json({
'id': 6,
'type': 'config/entity_registry/update',
'entity_id': 'test_domain.world',
'name': 'name of entity',
})
msg = await client.receive_json()
assert msg['result'] == {
'entity_id': 'test_domain.world',
'name': 'name of entity'
}
@@ -120,15 +130,24 @@ async def test_update_entity_no_changes(hass, client):
async def test_get_nonexisting_entity(client):
"""Test get entry."""
resp = await client.get(
'/api/config/entity_registry/test_domain.non_existing')
assert resp.status == 404
await client.send_json({
'id': 6,
'type': 'config/entity_registry/get',
'entity_id': 'test_domain.no_name',
})
msg = await client.receive_json()
assert not msg['success']
async def test_update_nonexisting_entity(client):
"""Test get entry."""
resp = await client.post(
'/api/config/entity_registry/test_domain.non_existing', json={
'name': 'some name'
})
assert resp.status == 404
await client.send_json({
'id': 6,
'type': 'config/entity_registry/update',
'entity_id': 'test_domain.no_name',
'name': 'new-name'
})
msg = await client.receive_json()
assert not msg['success']