Add response slot to HassRespond intent (#133162)

This commit is contained in:
Michael Hansen 2024-12-13 14:19:43 -06:00 committed by GitHub
parent 50b897bdaa
commit f06fda8023
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View File

@ -139,7 +139,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
intent.async_register(hass, TimerStatusIntentHandler())
intent.async_register(hass, GetCurrentDateIntentHandler())
intent.async_register(hass, GetCurrentTimeIntentHandler())
intent.async_register(hass, HelloIntentHandler())
intent.async_register(hass, RespondIntentHandler())
return True
@ -423,15 +423,25 @@ class GetCurrentTimeIntentHandler(intent.IntentHandler):
return response
class HelloIntentHandler(intent.IntentHandler):
class RespondIntentHandler(intent.IntentHandler):
"""Responds with no action."""
intent_type = intent.INTENT_RESPOND
description = "Returns the provided response with no action."
slot_schema = {
vol.Optional("response"): cv.string,
}
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Return the provided response, but take no action."""
return intent_obj.create_response()
slots = self.async_validate_slots(intent_obj.slots)
response = intent_obj.create_response()
if "response" in slots:
response.async_set_speech(slots["response"]["value"])
return response
async def _async_process_intent(

View File

@ -466,3 +466,14 @@ async def test_intents_with_no_responses(hass: HomeAssistant) -> None:
for intent_name in (intent.INTENT_NEVERMIND, intent.INTENT_RESPOND):
response = await intent.async_handle(hass, "test", intent_name, {})
assert not response.speech
async def test_intents_respond_intent(hass: HomeAssistant) -> None:
"""Test HassRespond intent with a response slot value."""
assert await async_setup_component(hass, "homeassistant", {})
assert await async_setup_component(hass, "intent", {})
response = await intent.async_handle(
hass, "test", intent.INTENT_RESPOND, {"response": {"value": "Hello World"}}
)
assert response.speech["plain"]["speech"] == "Hello World"