我正在做报告状态。我使用java作为我的服务器语言。我能够成功地验证用户身份。我的智能开关有开关特性。除报告状态外,一切正常。我不太清楚。
作为node.js和google智能操作的新手,我有以下查询:
发布于 2018-10-31 19:56:51
报告国应该在您的服务器上实现,因为它确实需要一个您可能不想公开泄漏的服务密钥。(与Java相比,不确定您的Node.js从何而来)
除了该指南之外,它还可以在允许您将状态发送到家庭图的任何地方实现。
查看示例代码的一个好地方是在用codelab编写的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);
});
发布于 2019-04-15 22:27:53
在onWrite(事件、上下文)和context.params.deviceId中添加"context“
/**
* 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);
});
});
https://stackoverflow.com/questions/53089665
复制相似问题