智能家居 AOG.将设备状态与 Firestore 字段集成的最佳方式(2021 年) [英] Smarthome AOG. The best way (in 2021) to integrate state of devices with firestore fields
问题描述
我有这个项目:
您可能需要在 onExecute
中添加一个中间条件到 根据 Firestore 状态返回错误:
//...for(command.devices 的常量目标){const configRef = firestore.doc(`device-configs/${target.id}`)const targetDoc = 等待 configRef.get()const {garagestate} = targetDoc.data()如果(车库状态 === 假){//车库状态存在且为假//返回错误返回 {请求标识,有效载荷:{状态:'错误',错误代码:'已经关闭'}}}//...}//...
I have this project: https://github.com/neuberfran/firebasefunction/blob/main/firebase/functions/smart-home/fulfillment.js It works well. But, for example, I want to implement a condition that if I have the garage closed and I said "close garage", the Home assistantt will alert me about it.
As shown in the photo below, I am using an rpi3/iot-device/back-end that controls the garagestate field. I need to know the best way to implement this condition, that is, read the value of the garagestate field and from that, know if I can open the garage or not:
You'd probably need to add an intermediary condition in your onExecute
to return an error based on the Firestore state:
// ...
for (const target of command.devices) {
const configRef = firestore.doc(`device-configs/${target.id}`)
const targetDoc = await configRef.get()
const {garagestate} = targetDoc.data()
if (garagestate === false) {
// garagestate exists and is false
// return an error
return {
requestId,
payload: {
status: 'ERROR',
errorCode: 'alreadyClosed'
}
}
}
// ...
}
// ...
这篇关于智能家居 AOG.将设备状态与 Firestore 字段集成的最佳方式(2021 年)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!