node-red-contrib-alice 2.1.2 → 2.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.
- package/nodes/alice-color.js +1 -0
- package/nodes/alice-device.js +59 -30
- package/package.json +2 -2
package/nodes/alice-color.js
CHANGED
package/nodes/alice-device.js
CHANGED
|
@@ -42,42 +42,67 @@ module.exports = function(RED) {
|
|
|
42
42
|
this.initState = true;
|
|
43
43
|
};
|
|
44
44
|
// функция обновления информации об устройстве
|
|
45
|
-
this._updateDeviceInfo=
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
this._updateDeviceInfo= _=>{
|
|
46
|
+
let now = false;
|
|
47
|
+
|
|
48
|
+
if (deviceconfig.capabilities.length==0 && deviceconfig.properties.length==0){
|
|
49
|
+
this.debug("DELETE Device config from gateway ...");
|
|
50
|
+
/// отправка по http
|
|
51
|
+
const option = {
|
|
52
|
+
timeout: 5000,
|
|
53
|
+
method: 'POST',
|
|
54
|
+
url: 'https://api.nodered-home.ru/gtw/device/config',
|
|
55
|
+
headers: {
|
|
56
|
+
'content-type': 'application/json',
|
|
57
|
+
'Authorization': "Bearer "+service.getToken()
|
|
58
|
+
},
|
|
59
|
+
data: {
|
|
60
|
+
id: this.id,
|
|
61
|
+
config: deviceconfig
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
axios.request(option)
|
|
65
|
+
.then(res=>{
|
|
66
|
+
this.trace("Device config deleted on gateway successfully");
|
|
67
|
+
})
|
|
68
|
+
.catch(error=>{
|
|
69
|
+
this.debug("Error when delete device config on gateway: "+error.message);
|
|
70
|
+
});
|
|
55
71
|
return;
|
|
56
72
|
};
|
|
73
|
+
|
|
57
74
|
if (!updating){
|
|
58
75
|
updating = true;
|
|
59
76
|
setTimeout(() => {
|
|
60
|
-
this.debug("Updating Device
|
|
77
|
+
this.debug("Updating Device config ...");
|
|
61
78
|
updating = false;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
const option = {
|
|
80
|
+
timeout: 5000,
|
|
81
|
+
method: 'POST',
|
|
82
|
+
url: 'https://api.nodered-home.ru/gtw/device/config',
|
|
83
|
+
headers: {
|
|
84
|
+
'content-type': 'application/json',
|
|
85
|
+
'Authorization': "Bearer "+service.getToken()
|
|
86
|
+
},
|
|
87
|
+
data: {
|
|
88
|
+
id: this.id,
|
|
89
|
+
config: deviceconfig
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
axios.request(option)
|
|
93
|
+
.then(res=>{
|
|
94
|
+
this.trace("Device config updated successfully");
|
|
95
|
+
})
|
|
96
|
+
.catch(error=>{
|
|
97
|
+
this.debug("Error when update device config: "+error.message);
|
|
98
|
+
});
|
|
99
|
+
}, 1000);
|
|
66
100
|
}
|
|
67
101
|
};
|
|
68
102
|
// функция обновления состояния устройства (умений и сенсоров)
|
|
69
103
|
this._updateDeviceState= (event=null)=>{
|
|
70
|
-
// if (states === null || (states.capabilities.length==0 && states.properties.length==0)){
|
|
71
|
-
// data = '';
|
|
72
|
-
// }else{
|
|
73
|
-
// data = JSON.stringify(states);
|
|
74
|
-
// };
|
|
75
|
-
// service.send2gate('$me/device/state/'+this.id+'/states', data ,true);
|
|
76
|
-
if (states === null){
|
|
77
|
-
return;
|
|
78
|
-
};
|
|
79
104
|
const option = {
|
|
80
|
-
timeout:
|
|
105
|
+
timeout: 5000,
|
|
81
106
|
method: 'POST',
|
|
82
107
|
url: 'https://api.nodered-home.ru/gtw/device/state',
|
|
83
108
|
headers: {
|
|
@@ -85,6 +110,7 @@ module.exports = function(RED) {
|
|
|
85
110
|
'Authorization': "Bearer "+service.getToken()
|
|
86
111
|
},
|
|
87
112
|
data: {
|
|
113
|
+
id: this.id,
|
|
88
114
|
event: event,
|
|
89
115
|
state: states
|
|
90
116
|
}
|
|
@@ -94,7 +120,7 @@ module.exports = function(RED) {
|
|
|
94
120
|
this.trace("Device state updated successfully");
|
|
95
121
|
})
|
|
96
122
|
.catch(error=>{
|
|
97
|
-
this.
|
|
123
|
+
this.debug("Error when update device state: "+error.message);
|
|
98
124
|
})
|
|
99
125
|
};
|
|
100
126
|
// отправка эвентов
|
|
@@ -221,6 +247,7 @@ module.exports = function(RED) {
|
|
|
221
247
|
if (stateindex>-1){
|
|
222
248
|
states.properties.splice(stateindex, 1);
|
|
223
249
|
};
|
|
250
|
+
this._updateDeviceState();
|
|
224
251
|
resolve(true);
|
|
225
252
|
})
|
|
226
253
|
};
|
|
@@ -256,15 +283,17 @@ module.exports = function(RED) {
|
|
|
256
283
|
this.on('close', (removed, done)=>{
|
|
257
284
|
this.emit('offline');
|
|
258
285
|
if (removed){
|
|
259
|
-
deviceconfig =
|
|
260
|
-
|
|
286
|
+
deviceconfig.capabilities = [];
|
|
287
|
+
deviceconfig.properties = [];
|
|
288
|
+
states.capabilities = [];
|
|
289
|
+
states.properties = [];
|
|
261
290
|
this._updateDeviceState();
|
|
262
|
-
this._updateDeviceInfo(
|
|
291
|
+
this._updateDeviceInfo();
|
|
263
292
|
};
|
|
264
293
|
setTimeout(()=>{
|
|
265
294
|
// this.emit('offline');
|
|
266
295
|
done();
|
|
267
|
-
},
|
|
296
|
+
},500)
|
|
268
297
|
});
|
|
269
298
|
};
|
|
270
299
|
RED.nodes.registerType("alice-device",AliceDevice);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-alice",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "alice.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "git+https://github.com/efa2000/node-red-contrib-alice.git"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=14.0.0"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"node-red",
|