Allow easy extension of websocket API (#14186)
* Allow easy extension of websocket API * Lint * Move panel test to frontend * Register websocket commands * Simplify test * Lint
This commit is contained in:
1 parent
cdd45e7878
commit
d82693b460
5 files changed
+203
-154
No files matched your search
@@ -7,7 +7,7 @@ from async_timeout import timeout
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.components import websocket_api as wapi, frontend
|
||||
from homeassistant.components import websocket_api as wapi
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_coro
|
||||
@@ -16,20 +16,9 @@ API_PASSWORD = 'test1234'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def websocket_client(loop, hass, aiohttp_client):
|
||||
"""Websocket client fixture connected to websocket server."""
|
||||
assert loop.run_until_complete(
|
||||
async_setup_component(hass, 'websocket_api'))
|
||||
|
||||
client = loop.run_until_complete(aiohttp_client(hass.http.app))
|
||||
ws = loop.run_until_complete(client.ws_connect(wapi.URL))
|
||||
auth_ok = loop.run_until_complete(ws.receive_json())
|
||||
assert auth_ok['type'] == wapi.TYPE_AUTH_OK
|
||||
|
||||
yield ws
|
||||
|
||||
if not ws.closed:
|
||||
loop.run_until_complete(ws.close())
|
||||
def websocket_client(hass, hass_ws_client):
|
||||
"""Create a websocket client."""
|
||||
return hass.loop.run_until_complete(hass_ws_client(hass))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -289,31 +278,6 @@ def test_get_config(hass, websocket_client):
|
||||
assert msg['result'] == hass.config.as_dict()
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_panels(hass, websocket_client):
|
||||
"""Test get_panels command."""
|
||||
yield from hass.components.frontend.async_register_built_in_panel(
|
||||
'map', 'Map', 'mdi:account-location')
|
||||
hass.data[frontend.DATA_JS_VERSION] = 'es5'
|
||||
yield from websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': wapi.TYPE_GET_PANELS,
|
||||
})
|
||||
|
||||
msg = yield from websocket_client.receive_json()
|
||||
assert msg['id'] == 5
|
||||
assert msg['type'] == wapi.TYPE_RESULT
|
||||
assert msg['success']
|
||||
assert msg['result'] == {'map': {
|
||||
'component_name': 'map',
|
||||
'url_path': 'map',
|
||||
'config': None,
|
||||
'url': None,
|
||||
'icon': 'mdi:account-location',
|
||||
'title': 'Map',
|
||||
}}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_ping(websocket_client):
|
||||
"""Test get_panels command."""
|
||||
@@ -337,3 +301,15 @@ def test_pending_msg_overflow(hass, mock_low_queue, websocket_client):
|
||||
})
|
||||
msg = yield from websocket_client.receive()
|
||||
assert msg.type == WSMsgType.close
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_unknown_command(websocket_client):
|
||||
"""Test get_panels command."""
|
||||
yield from websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': 'unknown_command',
|
||||
})
|
||||
|
||||
msg = yield from websocket_client.receive()
|
||||
assert msg.type == WSMsgType.close
|
||||
Reference in new issue
Block a user