mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add response slot to HassRespond intent (#133162)
This commit is contained in:
parent
50b897bdaa
commit
f06fda8023
@ -139,7 +139,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
intent.async_register(hass, TimerStatusIntentHandler())
|
intent.async_register(hass, TimerStatusIntentHandler())
|
||||||
intent.async_register(hass, GetCurrentDateIntentHandler())
|
intent.async_register(hass, GetCurrentDateIntentHandler())
|
||||||
intent.async_register(hass, GetCurrentTimeIntentHandler())
|
intent.async_register(hass, GetCurrentTimeIntentHandler())
|
||||||
intent.async_register(hass, HelloIntentHandler())
|
intent.async_register(hass, RespondIntentHandler())
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -423,15 +423,25 @@ class GetCurrentTimeIntentHandler(intent.IntentHandler):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class HelloIntentHandler(intent.IntentHandler):
|
class RespondIntentHandler(intent.IntentHandler):
|
||||||
"""Responds with no action."""
|
"""Responds with no action."""
|
||||||
|
|
||||||
intent_type = intent.INTENT_RESPOND
|
intent_type = intent.INTENT_RESPOND
|
||||||
description = "Returns the provided response with no action."
|
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:
|
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
||||||
"""Return the provided response, but take no action."""
|
"""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(
|
async def _async_process_intent(
|
||||||
|
@ -466,3 +466,14 @@ async def test_intents_with_no_responses(hass: HomeAssistant) -> None:
|
|||||||
for intent_name in (intent.INTENT_NEVERMIND, intent.INTENT_RESPOND):
|
for intent_name in (intent.INTENT_NEVERMIND, intent.INTENT_RESPOND):
|
||||||
response = await intent.async_handle(hass, "test", intent_name, {})
|
response = await intent.async_handle(hass, "test", intent_name, {})
|
||||||
assert not response.speech
|
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user