From 36a169cd47efacdac0378113649cc9974ad69717 Mon Sep 17 00:00:00 2001 From: Andrea Genovese Date: Wed, 4 Nov 2026 21:19:31 +0100 Subject: [PATCH] Pass continue_conversation from Wyoming handled events (#190112) Co-authored-by: Michael Hansen --- .../components/wyoming/conversation.py | 20 +++++++---- tests/components/wyoming/test_conversation.py | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/wyoming/conversation.py b/homeassistant/components/wyoming/conversation.py index abb59be944dd..473e62b8a8a0 100644 --- a/homeassistant/components/wyoming/conversation.py +++ b/homeassistant/components/wyoming/conversation.py @@ -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, diff --git a/tests/components/wyoming/test_conversation.py b/tests/components/wyoming/test_conversation.py index 4d1986153322..795c373d4562 100644 --- a/tests/components/wyoming/test_conversation.py +++ b/tests/components/wyoming/test_conversation.py @@ -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: