node-red-contrib-alice 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/nodes/alice-event.js +24 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# NodeRed Home (node-red-contrib-alice)
|
|
2
2
|
|
|
3
|
-
**NodeRed Home** (node-red-contrib-alice) - это
|
|
3
|
+
**NodeRed Home** (node-red-contrib-alice) - это сервис позволит, в несколько простых шагов, подключить любые ваши устройства заведенные в Node-RED к умному дому от Яндекса и управлять ими с помощью голосового помощника Алиса.
|
|
4
4
|
|
|
5
5
|
[](https://nodered.org)
|
|
6
6
|
[](https://nodejs.org/en/)
|
package/nodes/alice-event.js
CHANGED
|
@@ -9,7 +9,7 @@ function AliceEvent(config){
|
|
|
9
9
|
const stype = 'devices.properties.event';
|
|
10
10
|
const instance = config.instance;
|
|
11
11
|
const reportable = true;
|
|
12
|
-
const retrievable =
|
|
12
|
+
const retrievable = false;
|
|
13
13
|
const events = config.events;
|
|
14
14
|
let initState = false;
|
|
15
15
|
let curentState = {
|
|
@@ -21,7 +21,7 @@ function AliceEvent(config){
|
|
|
21
21
|
};
|
|
22
22
|
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const init = ()=>{
|
|
25
25
|
this.debug("Starting sensor initilization ...");
|
|
26
26
|
let objEvents=[]
|
|
27
27
|
events.forEach(v => {
|
|
@@ -50,10 +50,14 @@ function AliceEvent(config){
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
// Проверяем сам девайс уже инициирован
|
|
53
|
-
if (device.initState)
|
|
53
|
+
if (device.initState) init();
|
|
54
54
|
|
|
55
55
|
device.on("online",()=>{
|
|
56
|
-
|
|
56
|
+
if (!initState){
|
|
57
|
+
init();
|
|
58
|
+
}else{
|
|
59
|
+
this.status({fill:"green",shape:"dot",text: curentState.state.value});
|
|
60
|
+
};
|
|
57
61
|
});
|
|
58
62
|
|
|
59
63
|
device.on("offline",()=>{
|
|
@@ -73,16 +77,23 @@ function AliceEvent(config){
|
|
|
73
77
|
}else{
|
|
74
78
|
curentState.state.value = msg.payload;
|
|
75
79
|
};
|
|
80
|
+
// для кнопок обнуляем значение через 1 сек
|
|
81
|
+
if (instance=='button'){
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
curentState.state.value = null;
|
|
84
|
+
this.status({fill:"green",shape:"dot",text:""});
|
|
85
|
+
}, 1000);
|
|
86
|
+
};
|
|
76
87
|
device.updateSensorState(id,curentState)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
.then(ref=>{
|
|
89
|
+
this.status({fill:"green",shape:"dot",text: curentState.state.value});
|
|
90
|
+
if (done) {done();}
|
|
91
|
+
})
|
|
92
|
+
.catch(err=>{
|
|
93
|
+
this.error("Error on update sensor state: " +err.message);
|
|
94
|
+
this.status({fill:"red",shape:"dot",text:"Error"});
|
|
95
|
+
if (done) {done();}
|
|
96
|
+
})
|
|
86
97
|
});
|
|
87
98
|
|
|
88
99
|
this.on('close', function(removed, done) {
|