当我在Google主页中调用onQuery时,以下响应有什么问题?
Response {
"status": 200,
"headers": {
"content-type": "application/json;charset=utf-8"
},
"body": {
"requestId": "3400750371404214251",
"payload": {
"devices": {
"00124B001856E002:01": {
"on": "false",
"online": "true"
}
}
}
}
}
代码如下: (我正在使用下面的代码来生成输出响应,如上所示。)
const queryCloud = (deviceId) => requestAPI(...)
.then((data) => {
let result = JSON.parse(data);
console.log('****** DEVICE STATE ****** ',result);
var deviceState = result.device_status;
if(deviceState ==="ON"){
deviceState = 'true';
}else{
deviceState = 'false';
}
console.log('****QUERY CLOUD****',deviceState);
return {
on: deviceState,
online:true,
};
});
const queryDevice = (deviceId) => queryCloud(deviceId).then((data) => ({
on: data.on,
online:data.online,
}));
app.onQuery((body) => {
const {requestId} = body;
const payload = {
devices: {},
};
const queryPromises = [];
for (const input of body.inputs) {
for (const device of input.payload.devices) {
const deviceId = device.id;
queryPromises.push(queryDevice(deviceId)
.then((data) => {
// Add response to device payload
console.log('*****',data);
payload.devices[deviceId] = data;
}
));
}
}
// Wait for all promises to resolve
return Promise.all(queryPromises).then((values) => ({
requestId: requestId,
payload: payload,
})
);
});
一切似乎都很好。甚至device.on值也有效,但是何时我说device_name开启? 我收到回复说很抱歉,我现在无法联系AC。