node-red-contrib-alice 1.1.3 → 1.1.4

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.
@@ -3,36 +3,36 @@ module.exports = function(RED) {
3
3
  // ************** Color *******************
4
4
  function AliceColor(config){
5
5
  RED.nodes.createNode(this,config);
6
- const device = RED.nodes.getNode(config.device);
7
- device.setMaxListeners(device.getMaxListeners() + 1); // увеличиваем лимит для event
8
- const name = config.name;
9
- const ctype = 'devices.capabilities.color_setting';
10
- const instance = 'color_model';
11
- let color_support = config.color_support;
12
- let scheme = config.scheme;
13
- const temperature_k = config.temperature_k;
14
- const temperature_min = parseInt(config.temperature_min);
15
- const temperature_max = parseInt(config.temperature_max);
16
- const color_scene = config.color_scene || [];
17
- let needConvert = false;
18
- let response = config.response;
19
- let initState = false;
20
- let curentValue;
6
+ this.device = RED.nodes.getNode(config.device);
7
+ this.device.setMaxListeners(this.device.getMaxListeners() + 1); // увеличиваем лимит для event
8
+ this.name = config.name;
9
+ this.ctype = 'devices.capabilities.color_setting';
10
+ this.instance = 'color_model';
11
+ this.color_support = config.color_support;
12
+ this.scheme = config.scheme;
13
+ this.temperature_k = config.temperature_k;
14
+ this.temperature_min = parseInt(config.temperature_min);
15
+ this.temperature_max = parseInt(config.temperature_max);
16
+ this.color_scene = config.color_scene || [];
17
+ this.needConvert = false;
18
+ this.response = config.response;
19
+ this.initState = false;
20
+ this.value;
21
21
 
22
- if (scheme == "rgb_normal"){
23
- scheme = "rgb";
24
- needConvert = true;
22
+ if (this.scheme == "rgb_normal"){
23
+ this.scheme = "rgb";
24
+ this.needConvert = true;
25
25
  };
26
26
  if (config.response === undefined){
27
- response = true;
27
+ this.response = true;
28
28
  };
29
29
  if (config.color_support === undefined){
30
- color_support = true
30
+ this.color_support = true
31
31
  };
32
32
 
33
- init = ()=>{
33
+ this.init = ()=>{
34
34
  var value = 0;
35
- if (scheme=="hsv"){
35
+ if (this.scheme=="hsv"){
36
36
  value = {
37
37
  h:0,
38
38
  s:0,
@@ -40,52 +40,52 @@ module.exports = function(RED) {
40
40
  };
41
41
  };
42
42
  let capab = {
43
- type: ctype,
43
+ type: this.ctype,
44
44
  retrievable: true,
45
45
  reportable: true,
46
46
  parameters: {
47
- // instance: scheme,//instance,
48
- // color_model: scheme
47
+ // instance: this.scheme,//this.instance,
48
+ // color_model: this.scheme
49
49
  }
50
50
  };
51
- if (!color_support && !temperature_k && color_scene.length<1){
51
+ if (!this.color_support && !this.temperature_k && this.color_scene.length<1){
52
52
  this.error("Error on create capability: " + "At least one parameter must be enabled");
53
53
  this.status({fill:"red",shape:"dot",text:"error"});
54
54
  return;
55
55
  };
56
- if (color_scene.length>0){
56
+ if (this.color_scene.length>0){
57
57
  let scenes = [];
58
- color_scene.forEach(s=>{
58
+ this.color_scene.forEach(s=>{
59
59
  scenes.push({id:s});
60
60
  });
61
61
  capab.parameters.color_scene = {
62
62
  scenes:scenes
63
63
  };
64
64
  // capab.state.instance = 'scene';
65
- // capab.state.value = color_scene[0];
65
+ // capab.state.value = this.color_scene[0];
66
66
  };
67
- if (color_support){
68
- capab.parameters.color_model = scheme;
69
- // capab.state.instance = scheme;
70
- // if (scheme=="hsv"){
67
+ if (this.color_support){
68
+ capab.parameters.color_model = this.scheme;
69
+ // capab.state.instance = this.scheme;
70
+ // if (this.scheme=="hsv"){
71
71
  // capab.state.value = {h:0,s:0,v:0};
72
72
  // }else{
73
73
  // capab.state.value = 0;
74
74
  // }
75
75
  };
76
- if (temperature_k){
76
+ if (this.temperature_k){
77
77
  capab.parameters.temperature_k = {
78
- min: temperature_min,
79
- max: temperature_max
78
+ min: this.temperature_min,
79
+ max: this.temperature_max
80
80
  };
81
81
  // capab.state.instance = 'temperature_k';
82
- // capab.state.value = temperature_min;
82
+ // capab.state.value = this.temperature_min;
83
83
  };
84
84
 
85
- device.setCapability(this.id,capab)
85
+ this.device.setCapability(this.id,capab)
86
86
  .then(res=>{
87
- initState = true;
88
- // curentValue = JSON.stringify(capab.state.value);
87
+ this.initState = true;
88
+ // this.value = JSON.stringify(capab.state.value);
89
89
  this.status({fill:"green",shape:"dot",text:"online"});
90
90
  })
91
91
  .catch(err=>{
@@ -95,21 +95,17 @@ module.exports = function(RED) {
95
95
  };
96
96
 
97
97
  // Проверяем сам девайс уже инициирован
98
- if (device.initState) init();
98
+ if (this.device.initState) this.init();
99
99
 
100
- device.on("online",()=>{
101
- if (initState){
102
- this.status({fill:"green",shape:"dot",text:JSON.stringify(curentValue)});
103
- }else{
104
- init();
105
- }
100
+ this.device.on("online",()=>{
101
+ this.init();
106
102
  });
107
103
 
108
- device.on("offline",()=>{
104
+ this.device.on("offline",()=>{
109
105
  this.status({fill:"red",shape:"dot",text:"offline"});
110
106
  });
111
107
 
112
- device.on(this.id,(val,newstate)=>{
108
+ this.device.on(this.id,(val,newstate)=>{
113
109
  // отправляем данные на выход
114
110
  let outmsgs=[null,null,null];
115
111
  switch (newstate.instance) {
@@ -135,16 +131,16 @@ module.exports = function(RED) {
135
131
  this.send(outmsgs);
136
132
  // возвращаем подтверждение в базу
137
133
  let state= {
138
- type:ctype,
134
+ type:this.ctype,
139
135
  state:{
140
136
  instance: newstate.instance,
141
137
  value: val
142
138
  }
143
139
  };
144
- if (response){
145
- device.updateCapabState(this.id,state)
140
+ if (this.response){
141
+ this.device.updateCapabState(this.id,state)
146
142
  .then (res=>{
147
- curentValue = JSON.stringify(val);
143
+ this.value = JSON.stringify(val);
148
144
  this.status({fill:"green",shape:"dot",text:"online"});
149
145
  })
150
146
  .catch(err=>{
@@ -160,11 +156,11 @@ module.exports = function(RED) {
160
156
  switch (typeof value) {
161
157
  case 'object':
162
158
  if ((value.r>-1 && value.g>-1 && value.b>-1) || (value.h>-1 && value.s>-1 && value.v>-1)){
163
- if (scheme == 'rgb'){
159
+ if (this.scheme == 'rgb'){
164
160
  value = value.r << 16 | value.g << 8 | value.b;
165
161
  };
166
162
  state.value = value;
167
- state.instance = scheme
163
+ state.instance = this.scheme
168
164
  }else{
169
165
  this.error("Wrong type! For Color, msg.payload must be RGB or HSV Object.");
170
166
  if (done) {done();}
@@ -172,7 +168,7 @@ module.exports = function(RED) {
172
168
  }
173
169
  break;
174
170
  case 'number':
175
- if (value>=temperature_min && value<=temperature_max){
171
+ if (value>=this.temperature_min && value<=this.temperature_max){
176
172
  state.value = value;
177
173
  state.instance = 'temperature_k';
178
174
  }else{
@@ -182,7 +178,7 @@ module.exports = function(RED) {
182
178
  }
183
179
  break;
184
180
  case 'string':
185
- if (color_scene.includes(value)){
181
+ if (this.color_scene.includes(value)){
186
182
  state.value = value;
187
183
  state.instance = 'scene';
188
184
  }else{
@@ -197,19 +193,19 @@ module.exports = function(RED) {
197
193
  return;
198
194
  }
199
195
 
200
- if (JSON.stringify(value) === curentValue){
196
+ if (JSON.stringify(value) === this.value){
201
197
  this.debug("Value not changed. Cancel update");
202
198
  if (done) {done();}
203
199
  return;
204
200
  };
205
201
  let upState= {
206
- type:ctype,
202
+ type:this.ctype,
207
203
  state:state
208
204
  };
209
- device.updateCapabState(this.id,upState)
205
+ this.device.updateCapabState(this.id,upState)
210
206
  .then(ref=>{
211
- curentValue = JSON.stringify(value);
212
- this.status({fill:"green",shape:"dot",text:JSON.stringify(curentValue)});
207
+ this.value = JSON.stringify(value);
208
+ this.status({fill:"green",shape:"dot",text:JSON.stringify(msg.payload)});
213
209
  if (done) {done();}
214
210
  })
215
211
  .catch(err=>{
@@ -221,7 +217,7 @@ module.exports = function(RED) {
221
217
 
222
218
  this.on('close', function(removed, done) {
223
219
  if (removed) {
224
- device.delCapability(this.id)
220
+ this.device.delCapability(this.id)
225
221
  .then(res=>{
226
222
  done()
227
223
  })
@@ -10,14 +10,14 @@ module.exports = function(RED) {
10
10
  this.response = config.response;
11
11
  this.instance = config.instance;
12
12
  this.modes = config.modes;
13
- let initState = false;
14
- let currentValue;
13
+ this.initState = false;
14
+ this.value;
15
15
 
16
16
  if (config.response === undefined){
17
17
  this.response = true;
18
18
  }
19
19
 
20
- init = _=>{
20
+ this.init = _=>{
21
21
  if (this.modes.length<1){
22
22
  this.status({fill:"red",shape:"dot",text:"error"});
23
23
  this.error("In the list of supported commands, there must be at least one command");
@@ -42,7 +42,7 @@ module.exports = function(RED) {
42
42
  };
43
43
  this.device.setCapability(this.id,capab)
44
44
  .then(res=>{
45
- initState = true;
45
+ this.initState = true;
46
46
  this.status({fill:"green",shape:"dot",text:"online"});
47
47
  })
48
48
  .catch(err=>{
@@ -52,14 +52,10 @@ module.exports = function(RED) {
52
52
  };
53
53
 
54
54
  // Проверяем сам девайс уже инициирован
55
- if (this.device.initState) init();
55
+ if (this.device.initState) this.init();
56
56
 
57
57
  this.device.on("online",()=>{
58
- if (initState){
59
- this.status({fill:"green",shape:"dot",text:currentValue});
60
- }else{
61
- init();
62
- }
58
+ this.init();
63
59
  });
64
60
 
65
61
  this.device.on("offline",()=>{
@@ -81,7 +77,7 @@ module.exports = function(RED) {
81
77
  if (this.response){
82
78
  this.device.updateCapabState(this.id,state)
83
79
  .then (res=>{
84
- currentValue = value;
80
+ this.value = value;
85
81
  this.status({fill:"green",shape:"dot",text:"online"});
86
82
  })
87
83
  .catch(err=>{
@@ -105,7 +101,7 @@ module.exports = function(RED) {
105
101
  if (done) {done();}
106
102
  return;
107
103
  };
108
- if (value === currentValue){
104
+ if (value === this.value){
109
105
  this.debug("Value not changed. Cancel update");
110
106
  if (done) {done();}
111
107
  return;
@@ -119,8 +115,8 @@ module.exports = function(RED) {
119
115
  };
120
116
  this.device.updateCapabState(this.id,state)
121
117
  .then(ref=>{
122
- currentValue = value;
123
- this.status({fill:"green",shape:"dot",text:currentValue});
118
+ this.value = value;
119
+ this.status({fill:"green",shape:"dot",text:value});
124
120
  if (done) {done();}
125
121
  })
126
122
  .catch(err=>{
@@ -67,11 +67,7 @@ function AliceOnOff(config){
67
67
  if (device.initState) this.init();
68
68
 
69
69
  device.on("online",()=>{
70
- if (initState){
71
- this.status({fill:"green",shape:"dot",text:curentState.state.value});
72
- }else{
73
- this.init();
74
- };
70
+ this.init();
75
71
  });
76
72
 
77
73
  device.on("offline",()=>{
@@ -14,8 +14,8 @@ module.exports = function(RED) {
14
14
  this.max = parseFloat(config.max);
15
15
  this.precision = parseFloat(config.precision);
16
16
  this.response = config.response;
17
- let initState = false;
18
- let currentState = null;
17
+ this.initState = false;
18
+ this.value = null;
19
19
 
20
20
  if (config.response === undefined){
21
21
  this.response = true;
@@ -48,7 +48,7 @@ module.exports = function(RED) {
48
48
 
49
49
  this.device.setCapability(this.id,capab)
50
50
  .then(res=>{
51
- initState = true;
51
+ this.initState = true;
52
52
  this.status({fill:"green",shape:"dot",text:"online"});
53
53
  })
54
54
  .catch(err=>{
@@ -61,11 +61,7 @@ module.exports = function(RED) {
61
61
  if (this.device.initState) this.init();
62
62
 
63
63
  this.device.on("online",()=>{
64
- if (initState){
65
- this.status({fill:"green",shape:"dot",text:currentState})
66
- }else{
67
- this.init();
68
- }
64
+ this.init();
69
65
  });
70
66
 
71
67
  this.device.on("offline",()=>{
@@ -76,7 +72,7 @@ module.exports = function(RED) {
76
72
  let value = val;
77
73
  //проверка является ли значение относительным и нужно ли отдавать полное значение
78
74
  if (fullstate.relative && this.retrievable){
79
- value = currentState + val;
75
+ value = this.value + val;
80
76
  if (val<0 && value<this.min) value=this.min;
81
77
  if (val>0 && value>this.max) value=this.max;
82
78
  };
@@ -95,7 +91,7 @@ module.exports = function(RED) {
95
91
  if (this.response){
96
92
  this.device.updateCapabState(this.id,state)
97
93
  .then (res=>{
98
- currentState = value;
94
+ this.value = value;
99
95
  this.status({fill:"green",shape:"dot",text:"online"});
100
96
  })
101
97
  .catch(err=>{
@@ -112,7 +108,7 @@ module.exports = function(RED) {
112
108
  if (done) {done();}
113
109
  return;
114
110
  }
115
- if (value === currentState){
111
+ if (value === this.value){
116
112
  this.debug("Value not changed. Cancel update");
117
113
  if (done) {done();}
118
114
  return;
@@ -126,7 +122,7 @@ module.exports = function(RED) {
126
122
  };
127
123
  this.device.updateCapabState(this.id,state)
128
124
  .then(ref=>{
129
- currentState = value;
125
+ this.value = value;
130
126
  this.status({fill:"green",shape:"dot",text:value});
131
127
  if (done) {done();}
132
128
  })
@@ -23,7 +23,7 @@ function AliceSensor(config){
23
23
 
24
24
  this.status({fill:"red",shape:"dot",text:"offline"});
25
25
 
26
- init = ()=>{
26
+ this.init = ()=>{
27
27
  this.debug("Starting sensor initilization ...");
28
28
  let sensor = {
29
29
  type: stype,
@@ -48,14 +48,10 @@ function AliceSensor(config){
48
48
  };
49
49
 
50
50
  // Проверяем сам девайс уже инициирован
51
- if (device.initState) init();
51
+ if (device.initState) this.init();
52
52
 
53
53
  device.on("online",()=>{
54
- if (initState){
55
- this.status({fill:"green",shape:"dot",text: curentState.state.value});
56
- }else{
57
- init();
58
- };
54
+ this.init();
59
55
  });
60
56
 
61
57
  device.on("offline",()=>{
@@ -8,8 +8,8 @@ module.exports = function(RED) {
8
8
  this.ctype = 'devices.capabilities.toggle';
9
9
  this.instance = config.instance;
10
10
  this.response = config.response;
11
- let initState = false;
12
- let currentState = false;
11
+ this.initState = false;
12
+ this.value = false;
13
13
 
14
14
  if (config.response === undefined){
15
15
  this.response = true;
@@ -29,8 +29,8 @@ module.exports = function(RED) {
29
29
  };
30
30
  this.device.setCapability(this.id,capab)
31
31
  .then(res=>{
32
- initState = true;
33
- // currentState = capab.state.value;
32
+ this.initState = true;
33
+ // this.value = capab.state.value;
34
34
  this.debug("Capability initilization - success!");
35
35
  this.status({fill:"green",shape:"dot",text:"online"});
36
36
  })
@@ -44,11 +44,7 @@ module.exports = function(RED) {
44
44
  if (this.device.initState) this.init();
45
45
 
46
46
  this.device.on("online",()=>{
47
- if (initState){
48
- this.status({fill:"green",shape:"dot",text:currentState});
49
- }else{
50
- this.init();
51
- }
47
+ this.init();
52
48
  });
53
49
 
54
50
  this.device.on("offline",()=>{
@@ -71,7 +67,7 @@ module.exports = function(RED) {
71
67
  this.debug("Automatic confirmation is true, sending confirmation to Yandex ...");
72
68
  this.device.updateCapabState(this.id,state)
73
69
  .then (res=>{
74
- currentState = val;
70
+ this.value = val;
75
71
  this.status({fill:"green",shape:"dot",text:val});
76
72
  })
77
73
  .catch(err=>{
@@ -87,7 +83,7 @@ module.exports = function(RED) {
87
83
  if (done) {done();}
88
84
  return;
89
85
  };
90
- if (msg.payload === currentState){
86
+ if (msg.payload === this.value){
91
87
  this.debug("Value not changed. Cancel update");
92
88
  if (done) {done();}
93
89
  return;
@@ -101,7 +97,7 @@ module.exports = function(RED) {
101
97
  };
102
98
  this.device.updateCapabState(this.id,state)
103
99
  .then(ref=>{
104
- currentState = msg.payload;
100
+ this.value = msg.payload;
105
101
  this.status({fill:"green",shape:"dot",text:msg.payload.toString()});
106
102
  if (done) {done();}
107
103
  })
@@ -67,11 +67,7 @@ function AliceVideo(config){
67
67
  if (device.initState) this.init();
68
68
 
69
69
  device.on("online",()=>{
70
- if (initState){
71
-
72
- }else{
73
- this.init();
74
- }
70
+ this.init();
75
71
  });
76
72
 
77
73
  device.on("offline",()=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-alice",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "main": "alice.js",
6
6
  "scripts": {