mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add a test for async_converse (#124697)
This commit is contained in:
parent
c1c158c0aa
commit
1936aeccb9
@ -23,11 +23,22 @@ class ConversationInput:
|
|||||||
"""User input to be processed."""
|
"""User input to be processed."""
|
||||||
|
|
||||||
text: str
|
text: str
|
||||||
|
"""User spoken text."""
|
||||||
|
|
||||||
context: Context
|
context: Context
|
||||||
|
"""Context of the request."""
|
||||||
|
|
||||||
conversation_id: str | None
|
conversation_id: str | None
|
||||||
|
"""Unique identifier for the conversation."""
|
||||||
|
|
||||||
device_id: str | None
|
device_id: str | None
|
||||||
|
"""Unique identifier for the device."""
|
||||||
|
|
||||||
language: str
|
language: str
|
||||||
|
"""Language of the request."""
|
||||||
|
|
||||||
agent_id: str | None = None
|
agent_id: str | None = None
|
||||||
|
"""Agent to use for processing."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass(slots=True)
|
@dataclass(slots=True)
|
||||||
|
34
tests/components/conversation/test_agent_manager.py
Normal file
34
tests/components/conversation/test_agent_manager.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
"""Test agent manager."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from homeassistant.components.conversation import ConversationResult, async_converse
|
||||||
|
from homeassistant.core import Context, HomeAssistant
|
||||||
|
from homeassistant.helpers.intent import IntentResponse
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_converse(hass: HomeAssistant, init_components) -> None:
|
||||||
|
"""Test the async_converse method."""
|
||||||
|
context = Context()
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.conversation.default_agent.DefaultAgent.async_process",
|
||||||
|
return_value=ConversationResult(response=IntentResponse(language="test lang")),
|
||||||
|
) as mock_process:
|
||||||
|
await async_converse(
|
||||||
|
hass,
|
||||||
|
text="test command",
|
||||||
|
conversation_id="test id",
|
||||||
|
context=context,
|
||||||
|
language="test lang",
|
||||||
|
agent_id="conversation.home_assistant",
|
||||||
|
device_id="test device id",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert mock_process.called
|
||||||
|
conversation_input = mock_process.call_args[0][0]
|
||||||
|
assert conversation_input.text == "test command"
|
||||||
|
assert conversation_input.conversation_id == "test id"
|
||||||
|
assert conversation_input.context is context
|
||||||
|
assert conversation_input.language == "test lang"
|
||||||
|
assert conversation_input.agent_id == "conversation.home_assistant"
|
||||||
|
assert conversation_input.device_id == "test device id"
|
Loading…
x
Reference in New Issue
Block a user