欢迎使用 Google Home 开发者中心,您可以在这里学习有关如何开发智能家居 Action 的新平台。注意:你将继续在 Actions 控制台中构建操作。

Intent

使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。

智能家居 intent 是一个简单的消息传递对象,用于描述 smart home Action to perform such as turn on a light or cast audio to a speaker.

所有 smart home intent 都包含在 action.devices 命名空间中,并且您必须为 intent 提供执行方式。每次 Google Assistant sends an intent to fulfillment, a user's third-party OAuth 2 access token is passed in the Authorization header.

以下是受支持的 smart home intent:

SYNC

action.devices.SYNC intent 用于请求用户已连接且可供使用的 smart home 设备的列表。

当用户使用 Google Home app (GHA) , they also get authenticated to your cloud infrastructure. Then, Assistant receives an OAuth2 token. At this point, Assistant sends a action.devices.SYNC intent to your fulfillment to retrieve the initial list of user devices and capabilities from your cloud infrastructure. 设置设备时

下图显示了 Google 基础架构与合作伙伴基础架构之间的互动。Google 基础架构中有一个可供 Google 助理客户端应用使用的合作伙伴列表,该列表随后会流向合作伙伴基础架构以完成 OAuth 身份验证。合作伙伴端的 OAuth 身份验证包括合作伙伴设置 WebView、OAuth WebView、可选设置和条款,以及合作伙伴云服务。然后,合作伙伴基础架构会将 OAuth 凭据返回给 Google 助理客户端应用。合作伙伴云服务会向 Google 助理服务发送可用的设备和功能,然后这类服务会在 Home Graph 中存储这些信息。
图 1:Google 与合作伙伴基础架构之间的交互

为避免解除关联用户帐号并重新关联,您可以向 Assistant 发送请求同步。这会将 action.devices.SYNC intent 发送到您的执行方式,以同步设备和功能列表。如需了解详情,请参阅实现请求同步

SYNC intent 的流程图
图 2:SYNC intent

本地执行方式设置期间,Local Home 平台会检查来自 smart home Action 的云执行方式的 SYNC 响应。如需详细了解如何修改 SYNC 响应以支持本地执行方式,请参阅在云执行方式中更新 SYNC 响应

查询

action.devices.QUERY intent 用于查询 smart home 设备的当前状态。

当用户查询设备状态时,为了回答“Ok Google,厨房里开了哪些灯?”之类的问题, Assistant 会向您的执行方式发送 action.devices.QUERY intent。

QUERY intent 的流程图
图 3:QUERY intent

为了提供最佳用户体验,您应实现报告状态,以主动向 Google Home Graph . For example, this lets Assistant know if your user turned on a smart light with a physical light switch. 报告用户设备的当前状态

使用报告状态报告设备状态
图 4:报告设备状态

EXECUTE

action.devices.EXECUTE intent 用于提供在 smart home 设备上执行的命令。

当用户使用 Assistant 向设备发送命令时,你的执行方式会接收到你的执行方式的 action.devices.EXECUTE intent,该 intent 说明了要执行的操作和要执行操作的设备。用户可以使用“Ok Google,打开客厅的灯”等命令在设备上执行一项操作。

EXECUTE intent 的流程图
图 5:执行 intent

断开连接

当用户将应用帐号与 Assistant 解除关联时,会触发 action.devices.DISCONNECT intent 通知您。收到 action.devices.DISCONNECT intent 后,您不应报告此用户设备的状态。