node-red-contrib-alice 0.6.11 → 1.0.0
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 -0
- package/nodes/alice-color.js +25 -28
- package/nodes/alice-mode.js +13 -15
- package/nodes/alice-onoff.js +50 -48
- package/nodes/alice-range.js +16 -17
- package/nodes/alice-sensor.js +12 -20
- package/nodes/alice-togle.js +17 -16
- package/nodes/alice.html +55 -178
- package/nodes/alice.js +189 -299
- package/package.json +1 -2
- package/nodes/alice-event.html +0 -226
- package/nodes/alice-event.js +0 -108
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|

|
|
11
11
|
[](https://github.com/efa2000/node-red-contrib-alice/issues)
|
|
12
12
|
|
|
13
|
+
## ВАЖНО !!!! с 28-го марта 2022 г. в связи с необходимостью перехода на новую версию, временно приостанавливается работа сервиса
|
|
13
14
|
|
|
14
15
|
**NodeRed Home** (node-red-contrib-alice) - это бесплатный сервис который позволит, в несколько простых шагов, подключить любые ваши устройства заведенные в Node-RED к умному дому от Яндекса и управлять ими с помощью голосового помощника Алиса.
|
|
15
16
|
|
package/nodes/alice-color.js
CHANGED
|
@@ -4,6 +4,7 @@ module.exports = function(RED) {
|
|
|
4
4
|
function AliceColor(config){
|
|
5
5
|
RED.nodes.createNode(this,config);
|
|
6
6
|
this.device = RED.nodes.getNode(config.device);
|
|
7
|
+
this.device.setMaxListeners(this.device.getMaxListeners() + 1); // увеличиваем лимит для event
|
|
7
8
|
this.name = config.name;
|
|
8
9
|
this.ctype = 'devices.capabilities.color_setting';
|
|
9
10
|
this.instance = 'color_model';
|
|
@@ -30,7 +31,6 @@ module.exports = function(RED) {
|
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
this.init = ()=>{
|
|
33
|
-
this.ref = this.device.getRef(this.id);
|
|
34
34
|
var value = 0;
|
|
35
35
|
if (this.scheme=="hsv"){
|
|
36
36
|
value = {
|
|
@@ -46,10 +46,6 @@ module.exports = function(RED) {
|
|
|
46
46
|
parameters: {
|
|
47
47
|
// instance: this.scheme,//this.instance,
|
|
48
48
|
// color_model: this.scheme
|
|
49
|
-
},
|
|
50
|
-
state: {
|
|
51
|
-
updatedfrom:"node-red",
|
|
52
|
-
updated: this.device.getTime()
|
|
53
49
|
}
|
|
54
50
|
};
|
|
55
51
|
if (!this.color_support && !this.temperature_k && this.color_scene.length<1){
|
|
@@ -65,31 +61,31 @@ module.exports = function(RED) {
|
|
|
65
61
|
capab.parameters.color_scene = {
|
|
66
62
|
scenes:scenes
|
|
67
63
|
};
|
|
68
|
-
capab.state.instance = 'scene';
|
|
69
|
-
capab.state.value = this.color_scene[0];
|
|
64
|
+
// capab.state.instance = 'scene';
|
|
65
|
+
// capab.state.value = this.color_scene[0];
|
|
70
66
|
};
|
|
71
67
|
if (this.color_support){
|
|
72
68
|
capab.parameters.color_model = this.scheme;
|
|
73
|
-
capab.state.instance = this.scheme;
|
|
74
|
-
if (this.scheme=="hsv"){
|
|
75
|
-
|
|
76
|
-
}else{
|
|
77
|
-
|
|
78
|
-
}
|
|
69
|
+
// capab.state.instance = this.scheme;
|
|
70
|
+
// if (this.scheme=="hsv"){
|
|
71
|
+
// capab.state.value = {h:0,s:0,v:0};
|
|
72
|
+
// }else{
|
|
73
|
+
// capab.state.value = 0;
|
|
74
|
+
// }
|
|
79
75
|
};
|
|
80
76
|
if (this.temperature_k){
|
|
81
77
|
capab.parameters.temperature_k = {
|
|
82
78
|
min: this.temperature_min,
|
|
83
79
|
max: this.temperature_max
|
|
84
80
|
};
|
|
85
|
-
capab.state.instance = 'temperature_k';
|
|
86
|
-
capab.state.value = this.temperature_min;
|
|
81
|
+
// capab.state.instance = 'temperature_k';
|
|
82
|
+
// capab.state.value = this.temperature_min;
|
|
87
83
|
};
|
|
88
84
|
|
|
89
85
|
this.device.setCapability(this.id,capab)
|
|
90
86
|
.then(res=>{
|
|
91
87
|
this.initState = true;
|
|
92
|
-
this.value = JSON.stringify(capab.state.value);
|
|
88
|
+
// this.value = JSON.stringify(capab.state.value);
|
|
93
89
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
94
90
|
})
|
|
95
91
|
.catch(err=>{
|
|
@@ -133,12 +129,13 @@ module.exports = function(RED) {
|
|
|
133
129
|
break;
|
|
134
130
|
}
|
|
135
131
|
this.send(outmsgs);
|
|
136
|
-
// возвращаем подтверждение в базу
|
|
137
|
-
let state
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
// возвращаем подтверждение в базу
|
|
133
|
+
let state= {
|
|
134
|
+
type:this.ctype,
|
|
135
|
+
state:{
|
|
136
|
+
instance: newstate.instance,
|
|
137
|
+
value: val
|
|
138
|
+
}
|
|
142
139
|
};
|
|
143
140
|
if (this.response){
|
|
144
141
|
this.device.updateCapabState(this.id,state)
|
|
@@ -155,10 +152,7 @@ module.exports = function(RED) {
|
|
|
155
152
|
|
|
156
153
|
this.on('input', (msg, send, done)=>{
|
|
157
154
|
let value = msg.payload;
|
|
158
|
-
let state = {
|
|
159
|
-
updatedfrom: "node-red",
|
|
160
|
-
updated: this.device.getTime()
|
|
161
|
-
};
|
|
155
|
+
let state = {};
|
|
162
156
|
switch (typeof value) {
|
|
163
157
|
case 'object':
|
|
164
158
|
if ((value.r>-1 && value.g>-1 && value.b>-1) || (value.h>-1 && value.s>-1 && value.v>-1)){
|
|
@@ -204,8 +198,11 @@ module.exports = function(RED) {
|
|
|
204
198
|
if (done) {done();}
|
|
205
199
|
return;
|
|
206
200
|
};
|
|
207
|
-
|
|
208
|
-
|
|
201
|
+
let upState= {
|
|
202
|
+
type:this.ctype,
|
|
203
|
+
state:state
|
|
204
|
+
};
|
|
205
|
+
this.device.updateCapabState(this.id,upState)
|
|
209
206
|
.then(ref=>{
|
|
210
207
|
this.value = JSON.stringify(value);
|
|
211
208
|
this.status({fill:"green",shape:"dot",text:JSON.stringify(msg.payload)});
|
package/nodes/alice-mode.js
CHANGED
|
@@ -38,17 +38,11 @@ module.exports = function(RED) {
|
|
|
38
38
|
parameters: {
|
|
39
39
|
instance: this.instance,
|
|
40
40
|
modes: cfgModes
|
|
41
|
-
},
|
|
42
|
-
state: {
|
|
43
|
-
value: this.modes[0],
|
|
44
|
-
updatedfrom:"node-red",
|
|
45
|
-
updated: this.device.getTime()
|
|
46
41
|
}
|
|
47
42
|
};
|
|
48
43
|
this.device.setCapability(this.id,capab)
|
|
49
44
|
.then(res=>{
|
|
50
45
|
this.initState = true;
|
|
51
|
-
this.value = capab.state.value;
|
|
52
46
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
53
47
|
})
|
|
54
48
|
.catch(err=>{
|
|
@@ -73,15 +67,17 @@ module.exports = function(RED) {
|
|
|
73
67
|
this.send({
|
|
74
68
|
payload: value
|
|
75
69
|
});
|
|
76
|
-
let state
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
let state= {
|
|
71
|
+
type:this.ctype,
|
|
72
|
+
state:{
|
|
73
|
+
instance: this.instance,
|
|
74
|
+
value: value
|
|
75
|
+
}
|
|
80
76
|
};
|
|
81
77
|
if (this.response){
|
|
82
78
|
this.device.updateCapabState(this.id,state)
|
|
83
79
|
.then (res=>{
|
|
84
|
-
this.value =
|
|
80
|
+
this.value = value;
|
|
85
81
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
86
82
|
})
|
|
87
83
|
.catch(err=>{
|
|
@@ -110,10 +106,12 @@ module.exports = function(RED) {
|
|
|
110
106
|
if (done) {done();}
|
|
111
107
|
return;
|
|
112
108
|
};
|
|
113
|
-
let state
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
let state= {
|
|
110
|
+
type:this.ctype,
|
|
111
|
+
state:{
|
|
112
|
+
instance: this.instance,
|
|
113
|
+
value: value
|
|
114
|
+
}
|
|
117
115
|
};
|
|
118
116
|
this.device.updateCapabState(this.id,state)
|
|
119
117
|
.then(ref=>{
|
package/nodes/alice-onoff.js
CHANGED
|
@@ -2,24 +2,26 @@ module.exports = function(RED) {
|
|
|
2
2
|
// ************** ON/OFF *******************
|
|
3
3
|
function AliceOnOff(config){
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const device = RED.nodes.getNode(config.device);
|
|
6
|
+
device.setMaxListeners(device.getMaxListeners() + 1); // увеличиваем лимит для event
|
|
7
|
+
const id =JSON.parse(JSON.stringify(this.id));
|
|
8
|
+
const name = config.name;
|
|
9
|
+
const ctype = 'devices.capabilities.on_off';
|
|
10
|
+
const instance = 'on';
|
|
11
|
+
let response = config.response;
|
|
12
|
+
let retrievable = config.retrievable;
|
|
13
|
+
let split = false;
|
|
14
|
+
let value;
|
|
15
|
+
let initState = false;
|
|
14
16
|
|
|
15
17
|
if (config.response === undefined){
|
|
16
|
-
|
|
18
|
+
response = true;
|
|
17
19
|
};
|
|
18
20
|
if (config.retrievable === undefined){
|
|
19
|
-
|
|
21
|
+
retrievable = true;
|
|
20
22
|
};
|
|
21
|
-
if (!
|
|
22
|
-
|
|
23
|
+
if (!retrievable){
|
|
24
|
+
split = true;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
@@ -27,23 +29,18 @@ function AliceOnOff(config){
|
|
|
27
29
|
this.init = ()=>{
|
|
28
30
|
this.debug("Starting capability initilization ...");
|
|
29
31
|
let capab = {
|
|
30
|
-
type:
|
|
31
|
-
retrievable:
|
|
32
|
+
type: ctype,
|
|
33
|
+
retrievable: retrievable,
|
|
32
34
|
parameters: {
|
|
33
|
-
instance:
|
|
34
|
-
split:
|
|
35
|
-
},
|
|
36
|
-
state: {
|
|
37
|
-
value: false,
|
|
38
|
-
updatedfrom:"node-red",
|
|
39
|
-
updated: this.device.getTime()
|
|
35
|
+
instance: instance,
|
|
36
|
+
split: split
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
|
-
|
|
39
|
+
|
|
40
|
+
device.setCapability(id,capab)
|
|
43
41
|
.then(res=>{
|
|
44
42
|
this.debug("Capability initilization - success!");
|
|
45
|
-
|
|
46
|
-
this.value = capab.state.value;
|
|
43
|
+
initState = true;
|
|
47
44
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
48
45
|
})
|
|
49
46
|
.catch(err=>{
|
|
@@ -53,30 +50,32 @@ function AliceOnOff(config){
|
|
|
53
50
|
};
|
|
54
51
|
|
|
55
52
|
// Проверяем сам девайс уже инициирован
|
|
56
|
-
if (
|
|
53
|
+
if (device.initState) this.init();
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
device.on("online",()=>{
|
|
59
56
|
this.init();
|
|
60
57
|
});
|
|
61
58
|
|
|
62
|
-
|
|
59
|
+
device.on("offline",()=>{
|
|
63
60
|
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
64
61
|
});
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
device.on(id,(val)=>{
|
|
67
64
|
this.send({
|
|
68
65
|
payload: val
|
|
69
66
|
});
|
|
70
|
-
let state
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
let state= {
|
|
68
|
+
type:ctype,
|
|
69
|
+
state:{
|
|
70
|
+
instance: instance,
|
|
71
|
+
value: val
|
|
72
|
+
}
|
|
74
73
|
};
|
|
75
|
-
if (
|
|
76
|
-
|
|
74
|
+
if (response){
|
|
75
|
+
device.updateCapabState(id,state)
|
|
77
76
|
.then (res=>{
|
|
78
|
-
|
|
79
|
-
this.status({fill:"green",shape:"dot",text:
|
|
77
|
+
value = val;
|
|
78
|
+
this.status({fill:"green",shape:"dot",text:val.toString()});
|
|
80
79
|
})
|
|
81
80
|
.catch(err=>{
|
|
82
81
|
this.error("Error on update capability state: " + err.message);
|
|
@@ -91,19 +90,21 @@ function AliceOnOff(config){
|
|
|
91
90
|
if (done) {done();}
|
|
92
91
|
return;
|
|
93
92
|
};
|
|
94
|
-
if (msg.payload ===
|
|
93
|
+
if (msg.payload === value){
|
|
95
94
|
this.debug("Value not changed. Cancel update");
|
|
96
95
|
if (done) {done();}
|
|
97
96
|
return;
|
|
98
97
|
};
|
|
99
|
-
let state
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
let state= {
|
|
99
|
+
type:ctype,
|
|
100
|
+
state:{
|
|
101
|
+
instance: instance,
|
|
102
|
+
value: msg.payload
|
|
103
|
+
}
|
|
103
104
|
};
|
|
104
|
-
|
|
105
|
+
device.updateCapabState(id,state)
|
|
105
106
|
.then(ref=>{
|
|
106
|
-
|
|
107
|
+
value = msg.payload;
|
|
107
108
|
this.status({fill:"green",shape:"dot",text:msg.payload.toString()});
|
|
108
109
|
if (done) {done();}
|
|
109
110
|
})
|
|
@@ -115,8 +116,9 @@ function AliceOnOff(config){
|
|
|
115
116
|
});
|
|
116
117
|
|
|
117
118
|
this.on('close', (removed, done)=>{
|
|
119
|
+
device.setMaxListeners(device.getMaxListeners() - 1);
|
|
118
120
|
if (removed) {
|
|
119
|
-
|
|
121
|
+
device.delCapability(id)
|
|
120
122
|
.then(res=>{
|
|
121
123
|
done()
|
|
122
124
|
})
|
|
@@ -124,9 +126,9 @@ function AliceOnOff(config){
|
|
|
124
126
|
this.error("Error on delete capability: " + err.message);
|
|
125
127
|
done();
|
|
126
128
|
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
};
|
|
130
|
+
done();
|
|
131
|
+
return;
|
|
130
132
|
});
|
|
131
133
|
}
|
|
132
134
|
RED.nodes.registerType("On_Off",AliceOnOff);
|
package/nodes/alice-range.js
CHANGED
|
@@ -3,6 +3,7 @@ module.exports = function(RED) {
|
|
|
3
3
|
function AliceRange(config){
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
5
|
this.device = RED.nodes.getNode(config.device);
|
|
6
|
+
this.device.setMaxListeners(this.device.getMaxListeners() + 1); // увеличиваем лимит для event
|
|
6
7
|
this.name = config.name;
|
|
7
8
|
this.ctype = 'devices.capabilities.range';
|
|
8
9
|
this.retrievable = config.retrievable;
|
|
@@ -26,7 +27,6 @@ module.exports = function(RED) {
|
|
|
26
27
|
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
27
28
|
|
|
28
29
|
this.init = ()=>{
|
|
29
|
-
this.ref = this.device.getRef(this.id);
|
|
30
30
|
let capab = {
|
|
31
31
|
type: this.ctype,
|
|
32
32
|
retrievable: this.retrievable,
|
|
@@ -39,11 +39,6 @@ module.exports = function(RED) {
|
|
|
39
39
|
max: this.max,
|
|
40
40
|
precision: this.precision
|
|
41
41
|
}
|
|
42
|
-
},
|
|
43
|
-
state: {
|
|
44
|
-
value: this.min,
|
|
45
|
-
updatedfrom:"node-red",
|
|
46
|
-
updated: this.device.getTime()
|
|
47
42
|
}
|
|
48
43
|
};
|
|
49
44
|
// если unit не пременим к параметру, то нужно удалить
|
|
@@ -54,7 +49,6 @@ module.exports = function(RED) {
|
|
|
54
49
|
this.device.setCapability(this.id,capab)
|
|
55
50
|
.then(res=>{
|
|
56
51
|
this.initState = true;
|
|
57
|
-
this.value = capab.state.value;
|
|
58
52
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
59
53
|
})
|
|
60
54
|
.catch(err=>{
|
|
@@ -85,13 +79,15 @@ module.exports = function(RED) {
|
|
|
85
79
|
this.send({
|
|
86
80
|
payload: value
|
|
87
81
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
let state= {
|
|
83
|
+
type:this.ctype,
|
|
84
|
+
state:{
|
|
85
|
+
instance: this.instance,
|
|
86
|
+
value: value
|
|
87
|
+
}
|
|
93
88
|
};
|
|
94
89
|
// если установлено требование немедленно отвечать, отвечаем
|
|
90
|
+
console.log(this.response);
|
|
95
91
|
if (this.response){
|
|
96
92
|
this.device.updateCapabState(this.id,state)
|
|
97
93
|
.then (res=>{
|
|
@@ -117,10 +113,12 @@ module.exports = function(RED) {
|
|
|
117
113
|
if (done) {done();}
|
|
118
114
|
return;
|
|
119
115
|
};
|
|
120
|
-
let state
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
let state= {
|
|
117
|
+
type:this.ctype,
|
|
118
|
+
state:{
|
|
119
|
+
instance: this.instance,
|
|
120
|
+
value: value
|
|
121
|
+
}
|
|
124
122
|
};
|
|
125
123
|
this.device.updateCapabState(this.id,state)
|
|
126
124
|
.then(ref=>{
|
|
@@ -135,7 +133,8 @@ module.exports = function(RED) {
|
|
|
135
133
|
})
|
|
136
134
|
});
|
|
137
135
|
|
|
138
|
-
this.on('close',
|
|
136
|
+
this.on('close', (removed, done)=>{
|
|
137
|
+
this.device.setMaxListeners(this.device.getMaxListeners() - 1); // уменьшаем лимит для event
|
|
139
138
|
if (removed) {
|
|
140
139
|
this.device.delCapability(this.id)
|
|
141
140
|
.then(res=>{
|
package/nodes/alice-sensor.js
CHANGED
|
@@ -3,6 +3,7 @@ module.exports = function(RED) {
|
|
|
3
3
|
function AliceSensor(config){
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
5
|
this.device = RED.nodes.getNode(config.device);
|
|
6
|
+
this.device.setMaxListeners(this.device.getMaxListeners() + 1); // увеличиваем лимит для event
|
|
6
7
|
this.name = config.name;
|
|
7
8
|
this.stype = config.stype;
|
|
8
9
|
this.reportable = true;
|
|
@@ -15,6 +16,7 @@ function AliceSensor(config){
|
|
|
15
16
|
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
16
17
|
|
|
17
18
|
this.init = ()=>{
|
|
19
|
+
this.debug("Starting sensor initilization ...");
|
|
18
20
|
let sensor = {
|
|
19
21
|
type: this.stype,
|
|
20
22
|
reportable: this.reportable,
|
|
@@ -22,20 +24,12 @@ function AliceSensor(config){
|
|
|
22
24
|
parameters: {
|
|
23
25
|
instance: this.instance,
|
|
24
26
|
unit: this.unit
|
|
25
|
-
},
|
|
26
|
-
state: {
|
|
27
|
-
value: 0,
|
|
28
|
-
updatedfrom:"node-red",
|
|
29
|
-
updated: this.device.getTime()
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
|
-
|
|
33
|
-
delete sensor.parameters.unit;
|
|
34
|
-
sensor.state.value=false;
|
|
35
|
-
}
|
|
36
|
-
this.value = sensor.state.value;
|
|
29
|
+
|
|
37
30
|
this.device.setSensor(this.id,sensor)
|
|
38
31
|
.then(res=>{
|
|
32
|
+
this.debug("Sensor initilization - success!");
|
|
39
33
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
40
34
|
this.initState = true;
|
|
41
35
|
})
|
|
@@ -57,11 +51,6 @@ function AliceSensor(config){
|
|
|
57
51
|
});
|
|
58
52
|
|
|
59
53
|
this.on('input', (msg, send, done)=>{
|
|
60
|
-
// if (this.stype =='devices.properties.bool' && typeof msg.payload != 'boolean'){
|
|
61
|
-
// this.error("Wrong type! msg.payload must be boolean.");
|
|
62
|
-
// if (done) {done();}
|
|
63
|
-
// return;
|
|
64
|
-
// };
|
|
65
54
|
if (this.stype =='devices.properties.float' && typeof msg.payload != 'number'){
|
|
66
55
|
this.error("Wrong type! msg.payload must be number.");
|
|
67
56
|
if (done) {done();}
|
|
@@ -77,11 +66,14 @@ function AliceSensor(config){
|
|
|
77
66
|
if (done) {done();}
|
|
78
67
|
return;
|
|
79
68
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
let state= {
|
|
70
|
+
type:this.stype,
|
|
71
|
+
state:{
|
|
72
|
+
instance: this.instance,
|
|
73
|
+
value: msg.payload
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
this.device.updateSensorState(this.id,state)
|
|
85
77
|
.then(ref=>{
|
|
86
78
|
this.value = msg.payload;
|
|
87
79
|
this.status({fill:"green",shape:"dot",text: msg.payload});
|
package/nodes/alice-togle.js
CHANGED
|
@@ -3,6 +3,7 @@ module.exports = function(RED) {
|
|
|
3
3
|
function AliceToggle(config){
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
5
|
this.device = RED.nodes.getNode(config.device);
|
|
6
|
+
this.device.setMaxListeners(this.device.getMaxListeners() + 1); // увеличиваем лимит для event
|
|
6
7
|
this.name = config.name;
|
|
7
8
|
this.ctype = 'devices.capabilities.toggle';
|
|
8
9
|
this.instance = config.instance;
|
|
@@ -17,24 +18,20 @@ module.exports = function(RED) {
|
|
|
17
18
|
this.status({fill:"red",shape:"dot",text:"offline"});
|
|
18
19
|
|
|
19
20
|
this.init = ()=>{
|
|
20
|
-
this.
|
|
21
|
+
this.debug("Starting capability initilization ...");
|
|
21
22
|
let capab = {
|
|
22
23
|
type: this.ctype,
|
|
23
24
|
retrievable: true,
|
|
24
25
|
reportable: true,
|
|
25
26
|
parameters: {
|
|
26
27
|
instance: this.instance,
|
|
27
|
-
},
|
|
28
|
-
state: {
|
|
29
|
-
value: false,
|
|
30
|
-
updatedfrom:"node-red",
|
|
31
|
-
updated: this.device.getTime()
|
|
32
28
|
}
|
|
33
29
|
};
|
|
34
30
|
this.device.setCapability(this.id,capab)
|
|
35
31
|
.then(res=>{
|
|
36
32
|
this.initState = true;
|
|
37
|
-
this.value = capab.state.value;
|
|
33
|
+
// this.value = capab.state.value;
|
|
34
|
+
this.debug("Capability initilization - success!");
|
|
38
35
|
this.status({fill:"green",shape:"dot",text:"online"});
|
|
39
36
|
})
|
|
40
37
|
.catch(err=>{
|
|
@@ -59,11 +56,13 @@ module.exports = function(RED) {
|
|
|
59
56
|
this.send({
|
|
60
57
|
payload: val
|
|
61
58
|
});
|
|
62
|
-
let state={
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
let state= {
|
|
60
|
+
type:this.ctype,
|
|
61
|
+
state:{
|
|
62
|
+
instance: this.instance,
|
|
63
|
+
value: val
|
|
64
|
+
}
|
|
65
|
+
};
|
|
67
66
|
if (this.response){
|
|
68
67
|
this.debug("Automatic confirmation is true, sending confirmation to Yandex ...");
|
|
69
68
|
this.device.updateCapabState(this.id,state)
|
|
@@ -89,10 +88,12 @@ module.exports = function(RED) {
|
|
|
89
88
|
if (done) {done();}
|
|
90
89
|
return;
|
|
91
90
|
};
|
|
92
|
-
let state
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
let state= {
|
|
92
|
+
type:this.ctype,
|
|
93
|
+
state:{
|
|
94
|
+
instance: this.instance,
|
|
95
|
+
value: msg.payload
|
|
96
|
+
}
|
|
96
97
|
};
|
|
97
98
|
this.device.updateCapabState(this.id,state)
|
|
98
99
|
.then(ref=>{
|