diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 443225e70a6..2992d86f44b 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -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) diff --git a/homeassistant/components/media_source/__init__.py b/homeassistant/components/media_source/__init__.py index e6cd86ef08c..c73f517acd3 100644 --- a/homeassistant/components/media_source/__init__.py +++ b/homeassistant/components/media_source/__init__.py @@ -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" ) diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index 23b3a6b07d8..88a61b52038 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -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 diff --git a/homeassistant/components/shopping_list/__init__.py b/homeassistant/components/shopping_list/__init__.py index 10d5ecd5975..18fbb75e175 100644 --- a/homeassistant/components/shopping_list/__init__.py +++ b/homeassistant/components/shopping_list/__init__.py @@ -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, diff --git a/homeassistant/components/system_health/__init__.py b/homeassistant/components/system_health/__init__.py index 1d4adbfca64..be7232245e1 100644 --- a/homeassistant/components/system_health/__init__.py +++ b/homeassistant/components/system_health/__init__.py @@ -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( diff --git a/homeassistant/components/webhook/__init__.py b/homeassistant/components/webhook/__init__.py index 1988a1b1a58..6d10d276c8e 100644 --- a/homeassistant/components/webhook/__init__.py +++ b/homeassistant/components/webhook/__init__.py @@ -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 diff --git a/tests/components/websocket_api/test_connection.py b/tests/components/websocket_api/test_connection.py index 1d6bf5f2f6b..0a9ae710bc5 100644 --- a/tests/components/websocket_api/test_connection.py +++ b/tests/components/websocket_api/test_connection.py @@ -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"}) diff --git a/tests/components/websocket_api/test_init.py b/tests/components/websocket_api/test_init.py index 041c0e76533..c991eeed0d1 100644 --- a/tests/components/websocket_api/test_init.py +++ b/tests/components/websocket_api/test_init.py @@ -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(