Conversation list command to support match-all languages agents (#91844)
* Conversation list command to support match-all languages agnets * Reuse varpull/91867/head
parent
95d44e100b
commit
d4fb2cdcf7
|
@ -266,15 +266,18 @@ async def websocket_list_agents(
|
||||||
|
|
||||||
for agent_info in manager.async_get_agent_info():
|
for agent_info in manager.async_get_agent_info():
|
||||||
agent = await manager.async_get_agent(agent_info.id)
|
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] = {
|
agent_dict: dict[str, Any] = {
|
||||||
"id": agent_info.id,
|
"id": agent_info.id,
|
||||||
"name": agent_info.name,
|
"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)
|
agents.append(agent_dict)
|
||||||
|
|
||||||
connection.send_message(websocket_api.result_message(msg["id"], {"agents": agents}))
|
connection.send_message(websocket_api.result_message(msg["id"], {"agents": agents}))
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Tests for the conversation component."""
|
"""Tests for the conversation component."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from homeassistant.components import conversation
|
from homeassistant.components import conversation
|
||||||
from homeassistant.components.homeassistant.exposed_entities import (
|
from homeassistant.components.homeassistant.exposed_entities import (
|
||||||
DATA_EXPOSED_ENTITIES,
|
DATA_EXPOSED_ENTITIES,
|
||||||
|
@ -12,11 +14,14 @@ from homeassistant.helpers import intent
|
||||||
class MockAgent(conversation.AbstractConversationAgent):
|
class MockAgent(conversation.AbstractConversationAgent):
|
||||||
"""Test Agent."""
|
"""Test Agent."""
|
||||||
|
|
||||||
def __init__(self, agent_id: str) -> None:
|
def __init__(
|
||||||
|
self, agent_id: str, supported_languages: list[str] | Literal["*"]
|
||||||
|
) -> None:
|
||||||
"""Initialize the agent."""
|
"""Initialize the agent."""
|
||||||
self.agent_id = agent_id
|
self.agent_id = agent_id
|
||||||
self.calls = []
|
self.calls = []
|
||||||
self.response = "Test response"
|
self.response = "Test response"
|
||||||
|
self._supported_languages = supported_languages
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def attribution(self) -> conversation.Attribution | None:
|
def attribution(self) -> conversation.Attribution | None:
|
||||||
|
@ -26,7 +31,7 @@ class MockAgent(conversation.AbstractConversationAgent):
|
||||||
@property
|
@property
|
||||||
def supported_languages(self) -> list[str]:
|
def supported_languages(self) -> list[str]:
|
||||||
"""Return a list of supported languages."""
|
"""Return a list of supported languages."""
|
||||||
return ["smurfish"]
|
return self._supported_languages
|
||||||
|
|
||||||
async def async_process(
|
async def async_process(
|
||||||
self, user_input: conversation.ConversationInput
|
self, user_input: conversation.ConversationInput
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import conversation
|
from homeassistant.components import conversation
|
||||||
|
from homeassistant.const import MATCH_ALL
|
||||||
|
|
||||||
from . import MockAgent
|
from . import MockAgent
|
||||||
|
|
||||||
|
@ -14,6 +15,16 @@ def mock_agent(hass):
|
||||||
"""Mock agent."""
|
"""Mock agent."""
|
||||||
entry = MockConfigEntry(entry_id="mock-entry")
|
entry = MockConfigEntry(entry_id="mock-entry")
|
||||||
entry.add_to_hass(hass)
|
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)
|
conversation.async_set_agent(hass, entry, agent)
|
||||||
return agent
|
return agent
|
||||||
|
|
|
@ -85,6 +85,11 @@
|
||||||
'smurfish',
|
'smurfish',
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
dict({
|
||||||
|
'id': 'mock-entry-support-all',
|
||||||
|
'name': 'Mock Title',
|
||||||
|
'supported_languages': '*',
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -104,6 +109,11 @@
|
||||||
'smurfish',
|
'smurfish',
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
dict({
|
||||||
|
'id': 'mock-entry-support-all',
|
||||||
|
'name': 'Mock Title',
|
||||||
|
'supported_languages': '*',
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -123,6 +133,11 @@
|
||||||
'supported_languages': list([
|
'supported_languages': list([
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
dict({
|
||||||
|
'id': 'mock-entry-support-all',
|
||||||
|
'name': 'Mock Title',
|
||||||
|
'supported_languages': '*',
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -142,6 +157,11 @@
|
||||||
'supported_languages': list([
|
'supported_languages': list([
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
dict({
|
||||||
|
'id': 'mock-entry-support-all',
|
||||||
|
'name': 'Mock Title',
|
||||||
|
'supported_languages': '*',
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -162,6 +182,11 @@
|
||||||
'supported_languages': list([
|
'supported_languages': list([
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
dict({
|
||||||
|
'id': 'mock-entry-support-all',
|
||||||
|
'name': 'Mock Title',
|
||||||
|
'supported_languages': '*',
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -182,6 +207,11 @@
|
||||||
'supported_languages': list([
|
'supported_languages': list([
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
|
dict({
|
||||||
|
'id': 'mock-entry-support-all',
|
||||||
|
'name': 'Mock Title',
|
||||||
|
'supported_languages': '*',
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
|
|
@ -1576,6 +1576,7 @@ async def test_get_agent_list(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
init_components,
|
init_components,
|
||||||
mock_agent,
|
mock_agent,
|
||||||
|
mock_agent_support_all,
|
||||||
hass_ws_client: WebSocketGenerator,
|
hass_ws_client: WebSocketGenerator,
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Reference in New Issue