From 1a9ab0774215169270c3b7d003b0357c7ea06376 Mon Sep 17 00:00:00 2001
From: Michael <35783820+mib1185@users.noreply.github.com>
Date: Thu, 28 Nov 2024 18:30:05 +0100
Subject: [PATCH] Allow empty trigger sentence responses in conversations
 (#131849)

allow empty trigger sentence responses
---
 homeassistant/components/assist_pipeline/pipeline.py |  2 +-
 tests/components/conversation/test_init.py           | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/homeassistant/components/assist_pipeline/pipeline.py b/homeassistant/components/assist_pipeline/pipeline.py
index 96beaf792a7..5bbc81adb86 100644
--- a/homeassistant/components/assist_pipeline/pipeline.py
+++ b/homeassistant/components/assist_pipeline/pipeline.py
@@ -1040,7 +1040,7 @@ class PipelineRun:
                     := await conversation.async_handle_sentence_triggers(
                         self.hass, user_input
                     )
-                ):
+                ) is not None:
                     # Sentence trigger matched
                     trigger_response = intent.IntentResponse(
                         self.pipeline.conversation_language
diff --git a/tests/components/conversation/test_init.py b/tests/components/conversation/test_init.py
index 0100e62cf81..6900ba2d419 100644
--- a/tests/components/conversation/test_init.py
+++ b/tests/components/conversation/test_init.py
@@ -236,12 +236,17 @@ async def test_prepare_agent(
     assert len(mock_prepare.mock_calls) == 1
 
 
-async def test_async_handle_sentence_triggers(hass: HomeAssistant) -> None:
+@pytest.mark.parametrize(
+    ("response_template", "expected_response"),
+    [("response {{ trigger.device_id }}", "response 1234"), ("", "")],
+)
+async def test_async_handle_sentence_triggers(
+    hass: HomeAssistant, response_template: str, expected_response: str
+) -> None:
     """Test handling sentence triggers with async_handle_sentence_triggers."""
     assert await async_setup_component(hass, "homeassistant", {})
     assert await async_setup_component(hass, "conversation", {})
 
-    response_template = "response {{ trigger.device_id }}"
     assert await async_setup_component(
         hass,
         "automation",
@@ -260,7 +265,6 @@ async def test_async_handle_sentence_triggers(hass: HomeAssistant) -> None:
 
     # Device id will be available in response template
     device_id = "1234"
-    expected_response = f"response {device_id}"
     actual_response = await async_handle_sentence_triggers(
         hass,
         ConversationInput(
-- 
GitLab