From eabbe8969dd12d920e18c6b8ef562c71b034bfe0 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 19 Apr 2023 16:53:49 +0200 Subject: [PATCH] Adjust typing of AbstractConversationAgent.supported_languages (#91648) * Adjust typing of AbstractConversationAgent.supported_languages * Update test --- homeassistant/components/conversation/agent.py | 4 ++-- homeassistant/components/openai_conversation/__init__.py | 5 +++-- tests/components/openai_conversation/test_init.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/conversation/agent.py b/homeassistant/components/conversation/agent.py index 18a2f4edf56..162338a6ff0 100644 --- a/homeassistant/components/conversation/agent.py +++ b/homeassistant/components/conversation/agent.py @@ -3,7 +3,7 @@ from __future__ import annotations from abc import ABC, abstractmethod from dataclasses import dataclass -from typing import Any, TypedDict +from typing import Any, Literal, TypedDict from homeassistant.core import Context from homeassistant.helpers import intent @@ -51,7 +51,7 @@ class AbstractConversationAgent(ABC): @property @abstractmethod - def supported_languages(self) -> list[str]: + def supported_languages(self) -> list[str] | Literal["*"]: """Return a list of supported languages.""" @abstractmethod diff --git a/homeassistant/components/openai_conversation/__init__.py b/homeassistant/components/openai_conversation/__init__.py index d6eeb85e06a..c1b569ce9e1 100644 --- a/homeassistant/components/openai_conversation/__init__.py +++ b/homeassistant/components/openai_conversation/__init__.py @@ -3,6 +3,7 @@ from __future__ import annotations from functools import partial import logging +from typing import Literal import openai from openai import error @@ -71,9 +72,9 @@ class OpenAIAgent(conversation.AbstractConversationAgent): return {"name": "Powered by OpenAI", "url": "https://www.openai.com"} @property - def supported_languages(self) -> list[str]: + def supported_languages(self) -> list[str] | Literal["*"]: """Return a list of supported languages.""" - return [MATCH_ALL] + return MATCH_ALL async def async_process( self, user_input: conversation.ConversationInput diff --git a/tests/components/openai_conversation/test_init.py b/tests/components/openai_conversation/test_init.py index 62136ecfffd..4016ac03c97 100644 --- a/tests/components/openai_conversation/test_init.py +++ b/tests/components/openai_conversation/test_init.py @@ -148,4 +148,4 @@ async def test_conversation_agent( agent = await conversation._get_agent_manager(hass).async_get_agent( mock_config_entry.entry_id ) - assert agent.supported_languages == ["*"] + assert agent.supported_languages == "*"