Import websocket_api (part 3) (#63907)

This commit is contained in:
Erik Montnemery 2022-01-11 17:26:37 +01:00 committed by GitHub
parent 3b7448bb1c
commit 6eb0447566
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 18 deletions

View File

@ -231,8 +231,8 @@ async def async_setup(hass, config):
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
)
hass.components.websocket_api.async_register_command(websocket_handle_thumbnail)
hass.components.websocket_api.async_register_command(websocket_browse_media)
websocket_api.async_register_command(hass, websocket_handle_thumbnail)
websocket_api.async_register_command(hass, websocket_browse_media)
hass.http.register_view(MediaPlayerImageView(component))
await component.async_setup(config)

View File

@ -42,8 +42,8 @@ def generate_media_source_id(domain: str, identifier: str) -> str:
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the media_source component."""
hass.data[DOMAIN] = {}
hass.components.websocket_api.async_register_command(websocket_browse_media)
hass.components.websocket_api.async_register_command(websocket_resolve_media)
websocket_api.async_register_command(hass, websocket_browse_media)
websocket_api.async_register_command(hass, websocket_resolve_media)
hass.components.frontend.async_register_built_in_panel(
"media-browser", "media_browser", "hass:play-box-multiple"
)

View File

@ -207,7 +207,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
DOMAIN, "mark_read", mark_read_service, SCHEMA_SERVICE_NOTIFICATION
)
hass.components.websocket_api.async_register_command(websocket_get_notifications)
websocket_api.async_register_command(hass, websocket_get_notifications)
return True

View File

@ -166,18 +166,26 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
"shopping-list", "shopping_list", "mdi:cart"
)
hass.components.websocket_api.async_register_command(
WS_TYPE_SHOPPING_LIST_ITEMS, websocket_handle_items, SCHEMA_WEBSOCKET_ITEMS
websocket_api.async_register_command(
hass,
WS_TYPE_SHOPPING_LIST_ITEMS,
websocket_handle_items,
SCHEMA_WEBSOCKET_ITEMS,
)
hass.components.websocket_api.async_register_command(
WS_TYPE_SHOPPING_LIST_ADD_ITEM, websocket_handle_add, SCHEMA_WEBSOCKET_ADD_ITEM
websocket_api.async_register_command(
hass,
WS_TYPE_SHOPPING_LIST_ADD_ITEM,
websocket_handle_add,
SCHEMA_WEBSOCKET_ADD_ITEM,
)
hass.components.websocket_api.async_register_command(
websocket_api.async_register_command(
hass,
WS_TYPE_SHOPPING_LIST_UPDATE_ITEM,
websocket_handle_update,
SCHEMA_WEBSOCKET_UPDATE_ITEM,
)
hass.components.websocket_api.async_register_command(
websocket_api.async_register_command(
hass,
WS_TYPE_SHOPPING_LIST_CLEAR_ITEMS,
websocket_handle_clear,
SCHEMA_WEBSOCKET_CLEAR_ITEMS,

View File

@ -44,7 +44,7 @@ def async_register_info(
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the System Health component."""
hass.components.websocket_api.async_register_command(handle_info)
websocket_api.async_register_command(hass, handle_info)
hass.data.setdefault(DOMAIN, {})
await integration_platform.async_process_integration_platforms(

View File

@ -128,8 +128,8 @@ async def async_handle_webhook(hass, webhook_id, request):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Initialize the webhook component."""
hass.http.register_view(WebhookView)
hass.components.websocket_api.async_register_command(websocket_list)
hass.components.websocket_api.async_register_command(websocket_handle)
websocket_api.async_register_command(hass, websocket_list)
websocket_api.async_register_command(hass, websocket_handle)
return True

View File

@ -20,7 +20,7 @@ async def test_send_big_result(hass, websocket_client):
async def send_big_result(hass, connection, msg):
await connection.send_big_result(msg["id"], {"big": "result"})
hass.components.websocket_api.async_register_command(send_big_result)
websocket_api.async_register_command(hass, send_big_result)
await websocket_client.send_json({"id": 5, "type": "big_result"})

View File

@ -4,7 +4,11 @@ from unittest.mock import Mock, patch
from aiohttp import WSMsgType
import voluptuous as vol
from homeassistant.components.websocket_api import const, messages
from homeassistant.components.websocket_api import (
async_register_command,
const,
messages,
)
async def test_invalid_message_format(websocket_client):
@ -49,7 +53,8 @@ async def test_unknown_command(websocket_client):
async def test_handler_failing(hass, websocket_client):
"""Test a command that raises."""
hass.components.websocket_api.async_register_command(
async_register_command(
hass,
"bla",
Mock(side_effect=TypeError),
messages.BASE_COMMAND_MESSAGE_SCHEMA.extend({"type": "bla"}),
@ -65,7 +70,8 @@ async def test_handler_failing(hass, websocket_client):
async def test_invalid_vol(hass, websocket_client):
"""Test a command that raises invalid vol error."""
hass.components.websocket_api.async_register_command(
async_register_command(
hass,
"bla",
Mock(side_effect=TypeError),
messages.BASE_COMMAND_MESSAGE_SCHEMA.extend(