mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Import websocket_api (part 3) (#63907)
This commit is contained in:
parent
3b7448bb1c
commit
6eb0447566
@ -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)
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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"})
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user