Use new style for built-in ws commmands (#21694)

* Use new style for built-in ws commmands

* Lint
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-03-05 19:31:26 -08:00
1 parent c9b173405b
commit fc1ee9be43
4 files changed
+55 -82

No files matched your search

+1 -2
View File
@@ -5,7 +5,6 @@ from homeassistant.components.websocket_api.const import URL
from homeassistant.components.websocket_api.auth import (
TYPE_AUTH, TYPE_AUTH_INVALID, TYPE_AUTH_OK, TYPE_AUTH_REQUIRED)
from homeassistant.components.websocket_api import commands
from homeassistant.setup import async_setup_component
from tests.common import mock_coro
@@ -45,7 +44,7 @@ async def test_auth_via_msg_incorrect_pass(no_auth_websocket_client):
async def test_pre_auth_only_auth_allowed(no_auth_websocket_client):
"""Verify that before authentication, only auth messages are allowed."""
await no_auth_websocket_client.send_json({
'type': commands.TYPE_CALL_SERVICE,
'type': 'call_service',
'domain': 'domain_test',
'service': 'test_service',
'service_data': {
+17 -17
View File
@@ -6,7 +6,7 @@ from homeassistant.components.websocket_api.const import URL
from homeassistant.components.websocket_api.auth import (
TYPE_AUTH, TYPE_AUTH_OK, TYPE_AUTH_REQUIRED
)
from homeassistant.components.websocket_api import const, commands
from homeassistant.components.websocket_api import const
from homeassistant.exceptions import HomeAssistantError
from homeassistant.setup import async_setup_component
@@ -27,7 +27,7 @@ async def test_call_service(hass, websocket_client):
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_CALL_SERVICE,
'type': 'call_service',
'domain': 'domain_test',
'service': 'test_service',
'service_data': {
@@ -52,7 +52,7 @@ async def test_call_service_not_found(hass, websocket_client):
"""Test call service command."""
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_CALL_SERVICE,
'type': 'call_service',
'domain': 'domain_test',
'service': 'test_service',
'service_data': {
@@ -83,7 +83,7 @@ async def test_call_service_error(hass, websocket_client):
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_CALL_SERVICE,
'type': 'call_service',
'domain': 'domain_test',
'service': 'ha_error',
})
@@ -98,7 +98,7 @@ async def test_call_service_error(hass, websocket_client):
await websocket_client.send_json({
'id': 6,
'type': commands.TYPE_CALL_SERVICE,
'type': 'call_service',
'domain': 'domain_test',
'service': 'unknown_error',
})
@@ -118,7 +118,7 @@ async def test_subscribe_unsubscribe_events(hass, websocket_client):
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_SUBSCRIBE_EVENTS,
'type': 'subscribe_events',
'event_type': 'test_event'
})
@@ -138,7 +138,7 @@ async def test_subscribe_unsubscribe_events(hass, websocket_client):
msg = await websocket_client.receive_json()
assert msg['id'] == 5
assert msg['type'] == commands.TYPE_EVENT
assert msg['type'] == 'event'
event = msg['event']
assert event['event_type'] == 'test_event'
@@ -147,7 +147,7 @@ async def test_subscribe_unsubscribe_events(hass, websocket_client):
await websocket_client.send_json({
'id': 6,
'type': commands.TYPE_UNSUBSCRIBE_EVENTS,
'type': 'unsubscribe_events',
'subscription': 5
})
@@ -167,7 +167,7 @@ async def test_get_states(hass, websocket_client):
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_GET_STATES,
'type': 'get_states',
})
msg = await websocket_client.receive_json()
@@ -189,7 +189,7 @@ async def test_get_services(hass, websocket_client):
"""Test get_services command."""
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_GET_SERVICES,
'type': 'get_services',
})
msg = await websocket_client.receive_json()
@@ -203,7 +203,7 @@ async def test_get_config(hass, websocket_client):
"""Test get_config command."""
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_GET_CONFIG,
'type': 'get_config',
})
msg = await websocket_client.receive_json()
@@ -224,12 +224,12 @@ async def test_ping(websocket_client):
"""Test get_panels command."""
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_PING,
'type': 'ping',
})
msg = await websocket_client.receive_json()
assert msg['id'] == 5
assert msg['type'] == commands.TYPE_PONG
assert msg['type'] == 'pong'
async def test_call_service_context_with_user(hass, aiohttp_client,
@@ -258,7 +258,7 @@ async def test_call_service_context_with_user(hass, aiohttp_client,
await ws.send_json({
'id': 5,
'type': commands.TYPE_CALL_SERVICE,
'type': 'call_service',
'domain': 'domain_test',
'service': 'test_service',
'service_data': {
@@ -285,7 +285,7 @@ async def test_subscribe_requires_admin(websocket_client, hass_admin_user):
hass_admin_user.groups = []
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_SUBSCRIBE_EVENTS,
'type': 'subscribe_events',
'event_type': 'test_event'
})
@@ -307,7 +307,7 @@ async def test_states_filters_visible(hass, hass_admin_user, websocket_client):
hass.states.async_set('test.not_visible_entity', 'invisible')
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_GET_STATES,
'type': 'get_states',
})
msg = await websocket_client.receive_json()
@@ -327,7 +327,7 @@ async def test_get_states_not_allows_nan(hass, websocket_client):
await websocket_client.send_json({
'id': 5,
'type': commands.TYPE_GET_STATES,
'type': 'get_states',
})
msg = await websocket_client.receive_json()
+2 -2
View File
@@ -5,7 +5,7 @@ from unittest.mock import patch, Mock
from aiohttp import WSMsgType
import pytest
from homeassistant.components.websocket_api import const, commands, messages
from homeassistant.components.websocket_api import const, messages
@pytest.fixture
@@ -56,7 +56,7 @@ def test_pending_msg_overflow(hass, mock_low_queue, websocket_client):
for idx in range(10):
yield from websocket_client.send_json({
'id': idx + 1,
'type': commands.TYPE_PING,
'type': 'ping',
})
msg = yield from websocket_client.receive()
assert msg.type == WSMsgType.close