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
2019-03-05 19:31:26 -08:00
committed by GitHub
parent c9b173405b
commit fc1ee9be43
4 changed files with 55 additions and 82 deletions

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()