![](/img/trans.png)
[英]Report state failed for spectrum hsv in smart home action google
[英]Report state for google home action
我正在报告状态。 我使用Java作为服务器语言。 我能够成功验证用户身份。 我的智能开关具有开/关特性。 除报告状态外,其他所有东西都工作正常。 我不清楚。
作为Node.js和Google Home智能操作的新手,我有以下查询:
报告状态应在您的服务器上实现,因为它确实需要一个服务密钥,您可能不想公开泄漏该服务密钥。 (不确定与Java相比,Node.js的位置)
除了该准则之外,它还可以在允许您将状态发送到Homegraph的任何地方实施。
在Node.js编写的代码实验室中可以找到示例代码的好地方。 它显示了如何使用actions-on-google
库来报告状态(没有Java库)。
const postData = {
requestId: 'ff36a3cc', /* Any unique ID */
agentUserId: '123', /* Hardcoded user ID */
payload: {
devices: {
states: {
/* Report the current state of our washer */
[event.params.deviceId]: {
on: snapshotVal.OnOff.on,
isPaused: snapshotVal.StartStop.isPaused,
isRunning: snapshotVal.StartStop.isRunning,
},
},
},
},
};
return app.reportState(postData)
.then((data) => {
console.log('Report state came back');
console.info(data);
});
在onWrite((event,context)和[context.params.deviceId]中添加“上下文”
/**
* Send a REPORT STATE call to the homegraph when data for any device id
* has been changed.
*/
exports.reportstate = functions.database.ref('/{deviceId}').onWrite((event,context) => {
console.info('Firebase write event triggered this cloud function');
const snapshotVal = event.after.val();
const postData = {
requestId: 'ff36a3cc', /* Any unique ID */
agentUserId: '123', /* Hardcoded user ID */
payload: {
devices: {
states: {
/* Report the current state of our washer */
[context.params.deviceId]: {
on: snapshotVal.OnOff.on,
},
},
},
},
};
return app.reportState(postData)
.then((data) => {
console.log('Report state came back');
console.info(data);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.