From 3b7448bb1c551e649c46493fed8cbd0497848dce Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 11 Jan 2022 17:26:25 +0100 Subject: [PATCH] Import websocket_api (part 2) (#63906) --- .../components/config/entity_registry.py | 8 +++---- .../components/conversation/__init__.py | 6 ++--- .../components/device_automation/__init__.py | 24 +++++++++---------- homeassistant/components/frontend/__init__.py | 8 +++---- homeassistant/components/frontend/storage.py | 4 ++-- homeassistant/components/history/__init__.py | 6 ++--- homeassistant/components/html5/notify.py | 4 ++-- homeassistant/components/lovelace/__init__.py | 22 ++++++----------- 8 files changed, 35 insertions(+), 47 deletions(-) diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py index d42c5be08fc3..26a2d930d187 100644 --- a/homeassistant/components/config/entity_registry.py +++ b/homeassistant/components/config/entity_registry.py @@ -18,10 +18,10 @@ from homeassistant.helpers.entity_registry import ( async def async_setup(hass): """Enable the Entity Registry views.""" - hass.components.websocket_api.async_register_command(websocket_list_entities) - hass.components.websocket_api.async_register_command(websocket_get_entity) - hass.components.websocket_api.async_register_command(websocket_update_entity) - hass.components.websocket_api.async_register_command(websocket_remove_entity) + websocket_api.async_register_command(hass, websocket_list_entities) + websocket_api.async_register_command(hass, websocket_get_entity) + websocket_api.async_register_command(hass, websocket_update_entity) + websocket_api.async_register_command(hass, websocket_remove_entity) return True diff --git a/homeassistant/components/conversation/__init__.py b/homeassistant/components/conversation/__init__.py index 3263e2e77e02..d04878cae4ee 100644 --- a/homeassistant/components/conversation/__init__.py +++ b/homeassistant/components/conversation/__init__.py @@ -73,9 +73,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: DOMAIN, SERVICE_PROCESS, handle_service, schema=SERVICE_PROCESS_SCHEMA ) hass.http.register_view(ConversationProcessView()) - hass.components.websocket_api.async_register_command(websocket_process) - hass.components.websocket_api.async_register_command(websocket_get_agent_info) - hass.components.websocket_api.async_register_command(websocket_set_onboarding) + websocket_api.async_register_command(hass, websocket_process) + websocket_api.async_register_command(hass, websocket_get_agent_info) + websocket_api.async_register_command(hass, websocket_set_onboarding) return True diff --git a/homeassistant/components/device_automation/__init__.py b/homeassistant/components/device_automation/__init__.py index 3d16290d325d..603e88fd8c8e 100644 --- a/homeassistant/components/device_automation/__init__.py +++ b/homeassistant/components/device_automation/__init__.py @@ -96,23 +96,21 @@ async def async_get_device_automations( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up device automation.""" - hass.components.websocket_api.async_register_command( - websocket_device_automation_list_actions + websocket_api.async_register_command(hass, websocket_device_automation_list_actions) + websocket_api.async_register_command( + hass, websocket_device_automation_list_conditions ) - hass.components.websocket_api.async_register_command( - websocket_device_automation_list_conditions + websocket_api.async_register_command( + hass, websocket_device_automation_list_triggers ) - hass.components.websocket_api.async_register_command( - websocket_device_automation_list_triggers + websocket_api.async_register_command( + hass, websocket_device_automation_get_action_capabilities ) - hass.components.websocket_api.async_register_command( - websocket_device_automation_get_action_capabilities + websocket_api.async_register_command( + hass, websocket_device_automation_get_condition_capabilities ) - hass.components.websocket_api.async_register_command( - websocket_device_automation_get_condition_capabilities - ) - hass.components.websocket_api.async_register_command( - websocket_device_automation_get_trigger_capabilities + websocket_api.async_register_command( + hass, websocket_device_automation_get_trigger_capabilities ) return True diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 005384b6beb7..b4a2c9c97e97 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -326,10 +326,10 @@ def _frontend_root(dev_repo_path: str | None) -> pathlib.Path: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the serving of the frontend.""" await async_setup_frontend_storage(hass) - hass.components.websocket_api.async_register_command(websocket_get_panels) - hass.components.websocket_api.async_register_command(websocket_get_themes) - hass.components.websocket_api.async_register_command(websocket_get_translations) - hass.components.websocket_api.async_register_command(websocket_get_version) + websocket_api.async_register_command(hass, websocket_get_panels) + websocket_api.async_register_command(hass, websocket_get_themes) + websocket_api.async_register_command(hass, websocket_get_translations) + websocket_api.async_register_command(hass, websocket_get_version) hass.http.register_view(ManifestJSONView()) conf = config.get(DOMAIN, {}) diff --git a/homeassistant/components/frontend/storage.py b/homeassistant/components/frontend/storage.py index d7aabbec9b8a..e5100ca3ab28 100644 --- a/homeassistant/components/frontend/storage.py +++ b/homeassistant/components/frontend/storage.py @@ -19,8 +19,8 @@ STORAGE_VERSION_USER_DATA = 1 async def async_setup_frontend_storage(hass: HomeAssistant) -> None: """Set up frontend storage.""" hass.data[DATA_STORAGE] = ({}, {}) - hass.components.websocket_api.async_register_command(websocket_set_user_data) - hass.components.websocket_api.async_register_command(websocket_get_user_data) + websocket_api.async_register_command(hass, websocket_set_user_data) + websocket_api.async_register_command(hass, websocket_get_user_data) def with_store(orig_func: Callable) -> Callable: diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index 1c60bff27652..48a5204d2c05 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -101,10 +101,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.components.frontend.async_register_built_in_panel( "history", "history", "hass:chart-box" ) - hass.components.websocket_api.async_register_command( - ws_get_statistics_during_period - ) - hass.components.websocket_api.async_register_command(ws_get_list_statistic_ids) + websocket_api.async_register_command(hass, ws_get_statistics_during_period) + websocket_api.async_register_command(hass, ws_get_list_statistic_ids) return True diff --git a/homeassistant/components/html5/notify.py b/homeassistant/components/html5/notify.py index 92663bcdf90e..0a6cc689292a 100644 --- a/homeassistant/components/html5/notify.py +++ b/homeassistant/components/html5/notify.py @@ -179,8 +179,8 @@ def get_service(hass, config, discovery_info=None): def websocket_appkey(hass, connection, msg): connection.send_message(websocket_api.result_message(msg["id"], vapid_pub_key)) - hass.components.websocket_api.async_register_command( - WS_TYPE_APPKEY, websocket_appkey, SCHEMA_WS_APPKEY + websocket_api.async_register_command( + hass, WS_TYPE_APPKEY, websocket_appkey, SCHEMA_WS_APPKEY ) hass.http.register_view(HTML5PushRegistrationView(registrations, json_path)) diff --git a/homeassistant/components/lovelace/__init__.py b/homeassistant/components/lovelace/__init__.py index 6f5de83fd30b..9b268dfdfcdc 100644 --- a/homeassistant/components/lovelace/__init__.py +++ b/homeassistant/components/lovelace/__init__.py @@ -3,7 +3,7 @@ import logging import voluptuous as vol -from homeassistant.components import frontend +from homeassistant.components import frontend, websocket_api from homeassistant.config import async_hass_config_yaml, async_process_component_config from homeassistant.const import CONF_FILENAME, CONF_MODE, CONF_RESOURCES from homeassistant.core import HomeAssistant, ServiceCall, callback @@ -121,22 +121,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: RESOURCE_UPDATE_FIELDS, ).async_setup(hass, create_list=False) - hass.components.websocket_api.async_register_command( - websocket.websocket_lovelace_config - ) - hass.components.websocket_api.async_register_command( - websocket.websocket_lovelace_save_config - ) - hass.components.websocket_api.async_register_command( - websocket.websocket_lovelace_delete_config - ) - hass.components.websocket_api.async_register_command( - websocket.websocket_lovelace_resources + websocket_api.async_register_command(hass, websocket.websocket_lovelace_config) + websocket_api.async_register_command(hass, websocket.websocket_lovelace_save_config) + websocket_api.async_register_command( + hass, websocket.websocket_lovelace_delete_config ) + websocket_api.async_register_command(hass, websocket.websocket_lovelace_resources) - hass.components.websocket_api.async_register_command( - websocket.websocket_lovelace_dashboards - ) + websocket_api.async_register_command(hass, websocket.websocket_lovelace_dashboards) hass.data[DOMAIN] = { # We store a dictionary mapping url_path: config. None is the default.