mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Pass continue_conversation from Wyoming handled events (#190112)
Co-authored-by: Michael Hansen <mike@rhasspy.org>
This commit is contained in:
co-authored by
Michael Hansen
parent
37ba28fd69
commit
36a169cd47
@@ -141,7 +141,7 @@ class WyomingConversationEntity(
|
||||
language=user_input.language,
|
||||
).event()
|
||||
)
|
||||
intent_response = await self._async_process(
|
||||
intent_response, continue_conversation = await self._async_process(
|
||||
user_input, client, chat_log, intent_response
|
||||
)
|
||||
except (OSError, WyomingError) as err:
|
||||
@@ -167,7 +167,9 @@ class WyomingConversationEntity(
|
||||
|
||||
# Success
|
||||
return conversation.ConversationResult(
|
||||
response=intent_response, conversation_id=conversation_id
|
||||
response=intent_response,
|
||||
conversation_id=conversation_id,
|
||||
continue_conversation=continue_conversation,
|
||||
)
|
||||
|
||||
async def _async_process(
|
||||
@@ -176,9 +178,14 @@ class WyomingConversationEntity(
|
||||
client: AsyncTcpClient,
|
||||
chat_log: conversation.ChatLog,
|
||||
intent_response: intent.IntentResponse,
|
||||
) -> intent.IntentResponse:
|
||||
"""Process a sentence into an intent response."""
|
||||
) -> tuple[intent.IntentResponse, bool]:
|
||||
"""Process a sentence into an intent response.
|
||||
|
||||
Also returns whether the service expects a reply, so the client should
|
||||
listen again without a wake word.
|
||||
"""
|
||||
has_intents_list = False
|
||||
continue_conversation = False
|
||||
intents: list[Intent] = []
|
||||
|
||||
while True:
|
||||
@@ -228,6 +235,7 @@ class WyomingConversationEntity(
|
||||
# Success
|
||||
handled = Handled.from_event(event)
|
||||
intent_response.async_set_speech(handled.text or "")
|
||||
continue_conversation = bool(handled.continue_conversation)
|
||||
break
|
||||
|
||||
if NotHandled.is_type(event.type):
|
||||
@@ -240,7 +248,7 @@ class WyomingConversationEntity(
|
||||
break
|
||||
|
||||
if not intents:
|
||||
return intent_response
|
||||
return intent_response, continue_conversation
|
||||
|
||||
# Process recognized intents with a task group.
|
||||
# If any intent fails to be handled, the rest are cancelled.
|
||||
@@ -341,7 +349,7 @@ class WyomingConversationEntity(
|
||||
# language-dependent.
|
||||
intent_response.async_set_speech("\n".join(speech_texts))
|
||||
|
||||
return intent_response
|
||||
return intent_response, False
|
||||
|
||||
def _render_speech_template(
|
||||
self,
|
||||
|
||||
@@ -111,6 +111,7 @@ async def test_intent(
|
||||
assert result.response.speech, "No speech"
|
||||
assert result.response.speech.get("plain", {}).get("speech") == "success"
|
||||
assert result.conversation_id == conversation_id
|
||||
assert not result.continue_conversation
|
||||
|
||||
# Verify that chat log recorded intent as tool call
|
||||
content: chat_log.AssistantContent | None = next(
|
||||
@@ -381,6 +382,40 @@ async def test_handle(hass: HomeAssistant, init_wyoming_handle: ConfigEntry) ->
|
||||
assert result.conversation_id == conversation_id
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("continue_conversation", "expected"),
|
||||
[(True, True), (False, False), (None, False)],
|
||||
)
|
||||
async def test_handle_continue_conversation(
|
||||
hass: HomeAssistant,
|
||||
init_wyoming_handle: ConfigEntry,
|
||||
continue_conversation: bool | None,
|
||||
expected: bool,
|
||||
) -> None:
|
||||
"""Test the service can ask the client to listen again without a wake word."""
|
||||
with patch(
|
||||
"homeassistant.components.wyoming.conversation.AsyncTcpClient",
|
||||
MockAsyncTcpClient(
|
||||
[
|
||||
Handled(
|
||||
text="Which room?", continue_conversation=continue_conversation
|
||||
).event()
|
||||
]
|
||||
),
|
||||
):
|
||||
result = await conversation.async_converse(
|
||||
hass=hass,
|
||||
text="turn on the light",
|
||||
conversation_id=None,
|
||||
context=Context(),
|
||||
language=hass.config.language,
|
||||
agent_id="conversation.test_handle",
|
||||
)
|
||||
|
||||
assert result.response.speech.get("plain", {}).get("speech") == "Which room?"
|
||||
assert result.continue_conversation is expected
|
||||
|
||||
|
||||
async def test_handle_other_user(
|
||||
hass: HomeAssistant, init_wyoming_handle: ConfigEntry
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user