From eca45f9dd0ae3a85ef37f0f83fab33331d7c2bb9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 19 Oct 2022 04:08:06 +0200 Subject: [PATCH] Add websocket type hints in conversation (#80535) --- .../components/conversation/__init__.py | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/conversation/__init__.py b/homeassistant/components/conversation/__init__.py index 9fd6d1ad3e2..deab740909e 100644 --- a/homeassistant/components/conversation/__init__.py +++ b/homeassistant/components/conversation/__init__.py @@ -4,6 +4,7 @@ from __future__ import annotations from http import HTTPStatus import logging import re +from typing import Any import voluptuous as vol @@ -84,7 +85,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: {"type": "conversation/process", "text": str, vol.Optional("conversation_id"): str} ) @websocket_api.async_response -async def websocket_process(hass, connection, msg): +async def websocket_process( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """Process text.""" connection.send_result( msg["id"], @@ -96,7 +101,11 @@ async def websocket_process(hass, connection, msg): @websocket_api.websocket_command({"type": "conversation/agent/info"}) @websocket_api.async_response -async def websocket_get_agent_info(hass, connection, msg): +async def websocket_get_agent_info( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """Do we need onboarding.""" agent = await _get_agent(hass) @@ -111,7 +120,11 @@ async def websocket_get_agent_info(hass, connection, msg): @websocket_api.websocket_command({"type": "conversation/onboarding/set", "shown": bool}) @websocket_api.async_response -async def websocket_set_onboarding(hass, connection, msg): +async def websocket_set_onboarding( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """Set onboarding status.""" agent = await _get_agent(hass) @@ -120,7 +133,7 @@ async def websocket_set_onboarding(hass, connection, msg): if success: connection.send_result(msg["id"]) else: - connection.send_error(msg["id"]) + connection.send_error(msg["id"], "error", "Failed to set onboarding") class ConversationProcessView(http.HomeAssistantView): @@ -165,7 +178,10 @@ async def _get_agent(hass: core.HomeAssistant) -> AbstractConversationAgent: async def _async_converse( - hass: core.HomeAssistant, text: str, conversation_id: str, context: core.Context + hass: core.HomeAssistant, + text: str, + conversation_id: str | None, + context: core.Context, ) -> intent.IntentResponse: """Process text and get intent.""" agent = await _get_agent(hass)