diff --git a/homeassistant/components/conversation/__init__.py b/homeassistant/components/conversation/__init__.py index 5692ddf3a06..9b3d5ef8dff 100644 --- a/homeassistant/components/conversation/__init__.py +++ b/homeassistant/components/conversation/__init__.py @@ -266,15 +266,18 @@ async def websocket_list_agents( for agent_info in manager.async_get_agent_info(): agent = await manager.async_get_agent(agent_info.id) + + supported_languages = agent.supported_languages + if language and supported_languages != MATCH_ALL: + supported_languages = language_util.matches( + language, supported_languages, country + ) + agent_dict: dict[str, Any] = { "id": agent_info.id, "name": agent_info.name, - "supported_languages": agent.supported_languages, + "supported_languages": supported_languages, } - if language: - agent_dict["supported_languages"] = language_util.matches( - language, agent.supported_languages, country - ) agents.append(agent_dict) connection.send_message(websocket_api.result_message(msg["id"], {"agents": agents})) diff --git a/tests/components/conversation/__init__.py b/tests/components/conversation/__init__.py index 7fb4468277b..6eadb068054 100644 --- a/tests/components/conversation/__init__.py +++ b/tests/components/conversation/__init__.py @@ -1,6 +1,8 @@ """Tests for the conversation component.""" from __future__ import annotations +from typing import Literal + from homeassistant.components import conversation from homeassistant.components.homeassistant.exposed_entities import ( DATA_EXPOSED_ENTITIES, @@ -12,11 +14,14 @@ from homeassistant.helpers import intent class MockAgent(conversation.AbstractConversationAgent): """Test Agent.""" - def __init__(self, agent_id: str) -> None: + def __init__( + self, agent_id: str, supported_languages: list[str] | Literal["*"] + ) -> None: """Initialize the agent.""" self.agent_id = agent_id self.calls = [] self.response = "Test response" + self._supported_languages = supported_languages @property def attribution(self) -> conversation.Attribution | None: @@ -26,7 +31,7 @@ class MockAgent(conversation.AbstractConversationAgent): @property def supported_languages(self) -> list[str]: """Return a list of supported languages.""" - return ["smurfish"] + return self._supported_languages async def async_process( self, user_input: conversation.ConversationInput diff --git a/tests/components/conversation/conftest.py b/tests/components/conversation/conftest.py index 46f57dbcab9..85d5b5daa91 100644 --- a/tests/components/conversation/conftest.py +++ b/tests/components/conversation/conftest.py @@ -3,6 +3,7 @@ import pytest from homeassistant.components import conversation +from homeassistant.const import MATCH_ALL from . import MockAgent @@ -14,6 +15,16 @@ def mock_agent(hass): """Mock agent.""" entry = MockConfigEntry(entry_id="mock-entry") entry.add_to_hass(hass) - agent = MockAgent(entry.entry_id) + agent = MockAgent(entry.entry_id, ["smurfish"]) + conversation.async_set_agent(hass, entry, agent) + return agent + + +@pytest.fixture +def mock_agent_support_all(hass): + """Mock agent that supports all languages.""" + entry = MockConfigEntry(entry_id="mock-entry-support-all") + entry.add_to_hass(hass) + agent = MockAgent(entry.entry_id, MATCH_ALL) conversation.async_set_agent(hass, entry, agent) return agent diff --git a/tests/components/conversation/snapshots/test_init.ambr b/tests/components/conversation/snapshots/test_init.ambr index ac96f8947ff..017ee004a84 100644 --- a/tests/components/conversation/snapshots/test_init.ambr +++ b/tests/components/conversation/snapshots/test_init.ambr @@ -85,6 +85,11 @@ 'smurfish', ]), }), + dict({ + 'id': 'mock-entry-support-all', + 'name': 'Mock Title', + 'supported_languages': '*', + }), ]), }) # --- @@ -104,6 +109,11 @@ 'smurfish', ]), }), + dict({ + 'id': 'mock-entry-support-all', + 'name': 'Mock Title', + 'supported_languages': '*', + }), ]), }) # --- @@ -123,6 +133,11 @@ 'supported_languages': list([ ]), }), + dict({ + 'id': 'mock-entry-support-all', + 'name': 'Mock Title', + 'supported_languages': '*', + }), ]), }) # --- @@ -142,6 +157,11 @@ 'supported_languages': list([ ]), }), + dict({ + 'id': 'mock-entry-support-all', + 'name': 'Mock Title', + 'supported_languages': '*', + }), ]), }) # --- @@ -162,6 +182,11 @@ 'supported_languages': list([ ]), }), + dict({ + 'id': 'mock-entry-support-all', + 'name': 'Mock Title', + 'supported_languages': '*', + }), ]), }) # --- @@ -182,6 +207,11 @@ 'supported_languages': list([ ]), }), + dict({ + 'id': 'mock-entry-support-all', + 'name': 'Mock Title', + 'supported_languages': '*', + }), ]), }) # --- diff --git a/tests/components/conversation/test_init.py b/tests/components/conversation/test_init.py index 8ab2f1748fe..4bcfcdbf3dc 100644 --- a/tests/components/conversation/test_init.py +++ b/tests/components/conversation/test_init.py @@ -1576,6 +1576,7 @@ async def test_get_agent_list( hass: HomeAssistant, init_components, mock_agent, + mock_agent_support_all, hass_ws_client: WebSocketGenerator, snapshot: SnapshotAssertion, ) -> None: