node-red-contrib-alice 2.1.3 → 2.1.5

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.
@@ -168,6 +168,7 @@ module.exports = function(RED) {
168
168
  }
169
169
  break;
170
170
  case 'number':
171
+ value = Math.round(value);
171
172
  if (value>=this.temperature_min && value<=this.temperature_max){
172
173
  state.value = value;
173
174
  state.instance = 'temperature_k';
@@ -1,6 +1,5 @@
1
1
  const axios = require('axios');
2
2
 
3
-
4
3
  module.exports = function(RED) {
5
4
  // ***************************** Alice DEVICE ****************************
6
5
  function AliceDevice(config){
@@ -42,37 +41,65 @@ module.exports = function(RED) {
42
41
  this.initState = true;
43
42
  };
44
43
  // функция обновления информации об устройстве
45
- this._updateDeviceInfo= (now)=>{
46
- let data;
47
- if (deviceconfig === null || (deviceconfig.capabilities.length==0 && deviceconfig.properties.length==0)){
48
- data = '';
49
- }else{
50
- data = JSON.stringify(deviceconfig);
51
- };
52
- if (now){
53
- this.debug("Updating Device info ...");
54
- service.send2gate('$me/device/state/'+this.id, data ,true);
44
+ this._updateDeviceInfo= _=>{
45
+ let now = false;
46
+
47
+ if (deviceconfig.capabilities.length==0 && deviceconfig.properties.length==0){
48
+ this.debug("DELETE Device config from gateway ...");
49
+ /// отправка по http
50
+ const option = {
51
+ timeout: 5000,
52
+ method: 'POST',
53
+ url: 'https://api.nodered-home.ru/gtw/device/config',
54
+ headers: {
55
+ 'content-type': 'application/json',
56
+ 'Authorization': "Bearer "+service.getToken()
57
+ },
58
+ data: {
59
+ id: this.id,
60
+ config: deviceconfig
61
+ }
62
+ };
63
+ axios.request(option)
64
+ .then(res=>{
65
+ this.trace("Device config deleted on gateway successfully");
66
+ })
67
+ .catch(error=>{
68
+ this.debug("Error when delete device config on gateway: "+error.message);
69
+ });
55
70
  return;
56
71
  };
72
+
57
73
  if (!updating){
58
74
  updating = true;
59
75
  setTimeout(() => {
60
- this.debug("Updating Device info ...");
76
+ this.debug("Updating Device config ...");
61
77
  updating = false;
62
- let nData = JSON.stringify(deviceconfig);
63
- if (deviceconfig === null){ nData = ''};
64
- service.send2gate('$me/device/state/'+this.id, nData ,true);
65
- }, 300);
78
+ const option = {
79
+ timeout: 5000,
80
+ method: 'POST',
81
+ url: 'https://api.nodered-home.ru/gtw/device/config',
82
+ headers: {
83
+ 'content-type': 'application/json',
84
+ 'Authorization': "Bearer "+service.getToken()
85
+ },
86
+ data: {
87
+ id: this.id,
88
+ config: deviceconfig
89
+ }
90
+ };
91
+ axios.request(option)
92
+ .then(res=>{
93
+ this.trace("Device config updated successfully");
94
+ })
95
+ .catch(error=>{
96
+ this.debug("Error when update device config: "+error.message);
97
+ });
98
+ }, 1000);
66
99
  }
67
100
  };
68
101
  // функция обновления состояния устройства (умений и сенсоров)
69
102
  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
103
  const option = {
77
104
  timeout: 5000,
78
105
  method: 'POST',
@@ -82,6 +109,7 @@ module.exports = function(RED) {
82
109
  'Authorization': "Bearer "+service.getToken()
83
110
  },
84
111
  data: {
112
+ id: this.id,
85
113
  event: event,
86
114
  state: states
87
115
  }
@@ -254,16 +282,17 @@ module.exports = function(RED) {
254
282
  this.on('close', (removed, done)=>{
255
283
  this.emit('offline');
256
284
  if (removed){
257
- deviceconfig = null;
285
+ deviceconfig.capabilities = [];
286
+ deviceconfig.properties = [];
258
287
  states.capabilities = [];
259
288
  states.properties = [];
260
289
  this._updateDeviceState();
261
- this._updateDeviceInfo(true);
290
+ this._updateDeviceInfo();
262
291
  };
263
292
  setTimeout(()=>{
264
293
  // this.emit('offline');
265
294
  done();
266
- },300)
295
+ },500)
267
296
  });
268
297
  };
269
298
  RED.nodes.registerType("alice-device",AliceDevice);
package/nodes/alice.html CHANGED
@@ -56,6 +56,7 @@
56
56
  });
57
57
  };
58
58
  function GetToken(code){
59
+ console.log(this.id);
59
60
  RED.notify("Request has been sent. Please, wait",{type:"compact"});
60
61
  $('#verification_code').prop('disabled', true);
61
62
  $('#submit_button').prop('disabled', true);
@@ -84,8 +85,19 @@
84
85
  $('#submit_button').prop('disabled', false);
85
86
  });
86
87
  }
87
- function ClearDataOnGateway(jToken) {
88
-
88
+ function ClearDevicesConfigOnGateway(email) {
89
+ RED.notify("Request has been sent. Please, wait",{type:"compact"});
90
+ const suburl = btoa(email);
91
+ $.ajax({
92
+ url: "/noderedhome/"+suburl+"/clearalldevice",
93
+ type:"GET"
94
+ })
95
+ .done(result=>{
96
+ RED.notify("All configs have been successfully cleared", {type:"success"});
97
+ })
98
+ .fail(error=>{
99
+ RED.notify("Error when deleting configs on the gateway", {type:"error"});
100
+ })
89
101
  };
90
102
  function pay(id, email) {
91
103
  console.log("Start pay");
@@ -203,11 +215,6 @@
203
215
  <span> - By purchasing a subscription, you agree to the terms of the <a href="https://nodered-home.ru/public_offer.pdf" target="_blank">public offer</a></span><br>
204
216
  <span> - View and manage your subscriptions <a href="https://my.cloudpayments.ru/ru/unsubscribe" target="_blank">here</a></span>
205
217
  <div style="text-align: end">
206
- <!-- <label for="node-input-subList" style="text-align: start">Period:</label>
207
- <select id="node-input-subList" style="width:70%; margin-top:10px; margin-bottom:10px;">
208
- <option value=1>1 month - 199 rubles</option>
209
- <option value=12>12 month - 2 300 rubles</option>
210
- </select> -->
211
218
  <button id="subscribe-button"
212
219
  onclick="pay($('#node-config-input-id').val(), $('#node-config-input-email').val())"
213
220
  class="ui-button">Buy a subscription
@@ -217,21 +224,18 @@
217
224
  </div>
218
225
  </div>
219
226
  <hr>
220
- <div name="Clearing" style="display: none;">
221
- <div class="form-row"><b>Сlear all data on the gateway</b></div>
222
- <div class="form-row">
223
- <p>1. Click the clear button</p>
224
- <p>2. Wait for the success message</p>
225
- <p>3. Сlose the window and do a full deploy</p>
226
- <button
227
- style="margin-left: 150px; margin-top: 10px;"
228
- onclick="ClearDataOnGateway($('#node-config-input-token').val())"
229
- class="ui-button">
230
- Сlear data on the gateway
231
- </button>
232
- </div>
227
+ <div name="Clearing">
228
+ <div class="form-row"><b>Сlear all data and configs on the gateway</b></div>
233
229
  <div class="form-tips" id="node-tip">
234
- <span>Tip: Сlear all data on the gateway may take up to 15 seconds, please wait for success or error message.</span>
230
+ <span>Tip: Сlear all data on the gateway may take up to 15 seconds, please wait for success or error message. When finished, make a full deployment to update the settings on the gateway.</span>
231
+ <div style="text-align: end">
232
+ <button
233
+ style="margin-left: 150px; margin-top: 10px;"
234
+ onclick="ClearDevicesConfigOnGateway($('#node-config-input-email').val())"
235
+ class="ui-button">
236
+ Сlear data on the gateway
237
+ </button>
238
+ </div>
235
239
  </div>
236
240
  </div>
237
241
  </script>
package/nodes/alice.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const mqtt = require('mqtt');
2
+ const axios = require('axios');
2
3
 
3
4
  module.exports = function(RED) {
4
5
  //Sevice node, Alice-Service (credential)
@@ -11,6 +12,29 @@ module.exports = function(RED) {
11
12
  const password = this.credentials.password;
12
13
  const token = this.credentials.token;
13
14
 
15
+ const suburl = Buffer.from(email).toString('base64');
16
+ RED.httpAdmin.get("/noderedhome/"+suburl+"/clearalldevice",(req,res)=>{
17
+ const option = {
18
+ method: 'POST',
19
+ url: 'https://api.nodered-home.ru/gtw/device/clearallconfigs',
20
+ headers: {
21
+ 'content-type': 'application/json',
22
+ 'Authorization': "Bearer "+this.getToken()
23
+ },
24
+ data: {}
25
+ };
26
+ axios.request(option)
27
+ .then(result=>{
28
+ this.trace("All devices configs deleted on gateway successfully");
29
+ // console.log(result)
30
+ res.sendStatus(200);
31
+ })
32
+ .catch(error=>{
33
+ this.debug("Error when delete All devices configs deleted on gateway: "+error.message);
34
+ res.sendStatus(500);
35
+ });
36
+ });
37
+
14
38
  this.isOnline = false;
15
39
  if (!token){
16
40
  this.error("Authentication is required!!!");
@@ -97,3 +121,5 @@ module.exports = function(RED) {
97
121
  });
98
122
  };
99
123
 
124
+
125
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-alice",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "",
5
5
  "main": "alice.js",
6
6
  "scripts": {