iobroker.device-watcher 2.0.1 → 2.0.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/main.js CHANGED
@@ -16,7 +16,6 @@ const enableSendSentry = true;
16
16
  let isUnloaded = false;
17
17
 
18
18
  class DeviceWatcher extends utils.Adapter {
19
-
20
19
  constructor(options) {
21
20
  super({
22
21
  ...options,
@@ -30,12 +29,21 @@ class DeviceWatcher extends utils.Adapter {
30
29
  this.batteryPowered = [];
31
30
  this.batteryLowPowered = [];
32
31
  this.listAllDevices = [];
33
- this.listAllDevicesRaw = [];
34
32
  this.blacklistLists = [];
35
33
  this.blacklistNotify = [];
36
34
  this.arrDev = [];
37
35
  this.adapterSelected = [];
38
36
 
37
+ // raw arrays
38
+ this.listAllDevicesRaw = [];
39
+ this.batteryLowPoweredRaw = [];
40
+ this.offlineDevicesRaw = [];
41
+
42
+ // raw counts
43
+ this.offlineDevicesCountRaw = 0;
44
+ this.offlineDevicesCountRawOld = 0;
45
+ this.lowBatteryPoweredCountRaw = 0;
46
+
39
47
  // counts
40
48
  this.offlineDevicesCount = 0;
41
49
  this.deviceCounter = 0;
@@ -51,9 +59,11 @@ class DeviceWatcher extends utils.Adapter {
51
59
  // this.on('objectChange', this.onObjectChange.bind(this));
52
60
  this.on('message', this.onMessage.bind(this));
53
61
  this.on('unload', this.onUnload.bind(this));
54
-
55
62
  }
56
63
 
64
+ /**
65
+ * onReady
66
+ */
57
67
  async onReady() {
58
68
  this.log.debug(`Adapter ${adapterName} was started`);
59
69
 
@@ -71,7 +81,7 @@ class DeviceWatcher extends utils.Adapter {
71
81
  fritzdect: this.config.fritzdectDevices,
72
82
  ham: this.config.hamDevices,
73
83
  harmony: this.config.harmonyDevices,
74
- hmiP : this.config.hmiPDevices,
84
+ hmiP: this.config.hmiPDevices,
75
85
  hmrpc: this.config.hmrpcDevices,
76
86
  hs100: this.config.hs100Devices,
77
87
  hue: this.config.hueDevices,
@@ -111,7 +121,7 @@ class DeviceWatcher extends utils.Adapter {
111
121
  fritzdect: this.config.fritzdectMaxMinutes,
112
122
  ham: this.config.hamMaxMinutes,
113
123
  harmony: this.config.harmonyMaxMinutes,
114
- hmiP : this.config.hmiPMaxMinutes,
124
+ hmiP: this.config.hmiPMaxMinutes,
115
125
  hmrpc: this.config.hmrpcMaxMinutes,
116
126
  hs100: this.config.hs100MaxMinutes,
117
127
  hue: this.config.hueMaxMinutes,
@@ -158,7 +168,7 @@ class DeviceWatcher extends utils.Adapter {
158
168
  // show list in debug log
159
169
  this.log.debug(JSON.stringify(this.arrDev));
160
170
 
161
- this.log.info(`Number of selected adapters: ${this.adapterSelected.length}. Loading data from: ${(this.adapterSelected).join(', ')} ...`);
171
+ this.log.info(`Number of selected adapters: ${this.adapterSelected.length}. Loading data from: ${this.adapterSelected.join(', ')} ...`);
162
172
  } else {
163
173
  this.log.warn(`No adapter selected. Please check the instance configuration!`);
164
174
  return; // cancel run if no adapter is selected
@@ -175,8 +185,7 @@ class DeviceWatcher extends utils.Adapter {
175
185
  try {
176
186
  for (const [id] of Object.entries(arrApart)) {
177
187
  if (!isUnloaded) {
178
- if ((this.supAdapter !== undefined) && (this.supAdapter[id])) {
179
-
188
+ if (this.supAdapter !== undefined && this.supAdapter[id]) {
180
189
  if (this.config.createOwnFolder) {
181
190
  await this.createDPsForEachAdapter(id);
182
191
  if (this.config.createHtmlList) await this.createHtmlListDatapoints(id);
@@ -202,7 +211,6 @@ class DeviceWatcher extends utils.Adapter {
202
211
 
203
212
  // send overview of offline devices
204
213
  if (this.config.checkSendOfflineMsgDaily) await this.sendOfflineNotificationsShedule();
205
-
206
214
  } catch (error) {
207
215
  this.errorReporting('[onReady]', error);
208
216
  this.terminate ? this.terminate(15) : process.exit(15);
@@ -210,10 +218,10 @@ class DeviceWatcher extends utils.Adapter {
210
218
  } // <-- onReady end
211
219
 
212
220
  /**
213
- * Is called if a subscribed state changes
214
- * @param {string} id
215
- * @param {ioBroker.State | null | undefined} state
216
- */
221
+ * Is called if a subscribed state changes
222
+ * @param {string} id
223
+ * @param {ioBroker.State | null | undefined} state
224
+ */
217
225
  onStateChange(id, state) {
218
226
  if (state) {
219
227
  // The state was changed
@@ -225,8 +233,8 @@ class DeviceWatcher extends utils.Adapter {
225
233
  }
226
234
 
227
235
  /**
228
- * @param {ioBroker.Message} obj
229
- */
236
+ * @param {ioBroker.Message} obj
237
+ */
230
238
  onMessage(obj) {
231
239
  const devices = [];
232
240
  let myCount = 0;
@@ -234,28 +242,33 @@ class DeviceWatcher extends utils.Adapter {
234
242
 
235
243
  switch (obj.command) {
236
244
  case 'devicesList':
237
- if(obj.message){
238
- try{
245
+ if (obj.message) {
246
+ try {
239
247
  result = this.listAllDevicesRaw;
240
- for(const element in result){
248
+ for (const element in result) {
241
249
  const label = 'Device: ' + result[element].Device + ' - Adapter: ' + result[element].Adapter;
242
- const myValueObject = {deviceName: result[element].Device, adapter: result[element].Adapter, path: result[element].Path};
243
- devices[myCount] = {label: label,value: JSON.stringify(myValueObject)};
244
- myCount ++;
250
+ const myValueObject = {
251
+ deviceName: result[element].Device,
252
+ adapter: result[element].Adapter,
253
+ path: result[element].Path,
254
+ };
255
+ devices[myCount] = { label: label, value: JSON.stringify(myValueObject) };
256
+ myCount++;
245
257
  }
246
258
  this.sendTo(obj.from, obj.command, devices, obj.callback);
247
- }
248
- catch(error){
259
+ } catch (error) {
249
260
  this.sendTo(obj.from, obj.command, obj.callback);
250
261
  }
251
- }
252
- else{
262
+ } else {
253
263
  this.sendTo(obj.from, obj.command, obj.callback);
254
264
  }
255
265
  break;
256
266
  }
257
267
  }
258
268
 
269
+ /**
270
+ * refresh data with interval
271
+ */
259
272
  async refreshData() {
260
273
  const nextTimeout = this.config.updateinterval * 1000;
261
274
 
@@ -276,9 +289,11 @@ class DeviceWatcher extends utils.Adapter {
276
289
  } else {
277
290
  return; // cancel run if unloaded was called.
278
291
  }
279
-
280
292
  } // <-- refreshData end
281
293
 
294
+ /**
295
+ * main function
296
+ */
282
297
  async main() {
283
298
  this.log.debug(`Function started: ${this.main.name}`);
284
299
 
@@ -286,7 +301,7 @@ class DeviceWatcher extends utils.Adapter {
286
301
  try {
287
302
  for (const [id] of Object.entries(arrApart)) {
288
303
  if (!isUnloaded) {
289
- if ((this.supAdapter !== undefined) && (this.supAdapter[id])) {
304
+ if (this.supAdapter !== undefined && this.supAdapter[id]) {
290
305
  if (this.config.createOwnFolder) {
291
306
  await this.createDataForEachAdapter(id);
292
307
  this.log.debug(`Created and filled data for ${await this.capitalize(id)}`);
@@ -312,13 +327,12 @@ class DeviceWatcher extends utils.Adapter {
312
327
  this.log.debug(`Function finished: ${this.main.name}`);
313
328
  } //<--End of main function
314
329
 
315
-
316
330
  /**
317
- * @param {string} sentence - Word which should be capitalize
331
+ * @param {string} id - id which should be capitalize
318
332
  */
319
- async capitalize(sentence) {
333
+ capitalize(id) {
320
334
  //make the first letter uppercase
321
- return sentence && sentence[0].toUpperCase() + sentence.slice(1);
335
+ return id && id[0].toUpperCase() + id.slice(1);
322
336
  }
323
337
 
324
338
  /**
@@ -326,7 +340,7 @@ class DeviceWatcher extends utils.Adapter {
326
340
  */
327
341
  async getTimestamp(dpValue) {
328
342
  const time = new Date();
329
- return dpValue = Math.round((time.getTime() - dpValue) / 1000 / 60);
343
+ return (dpValue = Math.round((time.getTime() - dpValue) / 1000 / 60));
330
344
  }
331
345
 
332
346
  /**
@@ -347,6 +361,19 @@ class DeviceWatcher extends utils.Adapter {
347
361
  if (stateVal) return stateVal.val;
348
362
  }
349
363
 
364
+ /**
365
+ * @param {object} data - object
366
+ */
367
+ async parseData(data) {
368
+ if (!data) return {};
369
+ if (typeof data === 'object') return data;
370
+ if (typeof data === 'string') return JSON.parse(data);
371
+ return {};
372
+ }
373
+
374
+ /**
375
+ * create blacklist
376
+ */
350
377
  async createBlacklist() {
351
378
  this.log.debug(`Function started: ${this.createBlacklist.name}`);
352
379
 
@@ -354,14 +381,18 @@ class DeviceWatcher extends utils.Adapter {
354
381
  const myBlacklist = this.config.tableBlacklist;
355
382
 
356
383
  for (const i in myBlacklist) {
357
- const blacklistParse = JSON.parse(myBlacklist[i].devices);
358
- // push devices in list to ignor device in lists
359
- if (myBlacklist[i].checkIgnorLists) {
360
- this.blacklistLists.push(blacklistParse.path);
361
- }
362
- // push devices in list to ignor device in notifications
363
- if (myBlacklist[i].checkIgnorNotify) {
364
- this.blacklistNotify.push(blacklistParse.deviceName);
384
+ try {
385
+ const blacklistParse = await this.parseData(myBlacklist[i].devices);
386
+ // push devices in list to ignor device in lists
387
+ if (myBlacklist[i].checkIgnorLists) {
388
+ this.blacklistLists.push(blacklistParse.path);
389
+ }
390
+ // push devices in list to ignor device in notifications
391
+ if (myBlacklist[i].checkIgnorNotify) {
392
+ this.blacklistNotify.push(blacklistParse.path);
393
+ }
394
+ } catch (error) {
395
+ this.errorReporting('[createBlacklist]', error);
365
396
  }
366
397
  }
367
398
 
@@ -379,71 +410,87 @@ class DeviceWatcher extends utils.Adapter {
379
410
  * @param {object} i - each Device
380
411
  */
381
412
  async getDeviceName(id, i) {
382
- const currDeviceString = id.slice(0, (id.lastIndexOf('.') + 1) - 1);
383
- const shortCurrDeviceString = currDeviceString.slice(0, (currDeviceString.lastIndexOf('.') + 1) - 1);
384
- const shortshortCurrDeviceString = shortCurrDeviceString.slice(0, (shortCurrDeviceString.lastIndexOf('.') + 1) - 1);
385
-
386
- // Get device name
387
- const deviceObject = await this.getForeignObjectAsync(currDeviceString);
388
- const shortDeviceObject = await this.getForeignObjectAsync(shortCurrDeviceString);
389
- const shortshortDeviceObject = await this.getForeignObjectAsync(shortshortCurrDeviceString);
390
- let deviceName;
391
-
392
- // Get ID with currDeviceString from datapoint
393
- switch (this.arrDev[i].adapter) {
394
- // Get ID for Switchbot and ESPHome Devices
395
- case 'switchbotBle':
396
- case 'esphome':
397
- deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
398
- break;
399
-
400
- // Get ID with short currDeviceString from objectjson
401
- case 'hue-extended':
402
- case 'hmrpc':
403
- case 'nuki-extended':
404
- case 'wled':
405
- if (shortDeviceObject && typeof shortDeviceObject === 'object') {
406
- deviceName = shortDeviceObject.common.name;
407
- }
408
- break;
409
-
410
- // Get ID with short short currDeviceString from objectjson (HMiP Devices)
411
- case 'hmiP':
412
- if (shortshortDeviceObject && typeof shortshortDeviceObject === 'object') {
413
- deviceName = shortshortDeviceObject.common.name;
414
- }
415
- break;
416
-
417
- // Get ID with short currDeviceString from datapoint
418
- case 'mihomeVacuum':
419
- case 'roomba':
420
- deviceName = await this.getInitValue(shortCurrDeviceString + this.arrDev[i].id);
421
- break;
422
-
423
- //Get ID of foldername
424
- case 'tado':
425
- deviceName = currDeviceString.slice(currDeviceString.lastIndexOf('.') + 1);
426
- break;
413
+ const currDeviceString = id.slice(0, id.lastIndexOf('.') + 1 - 1);
414
+ const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
415
+ const shortshortCurrDeviceString = shortCurrDeviceString.slice(0, shortCurrDeviceString.lastIndexOf('.') + 1 - 1);
427
416
 
428
- //Get ID of foldername
429
- case 'yeelight-2':
430
- deviceName = shortCurrDeviceString.slice(shortCurrDeviceString.lastIndexOf('.') + 1);
431
- break;
417
+ try {
418
+ // Get device name
419
+ const deviceObject = await this.getForeignObjectAsync(currDeviceString);
420
+ const shortDeviceObject = await this.getForeignObjectAsync(shortCurrDeviceString);
421
+ const shortshortDeviceObject = await this.getForeignObjectAsync(shortshortCurrDeviceString);
422
+ let deviceName;
423
+
424
+ // Get ID with currDeviceString from datapoint
425
+ switch (this.arrDev[i].adapterID) {
426
+ // Get ID for Switchbot and ESPHome Devices
427
+ case 'switchbotBle':
428
+ case 'esphome':
429
+ deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
430
+ break;
431
+
432
+ // Get ID with short currDeviceString from objectjson
433
+ case 'hueExt':
434
+ case 'hmrpc':
435
+ case 'nukiExt':
436
+ case 'wled':
437
+ if (shortDeviceObject && typeof shortDeviceObject === 'object') {
438
+ deviceName = shortDeviceObject.common.name;
439
+ }
440
+ break;
432
441
 
433
- // Get ID with main selektor from objectjson
434
- default:
435
- if (deviceObject && typeof deviceObject === 'object') {
436
- if (deviceObject.common.name['de'] != undefined) {
437
- deviceName = deviceObject.common.name['de'];
438
- } else if (deviceObject.common.name['en'] != undefined) {
439
- deviceName = deviceObject.common.name['en'];
440
- } else {
442
+ // Get ID with short short currDeviceString from objectjson (HMiP Devices)
443
+ case 'hmiP':
444
+ if (shortshortDeviceObject && typeof shortshortDeviceObject === 'object') {
445
+ deviceName = shortshortDeviceObject.common.name;
446
+ }
447
+ break;
448
+
449
+ // Get ID with short currDeviceString from datapoint
450
+ case 'mihomeVacuum':
451
+ case 'roomba':
452
+ deviceName = await this.getInitValue(shortCurrDeviceString + this.arrDev[i].id);
453
+ break;
454
+
455
+ //Get ID of foldername
456
+ case 'tado':
457
+ deviceName = currDeviceString.slice(currDeviceString.lastIndexOf('.') + 1);
458
+ break;
459
+
460
+ //Get ID of foldername
461
+ case 'yeelight':
462
+ deviceName = shortCurrDeviceString.slice(shortCurrDeviceString.lastIndexOf('.') + 1);
463
+ break;
464
+
465
+ // Get ID with main selektor from objectjson
466
+ default:
467
+ if (deviceObject && typeof deviceObject === 'object') {
441
468
  deviceName = deviceObject.common.name;
442
469
  }
443
- }
444
- break;
470
+ break;
471
+ }
472
+ return deviceName;
473
+ } catch (error) {
474
+ this.errorReporting('[getDeviceName]', error);
475
+ }
476
+ }
477
+
478
+ /**
479
+ * get Last Contact
480
+ * @param {object} selector - Selector
481
+ */
482
+ async getLastContact(selector) {
483
+ const lastContact = await this.getTimestamp(selector);
484
+ let lastContactString;
485
+
486
+ lastContactString = this.formatDate(new Date(selector), 'hh:mm') + ' Uhr';
487
+ if (Math.round(lastContact) > 100) {
488
+ lastContactString = Math.round(lastContact / 60) + ' Stunden';
445
489
  }
446
- return deviceName;
490
+ if (Math.round(lastContact / 60) > 48) {
491
+ lastContactString = Math.round(lastContact / 60 / 24) + ' Tagen';
492
+ }
493
+ return lastContactString;
447
494
  }
448
495
 
449
496
  /**
@@ -455,59 +502,73 @@ class DeviceWatcher extends utils.Adapter {
455
502
  this.batteryLowPowered = [];
456
503
  this.listAllDevices = [];
457
504
  this.offlineDevices = [];
505
+ this.batteryLowPoweredRaw = [];
506
+ this.offlineDevicesRaw = [];
458
507
 
459
508
  for (const device of this.listAllDevicesRaw) {
509
+ /*---------- fill raw lists ----------*/
510
+ // low bat list
511
+ if (device['LowBat'] && device['Status'] !== 'Offline') {
512
+ this.batteryLowPoweredRaw.push({
513
+ Path: device['Path'],
514
+ Device: device['Device'],
515
+ Adapter: device['Adapter'],
516
+ Battery: device['Battery'],
517
+ });
518
+ }
519
+ // offline raw list
520
+ if (device['Status'] === 'Offline') {
521
+ this.offlineDevicesRaw.push({
522
+ Path: device['Path'],
523
+ Device: device['Device'],
524
+ Adapter: device['Adapter'],
525
+ 'Last contact': device['Last contact'],
526
+ });
527
+ }
528
+
529
+ /*---------- fill user lists ----------*/
460
530
  if (!this.blacklistLists.includes(device['Path'])) {
461
- this.listAllDevices.push(
462
- {
463
- 'Device': device['Device'],
464
- 'Adapter': device['Adapter'],
465
- 'Battery': device['Battery'],
466
- 'Signal strength': device['Signal strength'],
467
- 'Last contact': device['Last contact'],
468
- 'Status': device['Status']
469
- }
470
- );
531
+ this.listAllDevices.push({
532
+ Device: device['Device'],
533
+ Adapter: device['Adapter'],
534
+ Battery: device['Battery'],
535
+ 'Signal strength': device['Signal strength'],
536
+ 'Last contact': device['Last contact'],
537
+ Status: device['Status'],
538
+ });
471
539
  // LinkQuality lists
472
540
  if (device['Signal strength'] != ' - ') {
473
- this.linkQualityDevices.push(
474
- {
475
- 'Device': device['Device'],
476
- 'Adapter': device['Adapter'],
477
- 'Signal strength': device['Signal strength']
478
- }
479
- );
541
+ this.linkQualityDevices.push({
542
+ Device: device['Device'],
543
+ Adapter: device['Adapter'],
544
+ 'Signal strength': device['Signal strength'],
545
+ });
480
546
  }
481
547
  // Battery lists
482
- if (device['Battery'] != ' - ') {
483
- this.batteryPowered.push(
484
- {
485
- 'Device': device['Device'],
486
- 'Adapter': device['Adapter'],
487
- 'Battery': device['Battery']
488
- }
489
- );
548
+ if (device['isBatteryDevice']) {
549
+ this.batteryPowered.push({
550
+ Device: device['Device'],
551
+ Adapter: device['Adapter'],
552
+ Battery: device['Battery'],
553
+ Status: device['Status'],
554
+ });
490
555
  }
491
556
  // Low Bat lists
492
- if (device['LowBat']) {
493
- this.batteryLowPowered.push(
494
- {
495
- 'Device': device['Device'],
496
- 'Adapter': device['Adapter'],
497
- 'Battery': device['Battery']
498
- }
499
- );
557
+ if (device['LowBat'] && device['Status'] !== 'Offline') {
558
+ this.batteryLowPowered.push({
559
+ Device: device['Device'],
560
+ Adapter: device['Adapter'],
561
+ Battery: device['Battery'],
562
+ });
500
563
  }
501
564
 
502
565
  // Offline List
503
566
  if (device['Status'] === 'Offline') {
504
- this.offlineDevices.push(
505
- {
506
- 'Device': device['Device'],
507
- 'Adapter': device['Adapter'],
508
- 'Last contact': device['Last contact']
509
- }
510
- );
567
+ this.offlineDevices.push({
568
+ Device: device['Device'],
569
+ Adapter: device['Adapter'],
570
+ 'Last contact': device['Last contact'],
571
+ });
511
572
  }
512
573
  }
513
574
  }
@@ -531,6 +592,11 @@ class DeviceWatcher extends utils.Adapter {
531
592
 
532
593
  // Count how many devices are exists
533
594
  this.deviceCounter = this.listAllDevices.length;
595
+
596
+ // raws
597
+
598
+ // Count how many devcies are offline
599
+ this.offlineDevicesCountRaw = this.offlineDevicesRaw.length;
534
600
  }
535
601
 
536
602
  /**
@@ -538,23 +604,26 @@ class DeviceWatcher extends utils.Adapter {
538
604
  */
539
605
  async createData(i) {
540
606
  const devices = await this.getForeignStatesAsync(this.arrDev[i].Selektor);
541
- const adapterID = this.arrDev[i].adapter;
607
+ const adapterID = this.arrDev[i].adapterID;
542
608
 
543
609
  /*---------- Start of loop ----------*/
544
610
  for (const [id] of Object.entries(devices)) {
545
611
  if (!isUnloaded) {
546
-
547
612
  /*=============================================
548
613
  = Get device name =
549
614
  =============================================*/
550
615
  const deviceName = await this.getDeviceName(id, i);
551
616
 
617
+ /*=============================================
618
+ = Get adapter name =
619
+ =============================================*/
620
+ const adapter = this.arrDev[i].adapter;
552
621
 
553
622
  /*=============================================
554
623
  = Get path to datapoints =
555
624
  =============================================*/
556
- const currDeviceString = id.slice(0, (id.lastIndexOf('.') + 1) - 1);
557
- const shortCurrDeviceString = currDeviceString.slice(0, (currDeviceString.lastIndexOf('.') + 1) - 1);
625
+ const currDeviceString = id.slice(0, id.lastIndexOf('.') + 1 - 1);
626
+ const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
558
627
 
559
628
  /*=============================================
560
629
  = Get signal strength =
@@ -601,8 +670,8 @@ class DeviceWatcher extends utils.Adapter {
601
670
  } else if (deviceQualityState.val < 0) {
602
671
  linkQuality = Math.min(Math.max(2 * (deviceQualityState.val + 100), 0), 100) + '%';
603
672
  // If Quality State is an value between 0-255 (zigbee) calculate in percent:
604
- } else if ((deviceQualityState.val) >= 0) {
605
- linkQuality = parseFloat((100 / 255 * deviceQualityState.val).toFixed(0)) + '%';
673
+ } else if (deviceQualityState.val >= 0) {
674
+ linkQuality = parseFloat(((100 / 255) * deviceQualityState.val).toFixed(0)) + '%';
606
675
  }
607
676
  break;
608
677
  }
@@ -615,7 +684,7 @@ class DeviceWatcher extends utils.Adapter {
615
684
  // for Netatmo devices
616
685
  linkQuality = deviceQualityState.val;
617
686
  break;
618
- case 'nuki-extended':
687
+ case 'nukiExt':
619
688
  linkQuality = ' - ';
620
689
  break;
621
690
  }
@@ -630,6 +699,7 @@ class DeviceWatcher extends utils.Adapter {
630
699
  =============================================*/
631
700
  let batteryHealth;
632
701
  let lowBatIndicator;
702
+ let isBatteryDevice;
633
703
 
634
704
  // Get battery states
635
705
  const deviceBatteryState = await this.getInitValue(currDeviceString + this.arrDev[i].battery);
@@ -642,17 +712,19 @@ class DeviceWatcher extends utils.Adapter {
642
712
  deviceLowBatState = await this.getInitValue(currDeviceString + this.arrDev[i].isLowBat2);
643
713
  }
644
714
 
645
- if ((!deviceBatteryState) && (!shortDeviceBatteryState) && (!shortDeviceBatteryState2)) {
715
+ if (!deviceBatteryState && !shortDeviceBatteryState && !shortDeviceBatteryState2) {
646
716
  if (deviceLowBatState !== undefined) {
647
717
  switch (this.arrDev[i].isLowBat || this.arrDev[i].isLowBat2) {
648
718
  case 'none':
649
719
  batteryHealth = ' - ';
650
720
  break;
651
721
  default:
652
- if ((deviceLowBatState === false) || (deviceLowBatState === 'NORMAL') || (deviceLowBatState === 1)) {
722
+ if (deviceLowBatState === false || deviceLowBatState === 'NORMAL' || deviceLowBatState === 1) {
653
723
  batteryHealth = 'ok';
724
+ isBatteryDevice = true;
654
725
  } else {
655
726
  batteryHealth = 'low';
727
+ isBatteryDevice = true;
656
728
  }
657
729
  break;
658
730
  }
@@ -666,141 +738,109 @@ class DeviceWatcher extends utils.Adapter {
666
738
  batteryHealth = ' - ';
667
739
  } else {
668
740
  batteryHealth = deviceBatteryState + 'V';
741
+ isBatteryDevice = true;
669
742
  }
670
743
  break;
671
744
 
672
- case 'hue-extended':
745
+ case 'hueExt':
673
746
  if (shortDeviceBatteryState) {
674
747
  batteryHealth = shortDeviceBatteryState + '%';
748
+ isBatteryDevice = true;
675
749
  }
676
750
  break;
677
751
  case 'mihomeVacuum':
678
752
  if (shortDeviceBatteryState) {
679
753
  batteryHealth = shortDeviceBatteryState + '%';
754
+ isBatteryDevice = true;
680
755
  } else if (shortDeviceBatteryState2) {
681
756
  batteryHealth = shortDeviceBatteryState2 + '%';
757
+ isBatteryDevice = true;
682
758
  }
683
759
  break;
684
760
  default:
685
- batteryHealth = (deviceBatteryState) + '%';
761
+ batteryHealth = deviceBatteryState + '%';
762
+ isBatteryDevice = true;
686
763
  }
687
764
  }
688
765
 
689
766
  /*=============================================
690
767
  = Set Lowbat indicator =
691
768
  =============================================*/
692
- switch (adapterID) {
693
- case 'hmrpc': // there are differnt low bat states between hm and hmIp devices
694
- if (deviceLowBatState) {
769
+ switch (typeof deviceLowBatState) {
770
+ case 'number':
771
+ if (deviceLowBatState === 0) {
695
772
  lowBatIndicator = true;
696
773
  }
697
774
  break;
698
- case 'tado': // there is an string as indicator
699
- if (deviceLowBatState != 'NORMAL') {
775
+
776
+ case 'string':
777
+ if (deviceLowBatState !== 'NORMAL') {
778
+ // Tado devices
700
779
  lowBatIndicator = true;
701
780
  }
702
781
  break;
703
782
 
704
- default: // for all other devices with low bat states
705
- if ((deviceLowBatState === true) || (deviceLowBatState === 0)) {
783
+ case 'boolean':
784
+ if (deviceLowBatState) {
706
785
  lowBatIndicator = true;
707
- } else if (deviceBatteryState && (deviceBatteryState < this.config.minWarnBatterie)) { // if the battery state is under the set limit
786
+ }
787
+ break;
788
+
789
+ default: // if the battery state is under the set limit
790
+ if (deviceBatteryState && deviceBatteryState < this.config.minWarnBatterie) {
708
791
  lowBatIndicator = true;
709
792
  }
793
+ break;
710
794
  }
711
795
 
712
796
  /*=============================================
713
797
  = Get last contact of device =
714
798
  =============================================*/
715
799
  let lastContactString;
716
- let lastDeviceUnreachStateChange;
717
800
  let deviceState = 'Online';
718
801
 
719
802
  const deviceMainSelector = await this.getForeignStateAsync(id);
803
+ const deviceUnreachSelector = await this.getForeignStateAsync(currDeviceString + this.arrDev[i].reach);
720
804
  const deviceStateSelector = await this.getForeignStateAsync(shortCurrDeviceString + this.arrDev[i].stateValue); // for hmrpc devices
721
805
  const rssiPeerSelector = await this.getForeignStateAsync(currDeviceString + this.arrDev[i].rssiPeerState);
722
806
 
723
807
  if (deviceMainSelector) {
724
808
  try {
725
809
  const lastContact = await this.getTimestamp(deviceMainSelector.ts);
726
- const lastStateChange = await this.getTimestamp(deviceMainSelector.lc);
727
810
  const deviceUnreachState = await this.getInitValue(currDeviceString + this.arrDev[i].reach);
728
- const deviceUnreachSelector = await this.getForeignStateAsync(currDeviceString + this.arrDev[i].reach);
729
- if (deviceUnreachSelector) {lastDeviceUnreachStateChange = await this.getTimestamp(deviceUnreachSelector.lc);}
811
+ const lastDeviceUnreachStateChange = deviceUnreachSelector != undefined ? await this.getTimestamp(deviceUnreachSelector.lc) : await this.getTimestamp(deviceMainSelector.ts);
730
812
  const shortDeviceUnreachState = await this.getForeignStateAsync(shortCurrDeviceString + this.arrDev[i].reach);
731
813
 
732
- const getLastContact = async () => {
733
- lastContactString = this.formatDate(new Date((deviceMainSelector.ts)), 'hh:mm') + ' Uhr';
734
- if (Math.round(lastContact) > 100) {
735
- lastContactString = Math.round(lastContact / 60) + ' Stunden';
736
- }
737
- if (Math.round(lastContact / 60) > 48) {
738
- lastContactString = Math.round(lastContact / 60 / 24) + ' Tagen';
739
- }
740
- return lastContactString;
741
- };
742
-
743
- const getLastStateChange = async () => {
744
- lastContactString = this.formatDate(new Date((deviceMainSelector.lc)), 'hh:mm') + ' Uhr';
745
- if (Math.round(lastStateChange) > 100) {
746
- lastContactString = Math.round(lastStateChange / 60) + ' Stunden';
747
- }
748
- if (Math.round(lastStateChange / 60) > 48) {
749
- lastContactString = Math.round(lastStateChange / 60 / 24) + ' Tagen';
750
- }
751
- return lastContactString;
752
- };
753
-
754
814
  // If there is no contact since user sets minutes add device in offline list
755
815
  // calculate to days after 48 hours
756
816
  switch (this.arrDev[i].reach) {
757
817
  case 'none':
758
- await getLastContact();
818
+ lastContactString = await this.getLastContact(deviceMainSelector.ts);
759
819
  break;
760
820
 
761
821
  default:
762
822
  //State changed
763
- if (adapterID === 'hmrpc') {
764
- if (linkQuality != ' - ') {
823
+ if (adapterID === 'hmrpc') {
824
+ if (linkQuality !== ' - ') {
765
825
  if (deviceUnreachState) {
766
- await getLastStateChange();
826
+ lastContactString = await this.getLastContact(deviceMainSelector.lc);
767
827
  } else {
768
- await getLastContact();
828
+ lastContactString = await this.getLastContact(deviceMainSelector.ts);
769
829
  }
770
830
  } else {
771
- if (deviceStateSelector) { // because old hm devices don't send rssi states
772
- const lastContactOfState = await this.getTimestamp(deviceStateSelector.ts);
773
- const getLastContactOfState = async () => {
774
- lastContactString = this.formatDate(new Date((deviceStateSelector.ts)), 'hh:mm') + ' Uhr';
775
- if (Math.round(lastContactOfState) > 100) {
776
- lastContactString = Math.round(lastContactOfState / 60) + ' Stunden';
777
- }
778
- if (Math.round(lastContactOfState / 60) > 48) {
779
- lastContactString = Math.round(lastContactOfState / 60 / 24) + ' Tagen';
780
- }
781
- return lastContactString;
782
- };
783
- await getLastContactOfState();
784
- } else if (rssiPeerSelector) { // because old hm sensors don't send rssi/state values
785
- const lastContactOfState = await this.getTimestamp(rssiPeerSelector.ts);
786
- const getLastContactOfState = async () => {
787
- lastContactString = this.formatDate(new Date((rssiPeerSelector.ts)), 'hh:mm') + ' Uhr';
788
- if (Math.round(lastContactOfState) > 100) {
789
- lastContactString = Math.round(lastContactOfState / 60) + ' Stunden';
790
- }
791
- if (Math.round(lastContactOfState / 60) > 48) {
792
- lastContactString = Math.round(lastContactOfState / 60 / 24) + ' Tagen';
793
- }
794
- return lastContactString;
795
- };
796
- await getLastContactOfState();
831
+ if (deviceStateSelector) {
832
+ // because old hm devices don't send rssi states
833
+ lastContactString = await this.getLastContact(deviceStateSelector.ts);
834
+ } else if (rssiPeerSelector) {
835
+ // because old hm sensors don't send rssi/state values
836
+ lastContactString = await this.getLastContact(rssiPeerSelector.ts);
797
837
  }
798
838
  }
799
839
  } else {
800
840
  if (!deviceUnreachState) {
801
- await getLastStateChange();
841
+ lastContactString = await this.getLastContact(deviceMainSelector.lc);
802
842
  } else {
803
- await getLastContact();
843
+ lastContactString = await this.getLastContact(deviceMainSelector.ts);
804
844
  }
805
845
  break;
806
846
  }
@@ -809,115 +849,102 @@ class DeviceWatcher extends utils.Adapter {
809
849
  /*=============================================
810
850
  = Set Online Status =
811
851
  =============================================*/
812
- switch (adapterID) {
813
- case 'hmrpc':
814
- case 'hmiP':
815
- case 'maxcube':
816
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
817
- if (deviceUnreachState) {
852
+ if (this.maxMinutes !== undefined) {
853
+ switch (adapterID) {
854
+ case 'hmrpc':
855
+ case 'hmiP':
856
+ case 'maxcube':
857
+ if (this.maxMinutes[adapterID] <= 0) {
858
+ if (deviceUnreachState) {
859
+ deviceState = 'Offline'; //set online state to offline
860
+ linkQuality = '0%'; // set linkQuality to nothing
861
+ }
862
+ } else if (lastDeviceUnreachStateChange > this.maxMinutes[adapterID] && deviceUnreachState) {
818
863
  deviceState = 'Offline'; //set online state to offline
819
864
  linkQuality = '0%'; // set linkQuality to nothing
820
- batteryHealth = ' - '; // set batteryhelth to nothing
821
865
  }
822
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
823
- deviceState = 'Offline'; //set online state to offline
824
- linkQuality = '0%'; // set linkQuality to nothing
825
- batteryHealth = ' - '; // set batteryhelth to nothing
826
- }
827
- break;
828
- case 'ping':
829
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
830
- if (!deviceUnreachState) {
866
+ break;
867
+ case 'ping':
868
+ case 'deconz':
869
+ if (this.maxMinutes[adapterID] <= 0) {
870
+ if (!deviceUnreachState) {
871
+ deviceState = 'Offline'; //set online state to offline
872
+ linkQuality = '0%'; // set linkQuality to nothing
873
+ }
874
+ } else if (lastDeviceUnreachStateChange > this.maxMinutes[adapterID] && !deviceUnreachState) {
831
875
  deviceState = 'Offline'; //set online state to offline
832
876
  linkQuality = '0%'; // set linkQuality to nothing
833
- batteryHealth = ' - '; // set batteryhelth to nothing
834
877
  }
835
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID]) && (!deviceUnreachState)) {
836
- deviceState = 'Offline'; //set online state to offline
837
- linkQuality = '0%'; // set linkQuality to nothing
838
- batteryHealth = ' - '; // set batteryhelth to nothing
839
- }
840
- break;
841
- case 'unifi':
842
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
843
- if (deviceUnreachState === 0) {
878
+ break;
879
+ case 'unifi':
880
+ if (this.maxMinutes[adapterID] <= 0) {
881
+ if (deviceUnreachState === 0) {
882
+ deviceState = 'Offline'; //set online state to offline
883
+ linkQuality = '0%'; // set linkQuality to nothing
884
+ }
885
+ } else if (this.maxMinutes !== undefined && lastContact > this.maxMinutes[adapterID]) {
844
886
  deviceState = 'Offline'; //set online state to offline
845
887
  linkQuality = '0%'; // set linkQuality to nothing
846
- batteryHealth = ' - '; // set batteryhelth to nothing
847
888
  }
848
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
849
- deviceState = 'Offline'; //set online state to offline
850
- linkQuality = '0%'; // set linkQuality to nothing
851
- batteryHealth = ' - '; // set batteryhelth to nothing
852
- }
853
- break;
854
- case 'shelly':
855
- case 'sonoff':
856
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
857
- if (!deviceUnreachState) {
889
+ break;
890
+ case 'shelly':
891
+ case 'sonoff':
892
+ if (this.maxMinutes[adapterID] <= 0) {
893
+ if (!deviceUnreachState) {
894
+ deviceState = 'Offline'; //set online state to offline
895
+ linkQuality = '0%'; // set linkQuality to nothing
896
+ }
897
+ } else if (!deviceUnreachState && lastDeviceUnreachStateChange > this.maxMinutes[adapterID]) {
858
898
  deviceState = 'Offline'; //set online state to offline
859
899
  linkQuality = '0%'; // set linkQuality to nothing
860
- batteryHealth = ' - '; // set batteryhelth to nothing
861
900
  }
862
- } else if ((!deviceUnreachState) && (typeof lastDeviceUnreachStateChange !== 'undefined') && (this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
863
- deviceState = 'Offline'; //set online state to offline
864
- linkQuality = '0%'; // set linkQuality to nothing
865
- batteryHealth = ' - '; // set batteryhelth to nothing
866
- }
867
- break;
868
- case 'mihomeVacuum':
869
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
870
- if (!shortDeviceUnreachState) {
901
+ break;
902
+ case 'mihomeVacuum':
903
+ if (this.maxMinutes[adapterID] <= 0) {
904
+ if (!shortDeviceUnreachState) {
905
+ deviceState = 'Offline'; //set online state to offline
906
+ linkQuality = '0%'; // set linkQuality to nothing
907
+ }
908
+ } else if (lastContact > this.maxMinutes[adapterID]) {
871
909
  deviceState = 'Offline'; //set online state to offline
872
910
  linkQuality = '0%'; // set linkQuality to nothing
873
- batteryHealth = ' - '; // set batteryhelth to nothing
874
911
  }
875
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
876
- deviceState = 'Offline'; //set online state to offline
877
- linkQuality = '0%'; // set linkQuality to nothing
878
- batteryHealth = ' - '; // set batteryhelth to nothing
879
- }
880
- break;
881
- case 'miHome':
882
- if (this.arrDev[i].battery === 'none') {
883
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
884
- if (!deviceUnreachState) {
912
+ break;
913
+ case 'mihome':
914
+ if (this.arrDev[i].battery === 'none') {
915
+ if (this.maxMinutes[adapterID] <= 0) {
916
+ if (!deviceUnreachState) {
917
+ deviceState = 'Offline'; //set online state to offline
918
+ linkQuality = '0%'; // set linkQuality to nothing
919
+ }
920
+ } else if (lastContact > this.maxMinutes[adapterID]) {
921
+ deviceState = 'Offline'; //set online state to offline
922
+ linkQuality = '0%'; // set linkQuality to nothing
923
+ }
924
+ } else {
925
+ if (this.config.mihomeMaxMinutes <= 0) {
926
+ if (this.maxMinutes[adapterID] <= 0) {
927
+ deviceState = 'Offline'; //set online state to offline
928
+ linkQuality = '0%'; // set linkQuality to nothing
929
+ }
930
+ } else if (lastContact > this.maxMinutes[adapterID]) {
885
931
  deviceState = 'Offline'; //set online state to offline
886
932
  linkQuality = '0%'; // set linkQuality to nothing
887
- batteryHealth = ' - '; // set batteryhelth to nothing
888
933
  }
889
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
890
- deviceState = 'Offline'; //set online state to offline
891
- linkQuality = '0%'; // set linkQuality to nothing
892
- batteryHealth = ' - '; // set batteryhelth to nothing
893
934
  }
894
- } else {
895
- if (this.config.mihomeMaxMinutes === -1) {
896
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
935
+ break;
936
+ default:
937
+ if (this.maxMinutes[adapterID] <= 0) {
938
+ if (!deviceUnreachState) {
897
939
  deviceState = 'Offline'; //set online state to offline
898
940
  linkQuality = '0%'; // set linkQuality to nothing
899
- batteryHealth = ' - '; // set batteryhelth to nothing
900
941
  }
901
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
942
+ } else if (lastContact > this.maxMinutes[adapterID]) {
902
943
  deviceState = 'Offline'; //set online state to offline
903
944
  linkQuality = '0%'; // set linkQuality to nothing
904
- batteryHealth = ' - '; // set batteryhelth to nothing
905
- }
906
- }
907
- break;
908
- default:
909
- if ((this.maxMinutes !== undefined) && (this.maxMinutes[adapterID] === -1)) {
910
- if (!deviceUnreachState) {
911
- deviceState = 'Offline'; //set online state to offline
912
- linkQuality = '0%'; // set linkQuality to nothing
913
- batteryHealth = ' - '; // set batteryhelth to nothing
914
945
  }
915
- } else if ((this.maxMinutes !== undefined) && (lastContact > this.maxMinutes[adapterID])) {
916
- deviceState = 'Offline'; //set online state to offline
917
- linkQuality = '0%'; // set linkQuality to nothing
918
- batteryHealth = ' - '; // set batteryhelth to nothing
919
- }
920
- break;
946
+ break;
947
+ }
921
948
  }
922
949
  } catch (error) {
923
950
  this.errorReporting('[getLastContact]', error);
@@ -930,34 +957,32 @@ class DeviceWatcher extends utils.Adapter {
930
957
 
931
958
  /* Add only devices with battery in the rawlist */
932
959
  if (this.listOnlyBattery) {
933
- if (deviceBatteryState || shortDeviceBatteryState) {
934
- this.listAllDevicesRaw.push(
935
- {
936
- 'Path': id,
937
- 'Device': deviceName,
938
- 'Adapter': await this.capitalize(adapterID),
939
- 'Battery': batteryHealth,
940
- 'LowBat': lowBatIndicator,
941
- 'Signal strength': linkQuality,
942
- 'Last contact': lastContactString,
943
- 'Status': deviceState
944
- }
945
- );
960
+ if (isBatteryDevice) {
961
+ this.listAllDevicesRaw.push({
962
+ Path: id,
963
+ Device: deviceName,
964
+ Adapter: adapter,
965
+ isBatteryDevice: isBatteryDevice,
966
+ Battery: batteryHealth,
967
+ LowBat: lowBatIndicator,
968
+ 'Signal strength': linkQuality,
969
+ 'Last contact': lastContactString,
970
+ Status: deviceState,
971
+ });
946
972
  }
947
973
  } else {
948
974
  /* Add all devices */
949
- this.listAllDevicesRaw.push(
950
- {
951
- 'Path': id,
952
- 'Device': deviceName,
953
- 'Adapter': await this.capitalize(adapterID),
954
- 'Battery': batteryHealth,
955
- 'LowBat': lowBatIndicator,
956
- 'Signal strength': linkQuality,
957
- 'Last contact': lastContactString,
958
- 'Status': deviceState
959
- }
960
- );
975
+ this.listAllDevicesRaw.push({
976
+ Path: id,
977
+ Device: deviceName,
978
+ Adapter: adapter,
979
+ isBatteryDevice: isBatteryDevice,
980
+ Battery: batteryHealth,
981
+ LowBat: lowBatIndicator,
982
+ 'Signal strength': linkQuality,
983
+ 'Last contact': lastContactString,
984
+ Status: deviceState,
985
+ });
961
986
  }
962
987
  } else {
963
988
  /* cancel run if unloaded was called. */
@@ -968,7 +993,6 @@ class DeviceWatcher extends utils.Adapter {
968
993
  await this.countDevices();
969
994
  } // <-- end of createData
970
995
 
971
-
972
996
  /**
973
997
  * @param {string} adptName - Adapter name
974
998
  */
@@ -980,14 +1004,13 @@ class DeviceWatcher extends utils.Adapter {
980
1004
 
981
1005
  try {
982
1006
  for (let i = 0; i < this.arrDev.length; i++) {
983
-
984
- if (this.arrDev[i].adapter.includes(adptName)) { // list device only if selected adapter matched with device
1007
+ if (this.arrDev[i].adapterID.includes(adptName)) {
1008
+ // list device only if selected adapter matched with device
985
1009
  await this.createData(i);
986
1010
  }
987
1011
  }
988
1012
 
989
1013
  await this.writeDatapoints(adptName); // fill the datapoints
990
-
991
1014
  } catch (error) {
992
1015
  this.errorReporting('[createDataForEachAdapter]', error);
993
1016
  }
@@ -995,8 +1018,10 @@ class DeviceWatcher extends utils.Adapter {
995
1018
  this.log.debug(`Function finished: ${this.createDataForEachAdapter.name}`);
996
1019
  } // <-- end of createDataForEachAdapter
997
1020
 
1021
+ /**
1022
+ * create Data of all selected adapter in one list
1023
+ */
998
1024
  async createDataOfAllAdapter() {
999
- // create Data of all selected adapter in one list
1000
1025
  this.log.debug(`Function started: ${this.createDataOfAllAdapter.name}`);
1001
1026
 
1002
1027
  try {
@@ -1014,7 +1039,6 @@ class DeviceWatcher extends utils.Adapter {
1014
1039
  if (this.config.checkSendOfflineMsg) await this.sendOfflineNotifications();
1015
1040
 
1016
1041
  await this.writeDatapoints(); // fill the datapoints
1017
-
1018
1042
  } catch (error) {
1019
1043
  this.errorReporting('[createDataOfAllAdapter]', error);
1020
1044
  }
@@ -1022,13 +1046,11 @@ class DeviceWatcher extends utils.Adapter {
1022
1046
  this.log.debug(`Function finished: ${this.createDataOfAllAdapter.name}`);
1023
1047
  } // <-- end of createDataOfAllAdapter
1024
1048
 
1025
-
1026
1049
  /**
1027
1050
  * Notification service
1028
1051
  * @param {string} text - Text which should be send
1029
1052
  */
1030
1053
  async sendNotification(text) {
1031
-
1032
1054
  // Pushover
1033
1055
  try {
1034
1056
  if (this.config.instancePushover) {
@@ -1042,7 +1064,7 @@ class DeviceWatcher extends utils.Adapter {
1042
1064
  message: text,
1043
1065
  title: this.config.titlePushover,
1044
1066
  device: this.config.devicePushover,
1045
- priority: this.config.prioPushover
1067
+ priority: this.config.prioPushover,
1046
1068
  });
1047
1069
  }
1048
1070
  }
@@ -1062,7 +1084,7 @@ class DeviceWatcher extends utils.Adapter {
1062
1084
  await this.sendToAsync(this.config.instanceTelegram, 'send', {
1063
1085
  text: text,
1064
1086
  user: this.config.deviceTelegram,
1065
- chatId: this.config.chatIdTelegram
1087
+ chatId: this.config.chatIdTelegram,
1066
1088
  });
1067
1089
  }
1068
1090
  }
@@ -1081,7 +1103,7 @@ class DeviceWatcher extends utils.Adapter {
1081
1103
  } else {
1082
1104
  await this.sendToAsync(this.config.instanceWhatsapp, 'send', {
1083
1105
  text: text,
1084
- phone: this.config.phoneWhatsapp
1106
+ phone: this.config.phoneWhatsapp,
1085
1107
  });
1086
1108
  }
1087
1109
  }
@@ -1101,7 +1123,7 @@ class DeviceWatcher extends utils.Adapter {
1101
1123
  await this.sendToAsync(this.config.instanceEmail, 'send', {
1102
1124
  sendTo: this.config.sendToEmail,
1103
1125
  text: text,
1104
- subject: this.config.subjectEmail
1126
+ subject: this.config.subjectEmail,
1105
1127
  });
1106
1128
  }
1107
1129
  }
@@ -1119,7 +1141,10 @@ class DeviceWatcher extends utils.Adapter {
1119
1141
  this.log.warn('Jarvis instance is not running. Message could not be sent. Please check your instance configuration.');
1120
1142
  } else {
1121
1143
  const jsonText = JSON.stringify(text);
1122
- await this.setForeignStateAsync(`${this.config.instanceJarvis}.addNotification`, '{"title":"' + this.config.titleJarvis + ' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')","message": ' + jsonText + ',"display": "drawer"}');
1144
+ await this.setForeignStateAsync(
1145
+ `${this.config.instanceJarvis}.addNotification`,
1146
+ '{"title":"' + this.config.titleJarvis + ' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')","message": ' + jsonText + ',"display": "drawer"}',
1147
+ );
1123
1148
  }
1124
1149
  }
1125
1150
  } catch (error) {
@@ -1136,7 +1161,10 @@ class DeviceWatcher extends utils.Adapter {
1136
1161
  this.log.warn('Lovelace instance is not running. Message could not be sent. Please check your instance configuration.');
1137
1162
  } else {
1138
1163
  const jsonText = JSON.stringify(text);
1139
- await this.setForeignStateAsync(`${this.config.instanceLovelace}.notifications.add`, '{"message":' + jsonText + ', "title":"' + this.config.titleLovelace + ' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')"}');
1164
+ await this.setForeignStateAsync(
1165
+ `${this.config.instanceLovelace}.notifications.add`,
1166
+ '{"message":' + jsonText + ', "title":"' + this.config.titleLovelace + ' (' + this.formatDate(new Date(), 'DD.MM.YYYY - hh:mm:ss') + ')"}',
1167
+ );
1140
1168
  }
1141
1169
  }
1142
1170
  } catch (error) {
@@ -1144,10 +1172,11 @@ class DeviceWatcher extends utils.Adapter {
1144
1172
  }
1145
1173
  } // <-- End of sendNotification function
1146
1174
 
1175
+ /**
1176
+ * send shedule message for low battery devices
1177
+ */
1147
1178
  async sendBatteryNotifyShedule() {
1148
- // send message for low battery devices
1149
-
1150
- const time = (this.config.checkSendBatteryTime).split(':');
1179
+ const time = this.config.checkSendBatteryTime.split(':');
1151
1180
 
1152
1181
  const checkDays = []; // list of selected days
1153
1182
 
@@ -1160,8 +1189,9 @@ class DeviceWatcher extends utils.Adapter {
1160
1189
  if (this.config.checkSaturday) checkDays.push(6);
1161
1190
  if (this.config.checkSunday) checkDays.push(0);
1162
1191
 
1163
- if (checkDays.length >= 1) { // check if an day is selected
1164
- this.log.debug(`Number of selected days for daily battery message: ${checkDays.length}. Send Message on: ${(checkDays).join(', ')} ...`);
1192
+ if (checkDays.length >= 1) {
1193
+ // check if an day is selected
1194
+ this.log.debug(`Number of selected days for daily battery message: ${checkDays.length}. Send Message on: ${checkDays.join(', ')} ...`);
1165
1195
  } else {
1166
1196
  this.log.warn(`No days selected for daily battery message. Please check the instance configuration!`);
1167
1197
  return; // cancel function if no day is selected
@@ -1173,20 +1203,18 @@ class DeviceWatcher extends utils.Adapter {
1173
1203
  try {
1174
1204
  let deviceList = '';
1175
1205
 
1176
- for (const id of this.batteryLowPowered) {
1177
- if (!this.blacklistNotify.includes(id['Device'])) {
1206
+ for (const id of this.batteryLowPoweredRaw) {
1207
+ if (!this.blacklistNotify.includes(id['Path'])) {
1178
1208
  deviceList = `${deviceList}\n${id['Device']} (${id['Battery']})`;
1179
1209
  }
1180
1210
  }
1181
1211
 
1182
- if ((this.lowBatteryPoweredCount > 0) && (deviceList.length > 0)) {
1212
+ if (this.lowBatteryPoweredCountRaw > 0 && deviceList.length > 0) {
1183
1213
  this.log.info(`Niedrige Batteriezustände: ${deviceList}`);
1184
1214
  this.setStateAsync('lastNotification', `Niedrige Batteriezustände: ${deviceList}`, true);
1185
1215
 
1186
1216
  this.sendNotification(`Niedriege Batteriezustände: ${deviceList}`);
1187
-
1188
1217
  }
1189
-
1190
1218
  } catch (error) {
1191
1219
  this.errorReporting('[sendBatteryNotifyShedule]', error);
1192
1220
  }
@@ -1194,48 +1222,48 @@ class DeviceWatcher extends utils.Adapter {
1194
1222
  }
1195
1223
  } //<--End of battery notification
1196
1224
 
1225
+ /**
1226
+ * send message if an device is offline
1227
+ */
1197
1228
  async sendOfflineNotifications() {
1198
- // send message if an device is offline
1199
-
1200
1229
  this.log.debug(`Start the function: ${this.sendOfflineNotifications.name}`);
1201
1230
 
1202
1231
  try {
1203
1232
  let msg = '';
1204
1233
  let deviceList = '';
1205
- const offlineDevicesCountOld = await this.getOwnInitValue('offlineCount');
1206
-
1207
- if ((this.offlineDevicesCount !== offlineDevicesCountOld)) {
1208
1234
 
1209
- for (const id of this.offlineDevices) {
1210
- if (!this.blacklistNotify.includes(id['Device'])) {
1211
- deviceList = `${deviceList}\n${id['Device']} (${id['Last contact']})`;
1212
- }
1235
+ for (const id of this.offlineDevicesRaw) {
1236
+ if (!this.blacklistNotify.includes(id['Path'])) {
1237
+ deviceList = `${deviceList}\n${id['Device']} (${id['Last contact']})`;
1213
1238
  }
1214
- if (deviceList.length > 0) {
1215
- if (deviceList.length == 0) {
1216
- msg = 'Alle Geräte sind Online.';
1217
- } else if (deviceList.length == 1) { // make singular if it is only one device
1218
- msg = 'Folgendes Gerät ist seit einiger Zeit nicht erreichbar: \n';
1219
- } else if (deviceList.length >= 2) { //make plural if it is more than one device
1220
- msg = `Folgende Geräte sind seit einiger Zeit nicht erreichbar: \n`;
1221
- }
1222
-
1223
- this.log.info(msg + deviceList);
1224
- await this.setStateAsync('lastNotification', msg + deviceList, true);
1225
- await this.sendNotification(msg + deviceList);
1239
+ }
1240
+ if (deviceList.length !== this.offlineDevicesCountRawOld) {
1241
+ if (deviceList.length == 0) {
1242
+ msg = 'Alle Geräte sind Online.';
1243
+ } else if (deviceList.length == 1) {
1244
+ // make singular if it is only one device
1245
+ msg = 'Folgendes Gerät ist seit einiger Zeit nicht erreichbar: \n';
1246
+ } else if (deviceList.length >= 2) {
1247
+ //make plural if it is more than one device
1248
+ msg = `Folgende Geräte sind seit einiger Zeit nicht erreichbar: \n`;
1226
1249
  }
1227
1250
 
1251
+ this.log.info(msg + deviceList);
1252
+ this.offlineDevicesCountRawOld = deviceList.length;
1253
+ await this.setStateAsync('lastNotification', msg + deviceList, true);
1254
+ await this.sendNotification(msg + deviceList);
1228
1255
  }
1229
1256
  } catch (error) {
1230
1257
  this.errorReporting('[sendOfflineMessage]', error);
1231
1258
  }
1232
1259
  this.log.debug(`Finished the function: ${this.sendOfflineNotifications.name}`);
1233
- }//<--End of offline notification
1260
+ } //<--End of offline notification
1234
1261
 
1262
+ /**
1263
+ * send shedule message with offline devices
1264
+ */
1235
1265
  async sendOfflineNotificationsShedule() {
1236
- // send daily an overview with offline devices
1237
-
1238
- const time = (this.config.checkSendOfflineTime).split(':');
1266
+ const time = this.config.checkSendOfflineTime.split(':');
1239
1267
 
1240
1268
  const checkDays = []; // list of selected days
1241
1269
 
@@ -1248,8 +1276,9 @@ class DeviceWatcher extends utils.Adapter {
1248
1276
  if (this.config.checkOfflineSaturday) checkDays.push(6);
1249
1277
  if (this.config.checkOfflineSunday) checkDays.push(0);
1250
1278
 
1251
- if (checkDays.length >= 1) { // check if an day is selected
1252
- this.log.debug(`Number of selected days for daily offline message: ${checkDays.length}. Send Message on: ${(checkDays).join(', ')} ...`);
1279
+ if (checkDays.length >= 1) {
1280
+ // check if an day is selected
1281
+ this.log.debug(`Number of selected days for daily offline message: ${checkDays.length}. Send Message on: ${checkDays.join(', ')} ...`);
1253
1282
  } else {
1254
1283
  this.log.warn(`No days selected for daily offline message. Please check the instance configuration!`);
1255
1284
  return; // cancel function if no day is selected
@@ -1261,8 +1290,8 @@ class DeviceWatcher extends utils.Adapter {
1261
1290
  try {
1262
1291
  let deviceList = '';
1263
1292
 
1264
- for (const id of this.offlineDevices) {
1265
- if (!this.blacklistNotify.includes(id['Device'])) {
1293
+ for (const id of this.offlineDevicesRaw) {
1294
+ if (!this.blacklistNotify.includes(id['Path'])) {
1266
1295
  deviceList = `${deviceList}\n${id['Device']} (${id['Last contact']})`;
1267
1296
  }
1268
1297
  }
@@ -1273,14 +1302,16 @@ class DeviceWatcher extends utils.Adapter {
1273
1302
 
1274
1303
  this.sendNotification(`Geräte Offline: ${deviceList}`);
1275
1304
  }
1276
-
1277
1305
  } catch (error) {
1278
1306
  this.errorReporting('[sendOfflineNotificationsShedule]', error);
1279
1307
  }
1280
1308
  });
1281
1309
  }
1282
- }//<--End of daily offline notification
1310
+ } //<--End of daily offline notification
1283
1311
 
1312
+ /**
1313
+ * reset arrays and counts
1314
+ */
1284
1315
  async resetVars() {
1285
1316
  //Reset all arrays and counts
1286
1317
  this.log.debug(`Function started: ${this.resetVars.name}`);
@@ -1292,6 +1323,13 @@ class DeviceWatcher extends utils.Adapter {
1292
1323
  this.batteryLowPowered = [];
1293
1324
  this.listAllDevices = [];
1294
1325
  this.listAllDevicesRaw = [];
1326
+
1327
+ // raws
1328
+ this.batteryLowPoweredRaw = [];
1329
+ this.offlineDevicesRaw = [];
1330
+ this.lowBatteryPoweredCountRaw = 0;
1331
+ this.offlineDevicesCountRaw = 0;
1332
+
1295
1333
  // counts
1296
1334
  this.offlineDevicesCount = 0;
1297
1335
  this.deviceCounter = 0;
@@ -1302,7 +1340,6 @@ class DeviceWatcher extends utils.Adapter {
1302
1340
  this.log.debug(`Function finished: ${this.resetVars.name}`);
1303
1341
  } // <-- end of resetVars
1304
1342
 
1305
-
1306
1343
  /**
1307
1344
  * @param {string} [adptName] - Adaptername
1308
1345
  */
@@ -1312,7 +1349,6 @@ class DeviceWatcher extends utils.Adapter {
1312
1349
  this.log.debug(`Start the function: ${this.writeDatapoints.name}`);
1313
1350
 
1314
1351
  try {
1315
-
1316
1352
  let dpSubFolder;
1317
1353
  //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
1318
1354
  if (adptName) {
@@ -1328,62 +1364,91 @@ class DeviceWatcher extends utils.Adapter {
1328
1364
 
1329
1365
  if (this.deviceCounter == 0) {
1330
1366
  // if no device is count, write the JSON List with default value
1331
- this.listAllDevices = [{ 'Device': '--none--', 'Adapter': '', 'Battery': '', 'Last contact': '', 'Signal strength': '' }];
1367
+ this.listAllDevices = [{ Device: '--none--', Adapter: '', Battery: '', 'Last contact': '', 'Signal strength': '' }];
1332
1368
  }
1333
1369
  await this.setStateAsync(`${dpSubFolder}listAll`, { val: JSON.stringify(this.listAllDevices), ack: true });
1334
1370
 
1335
1371
  if (this.linkQualityCount == 0) {
1336
1372
  // if no device is count, write the JSON List with default value
1337
- this.linkQualityDevices = [{ 'Device': '--none--', 'Adapter': '', 'Signal strength': '' }];
1373
+ this.linkQualityDevices = [{ Device: '--none--', Adapter: '', 'Signal strength': '' }];
1338
1374
  }
1339
1375
  //write JSON list
1340
- await this.setStateAsync(`${dpSubFolder}linkQualityList`, { val: JSON.stringify(this.linkQualityDevices), ack: true });
1376
+ await this.setStateAsync(`${dpSubFolder}linkQualityList`, {
1377
+ val: JSON.stringify(this.linkQualityDevices),
1378
+ ack: true,
1379
+ });
1341
1380
  //write HTML list
1342
- if (this.config.createHtmlList) await this.setStateAsync(`${dpSubFolder}linkQualityListHTML`, { val: await this.creatLinkQualityListHTML(this.linkQualityDevices, this.linkQualityCount), ack: true });
1381
+ if (this.config.createHtmlList)
1382
+ await this.setStateAsync(`${dpSubFolder}linkQualityListHTML`, {
1383
+ val: await this.creatLinkQualityListHTML(this.linkQualityDevices, this.linkQualityCount),
1384
+ ack: true,
1385
+ });
1343
1386
 
1344
1387
  if (this.offlineDevicesCount == 0) {
1345
1388
  // if no device is count, write the JSON List with default value
1346
- this.offlineDevices = [{ 'Device': '--none--', 'Adapter': '', 'Last contact': '' }];
1389
+ this.offlineDevices = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
1347
1390
  }
1348
1391
  //write JSON list
1349
- await this.setStateAsync(`${dpSubFolder}offlineList`, { val: JSON.stringify(this.offlineDevices), ack: true });
1392
+ await this.setStateAsync(`${dpSubFolder}offlineList`, {
1393
+ val: JSON.stringify(this.offlineDevices),
1394
+ ack: true,
1395
+ });
1350
1396
  //write HTML list
1351
- if (this.config.createHtmlList) await this.setStateAsync(`${dpSubFolder}offlineListHTML`, { val: await this.createOfflineListHTML(this.offlineDevices, this.offlineDevicesCount), ack: true });
1397
+ if (this.config.createHtmlList)
1398
+ await this.setStateAsync(`${dpSubFolder}offlineListHTML`, {
1399
+ val: await this.createOfflineListHTML(this.offlineDevices, this.offlineDevicesCount),
1400
+ ack: true,
1401
+ });
1352
1402
 
1353
1403
  if (this.batteryPoweredCount == 0) {
1354
1404
  // if no device is count, write the JSON List with default value
1355
- this.batteryPowered = [{ 'Device': '--none--', 'Adapter': '', 'Battery': '' }];
1405
+ this.batteryPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
1356
1406
  }
1357
1407
  //write JSON list
1358
- await this.setStateAsync(`${dpSubFolder}batteryList`, { val: JSON.stringify(this.batteryPowered), ack: true });
1408
+ await this.setStateAsync(`${dpSubFolder}batteryList`, {
1409
+ val: JSON.stringify(this.batteryPowered),
1410
+ ack: true,
1411
+ });
1359
1412
  //write HTML list
1360
- if (this.config.createHtmlList) await this.setStateAsync(`${dpSubFolder}batteryListHTML`, { val: await this.createBatteryListHTML(this.batteryPowered, this.batteryPoweredCount, false), ack: true });
1413
+ if (this.config.createHtmlList)
1414
+ await this.setStateAsync(`${dpSubFolder}batteryListHTML`, {
1415
+ val: await this.createBatteryListHTML(this.batteryPowered, this.batteryPoweredCount, false),
1416
+ ack: true,
1417
+ });
1361
1418
 
1362
1419
  if (this.lowBatteryPoweredCount == 0) {
1363
1420
  // if no device is count, write the JSON List with default value
1364
- this.batteryLowPowered = [{ 'Device': '--none--', 'Adapter': '', 'Battery': '' }];
1421
+ this.batteryLowPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
1365
1422
  }
1366
1423
  //write JSON list
1367
- await this.setStateAsync(`${dpSubFolder}lowBatteryList`, { val: JSON.stringify(this.batteryLowPowered), ack: true });
1424
+ await this.setStateAsync(`${dpSubFolder}lowBatteryList`, {
1425
+ val: JSON.stringify(this.batteryLowPowered),
1426
+ ack: true,
1427
+ });
1368
1428
  //write HTML list
1369
- if (this.config.createHtmlList) await this.setStateAsync(`${dpSubFolder}lowBatteryListHTML`, { val: await this.createBatteryListHTML(this.batteryLowPowered, this.lowBatteryPoweredCount, true), ack: true });
1429
+ if (this.config.createHtmlList)
1430
+ await this.setStateAsync(`${dpSubFolder}lowBatteryListHTML`, {
1431
+ val: await this.createBatteryListHTML(this.batteryLowPowered, this.lowBatteryPoweredCount, true),
1432
+ ack: true,
1433
+ });
1370
1434
 
1371
1435
  // create timestamp of last run
1372
1436
  const lastCheck = this.formatDate(new Date(), 'DD.MM.YYYY') + ' - ' + this.formatDate(new Date(), 'hh:mm:ss');
1373
1437
  await this.setStateAsync('lastCheck', lastCheck, true);
1374
- }
1375
- catch (error) {
1438
+ } catch (error) {
1376
1439
  this.errorReporting('[writeDatapoints]', error);
1377
1440
  }
1378
1441
  this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
1379
- }//<--End of writing Datapoints
1442
+ } //<--End of writing Datapoints
1380
1443
 
1381
1444
  /**
1382
1445
  * @param {object} devices - Device
1383
1446
  * @param {number} deviceCount - Counted devices
1384
1447
  */
1385
1448
  async creatLinkQualityListHTML(devices, deviceCount) {
1386
- devices = devices.sort((a, b) => { return a.Device.localeCompare(b.Device); });
1449
+ devices = devices.sort((a, b) => {
1450
+ return a.Device.localeCompare(b.Device);
1451
+ });
1387
1452
  let html = `<center>
1388
1453
  <b>Link Quality Devices:<font> ${deviceCount}</b><small></small></font>
1389
1454
  <p></p>
@@ -1415,7 +1480,9 @@ class DeviceWatcher extends utils.Adapter {
1415
1480
  * @param {number} deviceCount - Counted devices
1416
1481
  */
1417
1482
  async createOfflineListHTML(devices, deviceCount) {
1418
- devices = devices.sort((a, b) => { return a.Device.localeCompare(b.Device); });
1483
+ devices = devices.sort((a, b) => {
1484
+ return a.Device.localeCompare(b.Device);
1485
+ });
1419
1486
  let html = `<center>
1420
1487
  <b>Offline Devices: <font color=${deviceCount == 0 ? '#3bcf0e' : 'orange'}>${deviceCount}</b><small></small></font>
1421
1488
  <p></p>
@@ -1448,7 +1515,9 @@ class DeviceWatcher extends utils.Adapter {
1448
1515
  * @param {object} [isLowBatteryList] - list Low Battery Devices
1449
1516
  */
1450
1517
  async createBatteryListHTML(devices, deviceCount, isLowBatteryList) {
1451
- devices = devices.sort((a, b) => { return a.Device.localeCompare(b.Device); });
1518
+ devices = devices.sort((a, b) => {
1519
+ return a.Device.localeCompare(b.Device);
1520
+ });
1452
1521
  let html = `<center>
1453
1522
  <b>${isLowBatteryList == true ? 'Schwache ' : ''}Batterie Devices: <font color=${isLowBatteryList == true ? (deviceCount > 0 ? 'orange' : '#3bcf0e') : ''}>${deviceCount}</b></font>
1454
1523
  <p></p>
@@ -1462,7 +1531,6 @@ class DeviceWatcher extends utils.Adapter {
1462
1531
  <tr>
1463
1532
  <td colspan="5"><hr></td>
1464
1533
  </tr>`;
1465
-
1466
1534
  for (const device of devices) {
1467
1535
  html += `<tr>
1468
1536
  <td><font>${device.Device}</font></td>
@@ -1473,7 +1541,6 @@ class DeviceWatcher extends utils.Adapter {
1473
1541
  } else {
1474
1542
  html += `<td align=right><font color=#3bcf0e>${device.Battery}</font></td>`;
1475
1543
  }
1476
-
1477
1544
  html += `</tr>`;
1478
1545
  }
1479
1546
 
@@ -1486,7 +1553,6 @@ class DeviceWatcher extends utils.Adapter {
1486
1553
  * @param {object} adptName - Adaptername of devices
1487
1554
  */
1488
1555
  async createDPsForEachAdapter(adptName) {
1489
-
1490
1556
  await this.setObjectNotExistsAsync(`${adptName}`, {
1491
1557
  type: 'channel',
1492
1558
  common: {
@@ -1496,210 +1562,210 @@ class DeviceWatcher extends utils.Adapter {
1496
1562
  });
1497
1563
 
1498
1564
  await this.setObjectNotExistsAsync(`${adptName}.offlineCount`, {
1499
- 'type': 'state',
1500
- 'common': {
1501
- 'name': {
1502
- 'en': 'Number of devices offline',
1503
- 'de': 'Anzahl der Geräte offline',
1504
- 'ru': 'Количество устройств offline',
1505
- 'pt': 'Número de dispositivos offline',
1506
- 'nl': 'Nummer van apparatuur offline',
1507
- 'fr': 'Nombre de dispositifs hors ligne',
1508
- 'it': 'Numero di dispositivi offline',
1509
- 'es': 'Número de dispositivos sin conexión',
1510
- 'pl': 'Ilość urządzeń offline',
1511
- 'zh-cn': '线内装置数量'
1565
+ type: 'state',
1566
+ common: {
1567
+ name: {
1568
+ en: 'Number of devices offline',
1569
+ de: 'Anzahl der Geräte offline',
1570
+ ru: 'Количество устройств offline',
1571
+ pt: 'Número de dispositivos offline',
1572
+ nl: 'Nummer van apparatuur offline',
1573
+ fr: 'Nombre de dispositifs hors ligne',
1574
+ it: 'Numero di dispositivi offline',
1575
+ es: 'Número de dispositivos sin conexión',
1576
+ pl: 'Ilość urządzeń offline',
1577
+ 'zh-cn': '线内装置数量',
1512
1578
  },
1513
- 'type': 'number',
1514
- 'role': 'value',
1515
- 'read': true,
1516
- 'write': false,
1579
+ type: 'number',
1580
+ role: 'value',
1581
+ read: true,
1582
+ write: false,
1517
1583
  },
1518
- 'native': {}
1584
+ native: {},
1519
1585
  });
1520
1586
 
1521
1587
  await this.setObjectNotExistsAsync(`${adptName}.offlineList`, {
1522
- 'type': 'state',
1523
- 'common': {
1524
- 'name': {
1525
- 'en': 'List of offline devices',
1526
- 'de': 'Liste der Offline-Geräte',
1527
- 'ru': 'Список оффлайн устройств',
1528
- 'pt': 'Lista de dispositivos off-line',
1529
- 'nl': 'List van offline apparatuur',
1530
- 'fr': 'Liste des dispositifs hors ligne',
1531
- 'it': 'Elenco dei dispositivi offline',
1532
- 'es': 'Lista de dispositivos sin conexión',
1533
- 'pl': 'Lista urządzeń offline',
1534
- 'zh-cn': '线装置清单'
1588
+ type: 'state',
1589
+ common: {
1590
+ name: {
1591
+ en: 'List of offline devices',
1592
+ de: 'Liste der Offline-Geräte',
1593
+ ru: 'Список оффлайн устройств',
1594
+ pt: 'Lista de dispositivos off-line',
1595
+ nl: 'List van offline apparatuur',
1596
+ fr: 'Liste des dispositifs hors ligne',
1597
+ it: 'Elenco dei dispositivi offline',
1598
+ es: 'Lista de dispositivos sin conexión',
1599
+ pl: 'Lista urządzeń offline',
1600
+ 'zh-cn': '线装置清单',
1535
1601
  },
1536
- 'type': 'array',
1537
- 'role': 'json',
1538
- 'read': true,
1539
- 'write': false,
1602
+ type: 'array',
1603
+ role: 'json',
1604
+ read: true,
1605
+ write: false,
1540
1606
  },
1541
- 'native': {}
1607
+ native: {},
1542
1608
  });
1543
1609
 
1544
1610
  await this.setObjectNotExistsAsync(`${adptName}.listAll`, {
1545
- 'type': 'state',
1546
- 'common': {
1547
- 'name': {
1548
- 'en': 'List of all devices',
1549
- 'de': 'Liste aller Geräte',
1550
- 'ru': 'Список всех устройств',
1551
- 'pt': 'Lista de todos os dispositivos',
1552
- 'nl': 'List van alle apparaten',
1553
- 'fr': 'Liste de tous les dispositifs',
1554
- 'it': 'Elenco di tutti i dispositivi',
1555
- 'es': 'Lista de todos los dispositivos',
1556
- 'pl': 'Lista wszystkich urządzeń',
1557
- 'zh-cn': '所有装置清单'
1611
+ type: 'state',
1612
+ common: {
1613
+ name: {
1614
+ en: 'List of all devices',
1615
+ de: 'Liste aller Geräte',
1616
+ ru: 'Список всех устройств',
1617
+ pt: 'Lista de todos os dispositivos',
1618
+ nl: 'List van alle apparaten',
1619
+ fr: 'Liste de tous les dispositifs',
1620
+ it: 'Elenco di tutti i dispositivi',
1621
+ es: 'Lista de todos los dispositivos',
1622
+ pl: 'Lista wszystkich urządzeń',
1623
+ 'zh-cn': '所有装置清单',
1558
1624
  },
1559
- 'type': 'array',
1560
- 'role': 'json',
1561
- 'read': true,
1562
- 'write': false,
1625
+ type: 'array',
1626
+ role: 'json',
1627
+ read: true,
1628
+ write: false,
1563
1629
  },
1564
- 'native': {}
1630
+ native: {},
1565
1631
  });
1566
1632
 
1567
1633
  await this.setObjectNotExistsAsync(`${adptName}.linkQualityList`, {
1568
- 'type': 'state',
1569
- 'common': {
1570
- 'name': {
1571
- 'en': 'List of devices with signal strength',
1572
- 'de': 'Liste der Geräte mit Signalstärke',
1573
- 'ru': 'Список устройств с силой сигнала',
1574
- 'pt': 'Lista de dispositivos com força de sinal',
1575
- 'nl': 'List van apparaten met signaalkracht',
1576
- 'fr': 'Liste des dispositifs avec force de signal',
1577
- 'it': 'Elenco dei dispositivi con forza del segnale',
1578
- 'es': 'Lista de dispositivos con fuerza de señal',
1579
- 'pl': 'Lista urządzeń z siłą sygnałową',
1580
- 'zh-cn': '具有信号实力的装置清单'
1634
+ type: 'state',
1635
+ common: {
1636
+ name: {
1637
+ en: 'List of devices with signal strength',
1638
+ de: 'Liste der Geräte mit Signalstärke',
1639
+ ru: 'Список устройств с силой сигнала',
1640
+ pt: 'Lista de dispositivos com força de sinal',
1641
+ nl: 'List van apparaten met signaalkracht',
1642
+ fr: 'Liste des dispositifs avec force de signal',
1643
+ it: 'Elenco dei dispositivi con forza del segnale',
1644
+ es: 'Lista de dispositivos con fuerza de señal',
1645
+ pl: 'Lista urządzeń z siłą sygnałową',
1646
+ 'zh-cn': '具有信号实力的装置清单',
1581
1647
  },
1582
- 'type': 'array',
1583
- 'role': 'json',
1584
- 'read': true,
1585
- 'write': false,
1648
+ type: 'array',
1649
+ role: 'json',
1650
+ read: true,
1651
+ write: false,
1586
1652
  },
1587
- 'native': {}
1653
+ native: {},
1588
1654
  });
1589
1655
 
1590
1656
  await this.setObjectNotExistsAsync(`${adptName}.countAll`, {
1591
- 'type': 'state',
1592
- 'common': {
1593
- 'name': {
1594
- 'en': 'Number of all devices',
1595
- 'de': 'Anzahl aller Geräte',
1596
- 'ru': 'Количество всех устройств',
1597
- 'pt': 'Número de todos os dispositivos',
1598
- 'nl': 'Nummer van alle apparaten',
1599
- 'fr': 'Nombre de tous les appareils',
1600
- 'it': 'Numero di tutti i dispositivi',
1601
- 'es': 'Número de todos los dispositivos',
1602
- 'pl': 'Ilość wszystkich urządzeń',
1603
- 'zh-cn': '所有装置的数目'
1657
+ type: 'state',
1658
+ common: {
1659
+ name: {
1660
+ en: 'Number of all devices',
1661
+ de: 'Anzahl aller Geräte',
1662
+ ru: 'Количество всех устройств',
1663
+ pt: 'Número de todos os dispositivos',
1664
+ nl: 'Nummer van alle apparaten',
1665
+ fr: 'Nombre de tous les appareils',
1666
+ it: 'Numero di tutti i dispositivi',
1667
+ es: 'Número de todos los dispositivos',
1668
+ pl: 'Ilość wszystkich urządzeń',
1669
+ 'zh-cn': '所有装置的数目',
1604
1670
  },
1605
- 'type': 'number',
1606
- 'role': 'value',
1607
- 'read': true,
1608
- 'write': false,
1671
+ type: 'number',
1672
+ role: 'value',
1673
+ read: true,
1674
+ write: false,
1609
1675
  },
1610
- 'native': {}
1676
+ native: {},
1611
1677
  });
1612
1678
 
1613
1679
  await this.setObjectNotExistsAsync(`${adptName}.batteryList`, {
1614
- 'type': 'state',
1615
- 'common': {
1616
- 'name': {
1617
- 'en': 'List of devices with battery state',
1618
- 'de': 'Liste der Geräte mit Batteriezustand',
1619
- 'ru': 'Список устройств с состоянием батареи',
1620
- 'pt': 'Lista de dispositivos com estado da bateria',
1621
- 'nl': 'List van apparaten met batterij staat',
1622
- 'fr': 'Liste des appareils avec état de batterie',
1623
- 'it': 'Elenco dei dispositivi con stato della batteria',
1624
- 'es': 'Lista de dispositivos con estado de batería',
1625
- 'pl': 'Lista urządzeń z baterią stanową',
1626
- 'zh-cn': '电池国装置清单'
1680
+ type: 'state',
1681
+ common: {
1682
+ name: {
1683
+ en: 'List of devices with battery state',
1684
+ de: 'Liste der Geräte mit Batteriezustand',
1685
+ ru: 'Список устройств с состоянием батареи',
1686
+ pt: 'Lista de dispositivos com estado da bateria',
1687
+ nl: 'List van apparaten met batterij staat',
1688
+ fr: 'Liste des appareils avec état de batterie',
1689
+ it: 'Elenco dei dispositivi con stato della batteria',
1690
+ es: 'Lista de dispositivos con estado de batería',
1691
+ pl: 'Lista urządzeń z baterią stanową',
1692
+ 'zh-cn': '电池国装置清单',
1627
1693
  },
1628
- 'type': 'array',
1629
- 'role': 'json',
1630
- 'read': true,
1631
- 'write': false,
1694
+ type: 'array',
1695
+ role: 'json',
1696
+ read: true,
1697
+ write: false,
1632
1698
  },
1633
- 'native': {}
1699
+ native: {},
1634
1700
  });
1635
1701
 
1636
1702
  await this.setObjectNotExistsAsync(`${adptName}.lowBatteryList`, {
1637
- 'type': 'state',
1638
- 'common': {
1639
- 'name': {
1640
- 'en': 'List of devices with low battery state',
1641
- 'de': 'Liste der Geräte mit niedrigem Batteriezustand',
1642
- 'ru': 'Список устройств с низким состоянием батареи',
1643
- 'pt': 'Lista de dispositivos com baixo estado da bateria',
1644
- 'nl': 'List van apparaten met lage batterij staat',
1645
- 'fr': 'Liste des appareils à faible état de batterie',
1646
- 'it': 'Elenco di dispositivi con stato di batteria basso',
1647
- 'es': 'Lista de dispositivos con estado de batería bajo',
1648
- 'pl': 'Lista urządzeń o niskim stanie baterii',
1649
- 'zh-cn': '低电池国家装置清单'
1703
+ type: 'state',
1704
+ common: {
1705
+ name: {
1706
+ en: 'List of devices with low battery state',
1707
+ de: 'Liste der Geräte mit niedrigem Batteriezustand',
1708
+ ru: 'Список устройств с низким состоянием батареи',
1709
+ pt: 'Lista de dispositivos com baixo estado da bateria',
1710
+ nl: 'List van apparaten met lage batterij staat',
1711
+ fr: 'Liste des appareils à faible état de batterie',
1712
+ it: 'Elenco di dispositivi con stato di batteria basso',
1713
+ es: 'Lista de dispositivos con estado de batería bajo',
1714
+ pl: 'Lista urządzeń o niskim stanie baterii',
1715
+ 'zh-cn': '低电池国家装置清单',
1650
1716
  },
1651
- 'type': 'array',
1652
- 'role': 'json',
1653
- 'read': true,
1654
- 'write': false,
1717
+ type: 'array',
1718
+ role: 'json',
1719
+ read: true,
1720
+ write: false,
1655
1721
  },
1656
- 'native': {}
1722
+ native: {},
1657
1723
  });
1658
1724
 
1659
1725
  await this.setObjectNotExistsAsync(`${adptName}.lowBatteryCount`, {
1660
- 'type': 'state',
1661
- 'common': {
1662
- 'name': {
1663
- 'en': 'Number of devices with low battery',
1664
- 'de': 'Anzahl der Geräte mit niedriger Batterie',
1665
- 'ru': 'Количество устройств c низкой батареей',
1666
- 'pt': 'Número de dispositivos com bateria baixa',
1667
- 'nl': 'Nummer van apparaten met lage batterij',
1668
- 'fr': 'Nombre de dispositifs avec batterie basse',
1669
- 'it': 'Numero di dispositivi con batteria bassa',
1670
- 'es': 'Número de dispositivos con batería baja',
1671
- 'pl': 'Liczba urządzeń z niską baterią',
1672
- 'zh-cn': '低电池的装置数量'
1726
+ type: 'state',
1727
+ common: {
1728
+ name: {
1729
+ en: 'Number of devices with low battery',
1730
+ de: 'Anzahl der Geräte mit niedriger Batterie',
1731
+ ru: 'Количество устройств c низкой батареей',
1732
+ pt: 'Número de dispositivos com bateria baixa',
1733
+ nl: 'Nummer van apparaten met lage batterij',
1734
+ fr: 'Nombre de dispositifs avec batterie basse',
1735
+ it: 'Numero di dispositivi con batteria bassa',
1736
+ es: 'Número de dispositivos con batería baja',
1737
+ pl: 'Liczba urządzeń z niską baterią',
1738
+ 'zh-cn': '低电池的装置数量',
1673
1739
  },
1674
- 'type': 'number',
1675
- 'role': 'value',
1676
- 'read': true,
1677
- 'write': false,
1740
+ type: 'number',
1741
+ role: 'value',
1742
+ read: true,
1743
+ write: false,
1678
1744
  },
1679
- 'native': {}
1745
+ native: {},
1680
1746
  });
1681
1747
 
1682
1748
  await this.setObjectNotExistsAsync(`${adptName}.batteryCount`, {
1683
- 'type': 'state',
1684
- 'common': {
1685
- 'name': {
1686
- 'en': 'Number of devices with battery',
1687
- 'de': 'Anzahl der Geräte mit Batterie',
1688
- 'ru': 'Количество устройств c батареей',
1689
- 'pt': 'Número de dispositivos com bateria',
1690
- 'nl': 'Nummer van apparaten met batterij',
1691
- 'fr': 'Nombre de dispositifs avec batterie',
1692
- 'it': 'Numero di dispositivi con batteria',
1693
- 'es': 'Número de dispositivos con batería',
1694
- 'pl': 'Liczba urządzeń z baterią',
1695
- 'zh-cn': '电池的装置数量'
1749
+ type: 'state',
1750
+ common: {
1751
+ name: {
1752
+ en: 'Number of devices with battery',
1753
+ de: 'Anzahl der Geräte mit Batterie',
1754
+ ru: 'Количество устройств c батареей',
1755
+ pt: 'Número de dispositivos com bateria',
1756
+ nl: 'Nummer van apparaten met batterij',
1757
+ fr: 'Nombre de dispositifs avec batterie',
1758
+ it: 'Numero di dispositivi con batteria',
1759
+ es: 'Número de dispositivos con batería',
1760
+ pl: 'Liczba urządzeń z baterią',
1761
+ 'zh-cn': '电池的装置数量',
1696
1762
  },
1697
- 'type': 'number',
1698
- 'role': 'value',
1699
- 'read': true,
1700
- 'write': false,
1763
+ type: 'number',
1764
+ role: 'value',
1765
+ read: true,
1766
+ write: false,
1701
1767
  },
1702
- 'native': {}
1768
+ native: {},
1703
1769
  });
1704
1770
  }
1705
1771
 
@@ -1707,7 +1773,6 @@ class DeviceWatcher extends utils.Adapter {
1707
1773
  * @param {object} [adptName] - Adaptername of devices
1708
1774
  **/
1709
1775
  async createHtmlListDatapoints(adptName) {
1710
-
1711
1776
  let dpSubFolder;
1712
1777
  //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
1713
1778
  if (adptName) {
@@ -1717,95 +1782,95 @@ class DeviceWatcher extends utils.Adapter {
1717
1782
  }
1718
1783
 
1719
1784
  await this.setObjectNotExistsAsync(`${dpSubFolder}offlineListHTML`, {
1720
- 'type': 'state',
1721
- 'common': {
1722
- 'name': {
1723
- 'en': 'HTML List of offline devices',
1724
- 'de': 'HTML Liste der Offline-Geräte',
1725
- 'ru': 'HTML Список оффлайн устройств',
1726
- 'pt': 'HTML Lista de dispositivos off-line',
1727
- 'nl': 'HTML List van offline apparatuur',
1728
- 'fr': 'HTML Liste des dispositifs hors ligne',
1729
- 'it': 'HTML Elenco dei dispositivi offline',
1730
- 'es': 'HTML Lista de dispositivos sin conexión',
1731
- 'pl': 'HTML Lista urządzeń offline',
1732
- 'zh-cn': 'HTML 线装置清单'
1785
+ type: 'state',
1786
+ common: {
1787
+ name: {
1788
+ en: 'HTML List of offline devices',
1789
+ de: 'HTML Liste der Offline-Geräte',
1790
+ ru: 'HTML Список оффлайн устройств',
1791
+ pt: 'HTML Lista de dispositivos off-line',
1792
+ nl: 'HTML List van offline apparatuur',
1793
+ fr: 'HTML Liste des dispositifs hors ligne',
1794
+ it: 'HTML Elenco dei dispositivi offline',
1795
+ es: 'HTML Lista de dispositivos sin conexión',
1796
+ pl: 'HTML Lista urządzeń offline',
1797
+ 'zh-cn': 'HTML 线装置清单',
1733
1798
  },
1734
- 'type': 'string',
1735
- 'role': 'html',
1736
- 'read': true,
1737
- 'write': false,
1799
+ type: 'string',
1800
+ role: 'html',
1801
+ read: true,
1802
+ write: false,
1738
1803
  },
1739
- 'native': {}
1804
+ native: {},
1740
1805
  });
1741
1806
 
1742
1807
  await this.setObjectNotExistsAsync(`${dpSubFolder}linkQualityListHTML`, {
1743
- 'type': 'state',
1744
- 'common': {
1745
- 'name': {
1746
- 'en': 'HTML List of devices with signal strength',
1747
- 'de': 'HTML Liste der Geräte mit Signalstärke',
1748
- 'ru': 'HTML Список устройств с силой сигнала',
1749
- 'pt': 'HTML Lista de dispositivos com força de sinal',
1750
- 'nl': 'HTML List van apparaten met signaalkracht',
1751
- 'fr': 'HTML Liste des dispositifs avec force de signal',
1752
- 'it': 'HTML Elenco dei dispositivi con forza del segnale',
1753
- 'es': 'HTML Lista de dispositivos con fuerza de señal',
1754
- 'pl': 'HTML Lista urządzeń z siłą sygnałową',
1755
- 'zh-cn': 'HTML 具有信号实力的装置清单'
1808
+ type: 'state',
1809
+ common: {
1810
+ name: {
1811
+ en: 'HTML List of devices with signal strength',
1812
+ de: 'HTML Liste der Geräte mit Signalstärke',
1813
+ ru: 'HTML Список устройств с силой сигнала',
1814
+ pt: 'HTML Lista de dispositivos com força de sinal',
1815
+ nl: 'HTML List van apparaten met signaalkracht',
1816
+ fr: 'HTML Liste des dispositifs avec force de signal',
1817
+ it: 'HTML Elenco dei dispositivi con forza del segnale',
1818
+ es: 'HTML Lista de dispositivos con fuerza de señal',
1819
+ pl: 'HTML Lista urządzeń z siłą sygnałową',
1820
+ 'zh-cn': 'HTML 具有信号实力的装置清单',
1756
1821
  },
1757
- 'type': 'string',
1758
- 'role': 'value',
1759
- 'read': true,
1760
- 'write': false,
1822
+ type: 'string',
1823
+ role: 'value',
1824
+ read: true,
1825
+ write: false,
1761
1826
  },
1762
- 'native': {}
1827
+ native: {},
1763
1828
  });
1764
1829
 
1765
1830
  await this.setObjectNotExistsAsync(`${dpSubFolder}batteryListHTML`, {
1766
- 'type': 'state',
1767
- 'common': {
1768
- 'name': {
1769
- 'en': 'HTML List of devices with battery state',
1770
- 'de': 'HTML Liste der Geräte mit Batteriezustand',
1771
- 'ru': 'HTML Список устройств с состоянием батареи',
1772
- 'pt': 'HTML Lista de dispositivos com estado da bateria',
1773
- 'nl': 'HTML List van apparaten met batterij staat',
1774
- 'fr': 'HTML Liste des appareils avec état de batterie',
1775
- 'it': 'HTML Elenco dei dispositivi con stato della batteria',
1776
- 'es': 'HTML Lista de dispositivos con estado de batería',
1777
- 'pl': 'HTML Lista urządzeń z baterią stanową',
1778
- 'zh-cn': 'HTML 电池国装置清单'
1831
+ type: 'state',
1832
+ common: {
1833
+ name: {
1834
+ en: 'HTML List of devices with battery state',
1835
+ de: 'HTML Liste der Geräte mit Batteriezustand',
1836
+ ru: 'HTML Список устройств с состоянием батареи',
1837
+ pt: 'HTML Lista de dispositivos com estado da bateria',
1838
+ nl: 'HTML List van apparaten met batterij staat',
1839
+ fr: 'HTML Liste des appareils avec état de batterie',
1840
+ it: 'HTML Elenco dei dispositivi con stato della batteria',
1841
+ es: 'HTML Lista de dispositivos con estado de batería',
1842
+ pl: 'HTML Lista urządzeń z baterią stanową',
1843
+ 'zh-cn': 'HTML 电池国装置清单',
1779
1844
  },
1780
- 'type': 'string',
1781
- 'role': 'html',
1782
- 'read': true,
1783
- 'write': false,
1845
+ type: 'string',
1846
+ role: 'html',
1847
+ read: true,
1848
+ write: false,
1784
1849
  },
1785
- 'native': {}
1850
+ native: {},
1786
1851
  });
1787
1852
 
1788
1853
  await this.setObjectNotExistsAsync(`${dpSubFolder}lowBatteryListHTML`, {
1789
- 'type': 'state',
1790
- 'common': {
1791
- 'name': {
1792
- 'en': 'HTML List of devices with low battery state',
1793
- 'de': 'HTML Liste der Geräte mit niedrigem Batteriezustand',
1794
- 'ru': 'HTML Список устройств с низким состоянием батареи',
1795
- 'pt': 'HTML Lista de dispositivos com baixo estado da bateria',
1796
- 'nl': 'HTML List van apparaten met lage batterij staat',
1797
- 'fr': 'HTML Liste des appareils à faible état de batterie',
1798
- 'it': 'HTML Elenco di dispositivi con stato di batteria basso',
1799
- 'es': 'HTML Lista de dispositivos con estado de batería bajo',
1800
- 'pl': 'HTML Lista urządzeń o niskim stanie baterii',
1801
- 'zh-cn': 'HTML 低电池国家装置清单'
1854
+ type: 'state',
1855
+ common: {
1856
+ name: {
1857
+ en: 'HTML List of devices with low battery state',
1858
+ de: 'HTML Liste der Geräte mit niedrigem Batteriezustand',
1859
+ ru: 'HTML Список устройств с низким состоянием батареи',
1860
+ pt: 'HTML Lista de dispositivos com baixo estado da bateria',
1861
+ nl: 'HTML List van apparaten met lage batterij staat',
1862
+ fr: 'HTML Liste des appareils à faible état de batterie',
1863
+ it: 'HTML Elenco di dispositivi con stato di batteria basso',
1864
+ es: 'HTML Lista de dispositivos con estado de batería bajo',
1865
+ pl: 'HTML Lista urządzeń o niskim stanie baterii',
1866
+ 'zh-cn': 'HTML 低电池国家装置清单',
1802
1867
  },
1803
- 'type': 'string',
1804
- 'role': 'html',
1805
- 'read': true,
1806
- 'write': false,
1868
+ type: 'string',
1869
+ role: 'html',
1870
+ read: true,
1871
+ write: false,
1807
1872
  },
1808
- 'native': {}
1873
+ native: {},
1809
1874
  });
1810
1875
  }
1811
1876
 
@@ -1828,10 +1893,9 @@ class DeviceWatcher extends utils.Adapter {
1828
1893
  }
1829
1894
  } // <-- end of errorReporting
1830
1895
 
1831
-
1832
1896
  /**
1833
- * @param {() => void} callback
1834
- */
1897
+ * @param {() => void} callback
1898
+ */
1835
1899
  onUnload(callback) {
1836
1900
  try {
1837
1901
  if (this.refreshDataTimeout) {