触发意图
当你触发一个意图时,你将得到一个响应或者会引发一个错误。由组件来决定将结果返回给用户。
这是在Home Assistant中处理意图的示例代码:
from homeassistant.helpers import intent
intent_type = 'TurnLightOn'
slots = {
'entity': { 'value': 'Kitchen' }
}
try:
intent_response = yield from intent.async_handle(
hass, 'example_component', intent_type, slots
)
except intent.UnknownIntent as err:
_LOGGER.warning('Received unknown intent %s', intent_type)
except intent.InvalidSlotInfo as err:
_LOGGER.error('Received invalid slot data: %s', err)
except intent.IntentError:
_LOGGER.exception('Error handling request for %s', intent_type)
意图响应是homeassistant.helpers.intent.IntentResponse的一个实例,其属性如下:
| 名称 | 类型 | 描述 |
|---|---|---|
intent | Intent | 触发响应的意图实例。 |
speech | Dictionary | 语音响应。每个键是一种类型。允许的类型是plain和ssml。 |
card | Dictionary | 卡片响应。每个键是一种类型。 |
语音字典值:
| 名称 | 类型 | 描述 |
|---|---|---|
speech | String | 要说的文本。 |
extra_data | Any | 与此语音相关的额外信息。 |
卡片字典值:
| 名称 | 类型 | 描述 |
|---|---|---|
title | String | 卡片的标题。 |
content | Any | 卡片的内容。 |
总结
介绍了在Home Assistant中触发意图的操作及相关处理。触发意图后会得到响应或错误,示例代码展示了如何处理意图,包括处理不同类型的异常情况。同时详细说明了意图响应实例的属性,包括意图、语音和卡片响应相关的内容,以及语音和卡片字典值的具体含义,为开发者在实现意图触发和处理功能时提供了清晰的指导,有助于准确构建和处理意图相关的交互逻辑,提升用户与系统的语音交互体验。
4675

被折叠的 条评论
为什么被折叠?



