iobroker.device-watcher 2.12.2 → 2.12.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/main.js CHANGED
@@ -5,10 +5,12 @@ const adapterName = require('./package.json').name.split('.').pop();
5
5
  const schedule = require('node-schedule');
6
6
  const arrApart = require('./lib/arrApart.js'); // list of supported adapters
7
7
  const translations = require('./lib/translations.js');
8
- const cronParser = require('cron-parser');
8
+ const tools = require('./lib/tools.js');
9
+ const crud = require('./lib/crud.js');
9
10
 
10
11
  // indicator if the adapter is running (for intervall/shedule)
11
12
  let isUnloaded = false;
13
+ const adapterUpdateListDP = 'admin.*.info.updatesJson';
12
14
 
13
15
  class DeviceWatcher extends utils.Adapter {
14
16
  constructor(options) {
@@ -21,7 +23,7 @@ class DeviceWatcher extends utils.Adapter {
21
23
  // instances and adapters
22
24
  // raw arrays
23
25
  this.listInstanceRaw = new Map();
24
- this.adapterUpdatesJsonRaw = new Map();
26
+ this.adapterUpdatesJsonRaw = [];
25
27
  this.listErrorInstanceRaw = [];
26
28
 
27
29
  // user arrays
@@ -88,6 +90,9 @@ class DeviceWatcher extends utils.Adapter {
88
90
  this.on('objectChange', this.onObjectChange.bind(this));
89
91
  this.on('message', this.onMessage.bind(this));
90
92
  this.on('unload', this.onUnload.bind(this));
93
+
94
+
95
+
91
96
  }
92
97
 
93
98
  /**
@@ -242,7 +247,7 @@ class DeviceWatcher extends utils.Adapter {
242
247
  for (const [id] of Object.entries(arrApart)) {
243
248
  if (this.configSetAdapter[id]) {
244
249
  this.selAdapter.push(arrApart[id]);
245
- this.adapterSelected.push(this.capitalize(id));
250
+ this.adapterSelected.push(tools.capitalize(id));
246
251
  }
247
252
  }
248
253
 
@@ -257,27 +262,27 @@ class DeviceWatcher extends utils.Adapter {
257
262
  }
258
263
 
259
264
  // create Blacklist
260
- await this.createBlacklist();
265
+ await crud.createBlacklist(this);
261
266
 
262
267
  // create user defined list with time of error for instances
263
- await this.createTimeListInstances();
268
+ await crud.createTimeListInstances(this);
264
269
 
265
270
  //create datapoints for each adapter if selected
266
271
  for (const [id] of Object.entries(arrApart)) {
267
272
  try {
268
273
  if (!this.configCreateOwnFolder) {
269
- await this.deleteDPsForEachAdapter(id);
270
- await this.deleteHtmlListDatapoints(id);
274
+ await crud.deleteDPsForEachAdapter(this, id);
275
+ await crud.deleteHtmlListDatapoints(this, id);
271
276
  } else {
272
277
  if (this.configSetAdapter && this.configSetAdapter[id]) {
273
- await this.createDPsForEachAdapter(id);
278
+ await crud.createDPsForEachAdapter(this, id);
274
279
  // create HTML list datapoints
275
280
  if (!this.configCreateHtmlList) {
276
- await this.deleteHtmlListDatapoints(id);
281
+ await crud.deleteHtmlListDatapoints(this, id);
277
282
  } else {
278
- await this.createHtmlListDatapoints(id);
283
+ await crud.createHtmlListDatapoints(this, id);
279
284
  }
280
- this.log.debug(`Created datapoints for ${this.capitalize(id)}`);
285
+ this.log.debug(`Created datapoints for ${tools.capitalize(id)}`);
281
286
  }
282
287
  }
283
288
  } catch (error) {
@@ -287,29 +292,28 @@ class DeviceWatcher extends utils.Adapter {
287
292
 
288
293
  // create HTML list datapoints
289
294
  if (!this.configCreateHtmlList) {
290
- await this.deleteHtmlListDatapoints();
291
- await this.deleteHtmlListDatapointsInstances();
295
+ await crud.deleteHtmlListDatapoints(this);
296
+ await crud.deleteHtmlListDatapointsInstances(this);
292
297
  } else {
293
- await this.createHtmlListDatapoints();
294
- if (this.config.checkAdapterInstances) await this.createHtmlListDatapointsInstances();
298
+ await crud.createHtmlListDatapoints(this);
299
+ if (this.config.checkAdapterInstances) await crud.createHtmlListDatapointsInstances(this);
295
300
  }
296
- if (!this.config.checkAdapterInstances) await this.deleteHtmlListDatapointsInstances();
301
+ if (!this.config.checkAdapterInstances) await crud.deleteHtmlListDatapointsInstances(this);
297
302
 
298
- // read data first at start
299
- // devices
300
- await this.main();
301
303
 
302
304
  // instances and adapters
303
305
  if (this.configCreateInstanceList) {
304
306
  // instances
305
- await this.createDPsForInstances();
307
+ await crud.createDPsForInstances(this);
306
308
  await this.getAllInstanceData();
307
309
  // adapter updates
308
- await this.createAdapterUpdateData();
310
+ await crud.createAdapterUpdateData(this, adapterUpdateListDP);
309
311
  } else {
310
- await this.deleteDPsForInstances();
312
+ await crud.deleteDPsForInstances(this);
311
313
  }
312
314
 
315
+ await this.main();
316
+
313
317
  // update last contact data in interval
314
318
  await this.refreshData();
315
319
 
@@ -330,12 +334,57 @@ class DeviceWatcher extends utils.Adapter {
330
334
 
331
335
  // send overview of instances with error
332
336
  if (this.config.checkSendInstanceFailedDaily) await this.sendScheduleNotifications('errorInstance');
333
- } catch (error) {
337
+
338
+ } catch (error) {
334
339
  this.log.error(`[onReady] - ${error}`);
335
340
  this.terminate ? this.terminate(15) : process.exit(15);
336
341
  }
337
342
  } // <-- onReady end
338
343
 
344
+ /**
345
+ * main function
346
+ */
347
+ async main() {
348
+ this.log.debug(`Function started main`);
349
+ this.mainRunning = true;
350
+
351
+ // cancel run if no adapter is selected
352
+ if (this.adapterSelected.length === 0) return;
353
+
354
+ // fill counts and lists of all selected adapter
355
+ try {
356
+ for (let i = 0; i < this.selAdapter.length; i++) {
357
+ await crud.createData(this, i);
358
+ await crud.createLists(this);
359
+ }
360
+ await crud.writeDatapoints(this); // fill the datapoints
361
+ this.log.debug(`Created and filled data for all adapters`);
362
+ } catch (error) {
363
+ this.log.error(`[main - create data of all adapter] - ${error}`);
364
+ }
365
+
366
+ // fill datapoints for each adapter if selected
367
+ if (this.configCreateOwnFolder) {
368
+ try {
369
+ for (const [id] of Object.entries(arrApart)) {
370
+ if (this.configSetAdapter && this.configSetAdapter[id]) {
371
+ for (const deviceData of this.listAllDevicesRaw.values()) {
372
+ // list device only if selected adapter matched with device
373
+ if (!deviceData.adapterID.includes(id)) continue;
374
+ await crud.createLists(this, id);
375
+ }
376
+ await crud.writeDatapoints(this, id); // fill the datapoints
377
+ this.log.debug(`Created and filled data for ${tools.capitalize(id)}`);
378
+ }
379
+ }
380
+ } catch (error) {
381
+ this.log.error(`[main - create and fill datapoints for each adapter] - ${error}`);
382
+ }
383
+ }
384
+ this.mainRunning = false;
385
+ this.log.debug(`Function finished: ${this.main.name}`);
386
+ } //<--End of main function
387
+
339
388
  // If you need to react to object changes, uncomment the following block and the corresponding line in the constructor.
340
389
  // You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`.
341
390
  //
@@ -517,50 +566,6 @@ class DeviceWatcher extends utils.Adapter {
517
566
  }
518
567
  }
519
568
 
520
- /**
521
- * main function
522
- */
523
- async main() {
524
- this.log.debug(`Function started: ${this.main.name}`);
525
- this.mainRunning = true;
526
-
527
- // cancel run if no adapter is selected
528
- if (this.adapterSelected.length === 0) return;
529
-
530
- // fill counts and lists of all selected adapter
531
- try {
532
- for (let i = 0; i < this.selAdapter.length; i++) {
533
- await this.createData(i);
534
- await this.createLists();
535
- }
536
- await this.writeDatapoints(); // fill the datapoints
537
- this.log.debug(`Created and filled data for all adapters`);
538
- } catch (error) {
539
- this.log.error(`[main - create data of all adapter] - ${error}`);
540
- }
541
-
542
- // fill datapoints for each adapter if selected
543
- if (this.configCreateOwnFolder) {
544
- try {
545
- for (const [id] of Object.entries(arrApart)) {
546
- if (this.configSetAdapter && this.configSetAdapter[id]) {
547
- for (const deviceData of this.listAllDevicesRaw.values()) {
548
- // list device only if selected adapter matched with device
549
- if (!deviceData.adapterID.includes(id)) continue;
550
- await this.createLists(id);
551
- }
552
- await this.writeDatapoints(id); // fill the datapoints
553
- this.log.debug(`Created and filled data for ${this.capitalize(id)}`);
554
- }
555
- }
556
- } catch (error) {
557
- this.log.error(`[main - create and fill datapoints for each adapter] - ${error}`);
558
- }
559
- }
560
- this.mainRunning = false;
561
- this.log.debug(`Function finished: ${this.main.name}`);
562
- } //<--End of main function
563
-
564
569
  /**
565
570
  * refresh data with interval
566
571
  * is neccessary to refresh lastContact data, especially of devices without state changes
@@ -570,17 +575,17 @@ class DeviceWatcher extends utils.Adapter {
570
575
  const nextTimeout = this.config.updateinterval * 1000;
571
576
 
572
577
  // devices data
573
- await this.checkLastContact();
574
- await this.createLists();
575
- await this.writeDatapoints();
578
+ await tools.checkLastContact(this);
579
+ await crud.createLists(this);
580
+ await crud.writeDatapoints(this);
576
581
 
577
582
  // devices data in own adapter folder
578
583
  if (this.configCreateOwnFolder) {
579
584
  for (const [id] of Object.entries(arrApart)) {
580
585
  if (this.configSetAdapter && this.configSetAdapter[id]) {
581
- await this.createLists(id);
582
- await this.writeDatapoints(id);
583
- this.log.debug(`Created and filled data for ${this.capitalize(id)}`);
586
+ await crud.createLists(this, id);
587
+ await crud.writeDatapoints(this, id);
588
+ this.log.debug(`Created and filled data for ${tools.capitalize(id)}`);
584
589
  }
585
590
  }
586
591
  }
@@ -603,366 +608,6 @@ class DeviceWatcher extends utils.Adapter {
603
608
  }, nextTimeout);
604
609
  } // <-- refreshData end
605
610
 
606
- /**
607
- * create blacklist
608
- */
609
- async createBlacklist() {
610
- this.log.debug(`Function started: ${this.createBlacklist.name}`);
611
-
612
- // DEVICES
613
- const myBlacklist = this.config.tableBlacklist;
614
- if (myBlacklist.length >= 1) {
615
- for (const i in myBlacklist) {
616
- try {
617
- const blacklistParse = this.parseData(myBlacklist[i].devices);
618
- // push devices in list to ignor device in lists
619
- if (myBlacklist[i].checkIgnorLists) {
620
- this.blacklistLists.push(blacklistParse.path);
621
- }
622
- if (myBlacklist[i].checkIgnorAdapterLists) {
623
- this.blacklistAdapterLists.push(blacklistParse.path);
624
- }
625
- // push devices in list to ignor device in notifications
626
- if (myBlacklist[i].checkIgnorNotify) {
627
- this.blacklistNotify.push(blacklistParse.path);
628
- }
629
- } catch (error) {
630
- this.log.error(`[createBlacklist] - ${error}`);
631
- }
632
- if (this.blacklistLists.length >= 1) this.log.info(`Found devices/services on blacklist for lists: ${this.blacklistLists}`);
633
- if (this.blacklistAdapterLists.length >= 1) this.log.info(`Found devices/services on blacklist for own adapter lists: ${this.blacklistAdapterLists}`);
634
- if (this.blacklistNotify.length >= 1) this.log.info(`Found devices/services on blacklist for notifications: ${this.blacklistNotify}`);
635
- }
636
- }
637
-
638
- // INSTANCES
639
- const myBlacklistInstances = this.config.tableBlacklistInstances;
640
- if (myBlacklistInstances.length >= 1) {
641
- for (const i in myBlacklistInstances) {
642
- try {
643
- const blacklistParse = this.parseData(myBlacklistInstances[i].instances);
644
- // push devices in list to ignor device in lists
645
- if (myBlacklistInstances[i].checkIgnorLists) {
646
- this.blacklistInstancesLists.push(blacklistParse.instanceID);
647
- }
648
- // push devices in list to ignor device in notifications
649
- if (myBlacklistInstances[i].checkIgnorNotify) {
650
- this.blacklistInstancesNotify.push(blacklistParse.instanceID);
651
- }
652
- } catch (error) {
653
- this.log.error(`[createBlacklist] - ${error}`);
654
- }
655
- }
656
- if (this.blacklistInstancesLists.length >= 1) this.log.info(`Found instances items on blacklist for lists: ${this.blacklistInstancesLists}`);
657
- if (this.blacklistInstancesNotify.length >= 1) this.log.info(`Found instances items on blacklist for notifications: ${this.blacklistInstancesNotify}`);
658
- }
659
- this.log.debug(`Function finished: ${this.createBlacklist.name}`);
660
- }
661
-
662
- /**
663
- * create list with time for instances
664
- */
665
- async createTimeListInstances() {
666
- // INSTANCES
667
- const userTimeListInstances = this.config.tableTimeInstance;
668
- if (userTimeListInstances.length >= 1) {
669
- for (const i in userTimeListInstances) {
670
- try {
671
- const userTimeListparse = this.parseData(userTimeListInstances[i].instancesTime);
672
- // push devices in list to ignor device in lists
673
- this.userTimeInstancesList.set(userTimeListparse.instanceName, {
674
- deactivationTime: userTimeListInstances[i].deactivationTime,
675
- errorTime: userTimeListInstances[i].errorTime,
676
- });
677
- } catch (error) {
678
- this.log.error(`[createTimeListInstances] - ${error}`);
679
- }
680
- }
681
- if (this.userTimeInstancesList.size >= 1) this.log.info(`Found instances items on lists for timesettings: ${Array.from(this.userTimeInstancesList.keys())}`);
682
- }
683
- }
684
-
685
- /**
686
- * @param {object} i - Device Object
687
- */
688
- async createData(i) {
689
- try {
690
- const devices = await this.getForeignStatesAsync(this.selAdapter[i].Selektor);
691
- const adapterID = this.selAdapter[i].adapterID;
692
-
693
- /*---------- Start of loop ----------*/
694
- for (const [id] of Object.entries(devices)) {
695
- if (id.endsWith('.')) continue;
696
- const mainSelector = id;
697
-
698
- /*=============================================
699
- = get Instanz =
700
- =============================================*/
701
- const instance = id.slice(0, id.indexOf('.') + 2);
702
-
703
- const instanceDeviceConnectionDP = `${instance}.info.connection`;
704
- const instancedeviceConnected = await this.getInitValue(instanceDeviceConnectionDP);
705
- this.subscribeForeignStates(instanceDeviceConnectionDP);
706
- this.subscribeForeignObjects(`${this.selAdapter[i].Selektor}`);
707
- // this.subscribeForeignObjects('*');
708
- //this.subscribeForeignStates('*');
709
- /*=============================================
710
- = Get device name =
711
- =============================================*/
712
- const deviceName = await this.getDeviceName(id, i);
713
-
714
- /*=============================================
715
- = Get adapter name =
716
- =============================================*/
717
- const adapter = this.selAdapter[i].adapter;
718
-
719
- /*=============================================
720
- = Get path to datapoints =
721
- =============================================*/
722
- const currDeviceString = id.slice(0, id.lastIndexOf('.') + 1 - 1);
723
- const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
724
-
725
- // subscribe to object device path
726
- this.subscribeForeignStates(currDeviceString);
727
-
728
- /*=============================================
729
- = Get signal strength =
730
- =============================================*/
731
- let deviceQualityDP = currDeviceString + this.selAdapter[i].rssiState;
732
- let deviceQualityState;
733
-
734
- switch (adapterID) {
735
- case 'mihomeVacuum':
736
- deviceQualityDP = shortCurrDeviceString + this.selAdapter[i].rssiState;
737
- deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
738
- break;
739
-
740
- case 'netatmo':
741
- deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
742
- if (!deviceQualityState) {
743
- deviceQualityDP = currDeviceString + this.selAdapter[i].rfState;
744
- deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
745
- }
746
- break;
747
-
748
- default:
749
- deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
750
- break;
751
- }
752
- //subscribe to states
753
- this.subscribeForeignStates(deviceQualityDP);
754
-
755
- const signalData = await this.calculateSignalStrength(deviceQualityState, adapterID);
756
- let linkQuality = signalData[0];
757
- const linkQualityRaw = signalData[1];
758
-
759
- /*=============================================
760
- = Get battery data =
761
- =============================================*/
762
- let deviceBatteryStateDP;
763
- let deviceBatteryState;
764
- let batteryHealth;
765
- let batteryHealthRaw;
766
- let batteryUnitRaw;
767
- let lowBatIndicator;
768
- let isBatteryDevice;
769
- let isLowBatDP;
770
- let faultReportingDP;
771
- let faultReportingState;
772
-
773
- const deviceChargerStateDP = currDeviceString + this.selAdapter[i].charger;
774
- const deviceChargerState = await this.getInitValue(deviceChargerStateDP);
775
-
776
- if (deviceChargerState === undefined || deviceChargerState === false) {
777
- // Get battery states
778
- switch (adapterID) {
779
- case 'hmrpc':
780
- deviceBatteryStateDP = currDeviceString + this.selAdapter[i].battery;
781
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
782
-
783
- if (deviceBatteryState === undefined) {
784
- deviceBatteryStateDP = shortCurrDeviceString + this.selAdapter[i].hmDNBattery;
785
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
786
- }
787
- break;
788
- case 'hueExt':
789
- case 'mihomeVacuum':
790
- case 'mqttNuki':
791
- case 'loqedSmartLock':
792
- deviceBatteryStateDP = shortCurrDeviceString + this.selAdapter[i].battery;
793
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
794
-
795
- if (deviceBatteryState === undefined) {
796
- deviceBatteryStateDP = shortCurrDeviceString + this.selAdapter[i].battery2;
797
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
798
- }
799
- break;
800
- default:
801
- deviceBatteryStateDP = currDeviceString + this.selAdapter[i].battery;
802
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
803
-
804
- if (deviceBatteryState === undefined) {
805
- deviceBatteryStateDP = currDeviceString + this.selAdapter[i].battery2;
806
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
807
-
808
- if (deviceBatteryState === undefined) {
809
- deviceBatteryStateDP = currDeviceString + this.selAdapter[i].battery3;
810
- deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
811
- }
812
- }
813
- break;
814
- }
815
-
816
- // Get low bat states
817
- isLowBatDP = currDeviceString + this.selAdapter[i].isLowBat;
818
- let deviceLowBatState = await this.getInitValue(isLowBatDP);
819
-
820
- if (deviceLowBatState === undefined) {
821
- isLowBatDP = currDeviceString + this.selAdapter[i].isLowBat2;
822
- deviceLowBatState = await this.getInitValue(isLowBatDP);
823
-
824
- if (deviceLowBatState === undefined) {
825
- isLowBatDP = currDeviceString + this.selAdapter[i].isLowBat3;
826
- deviceLowBatState = await this.getInitValue(isLowBatDP);
827
- }
828
- }
829
- if (deviceLowBatState === undefined) isLowBatDP = 'none';
830
-
831
- faultReportingDP = shortCurrDeviceString + this.selAdapter[i].faultReporting;
832
- faultReportingState = await this.getInitValue(faultReportingDP);
833
-
834
- //subscribe to states
835
- this.subscribeForeignStates(deviceBatteryStateDP);
836
- this.subscribeForeignStates(isLowBatDP);
837
- this.subscribeForeignStates(faultReportingDP);
838
-
839
- const batteryData = await this.getBatteryData(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
840
- batteryHealth = batteryData[0];
841
- batteryHealthRaw = batteryData[2];
842
- batteryUnitRaw = batteryData[3];
843
- isBatteryDevice = batteryData[1];
844
-
845
- if (isBatteryDevice) {
846
- lowBatIndicator = await this.setLowbatIndicator(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
847
- }
848
- }
849
-
850
- /*=============================================
851
- = Get last contact of device =
852
- =============================================*/
853
- let unreachDP = currDeviceString + this.selAdapter[i].reach;
854
- const deviceStateSelectorDP = shortCurrDeviceString + this.selAdapter[i].stateValue;
855
- const rssiPeerSelectorDP = currDeviceString + this.selAdapter[i].rssiPeerState;
856
- let timeSelector = currDeviceString + this.selAdapter[i].timeSelector;
857
-
858
- const timeSelectorState = await this.getInitValue(timeSelector);
859
- if (timeSelectorState === undefined) {
860
- timeSelector = shortCurrDeviceString + this.selAdapter[i].timeSelector;
861
- }
862
-
863
- let deviceUnreachState = await this.getInitValue(unreachDP);
864
- if (deviceUnreachState === undefined) {
865
- unreachDP = shortCurrDeviceString + this.selAdapter[i].reach;
866
- deviceUnreachState = await this.getInitValue(shortCurrDeviceString + this.selAdapter[i].reach);
867
- }
868
-
869
- // subscribe to states
870
- this.subscribeForeignStates(timeSelector);
871
- this.subscribeForeignStates(unreachDP);
872
- this.subscribeForeignStates(deviceStateSelectorDP);
873
- this.subscribeForeignStates(rssiPeerSelectorDP);
874
-
875
- const onlineState = await this.getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorDP, rssiPeerSelectorDP);
876
- let deviceState;
877
- let lastContactString;
878
-
879
- if (onlineState) {
880
- lastContactString = onlineState[0];
881
- deviceState = onlineState[1];
882
- linkQuality = onlineState[2];
883
- }
884
-
885
- /*=============================================
886
- = Get update data =
887
- =============================================*/
888
- let isUpgradable;
889
- let deviceUpdateDP;
890
-
891
- if (this.config.checkSendDeviceUpgrade) {
892
- deviceUpdateDP = currDeviceString + this.selAdapter[i].upgrade;
893
- let deviceUpdateSelector = await this.getInitValue(deviceUpdateDP);
894
- if (deviceUpdateSelector === undefined) {
895
- deviceUpdateDP = shortCurrDeviceString + this.selAdapter[i].upgrade;
896
- deviceUpdateSelector = await this.getInitValue(deviceUpdateDP);
897
- if (deviceUpdateSelector === undefined) {
898
- const shortShortCurrDeviceString = shortCurrDeviceString.slice(0, shortCurrDeviceString.lastIndexOf('.') + 1 - 1);
899
- deviceUpdateDP = shortShortCurrDeviceString + this.selAdapter[i].upgrade;
900
- deviceUpdateSelector = await this.getInitValue(deviceUpdateDP);
901
- }
902
- }
903
-
904
- if (deviceUpdateSelector !== undefined) {
905
- isUpgradable = await this.checkDeviceUpdate(adapterID, deviceUpdateSelector);
906
- } else {
907
- isUpgradable = ' - ';
908
- }
909
-
910
- // subscribe to states
911
- this.subscribeForeignStates(deviceUpdateDP);
912
- // this.subscribeForeignStates('*');
913
- }
914
-
915
- /*=============================================
916
- = Fill Raw Lists =
917
- =============================================*/
918
- const setupList = () => {
919
- this.listAllDevicesRaw.set(currDeviceString, {
920
- Path: id,
921
- mainSelector: mainSelector,
922
- instanceDeviceConnectionDP: instanceDeviceConnectionDP,
923
- instancedeviceConnected: instancedeviceConnected,
924
- instance: instance,
925
- Device: deviceName,
926
- adapterID: adapterID,
927
- Adapter: adapter,
928
- timeSelector: timeSelector,
929
- isBatteryDevice: isBatteryDevice,
930
- Battery: batteryHealth,
931
- BatteryRaw: batteryHealthRaw,
932
- BatteryUnitRaw: batteryUnitRaw,
933
- batteryDP: deviceBatteryStateDP,
934
- LowBat: lowBatIndicator,
935
- LowBatDP: isLowBatDP,
936
- faultReport: faultReportingState,
937
- faultReportDP: faultReportingDP,
938
- SignalStrengthDP: deviceQualityDP,
939
- SignalStrength: linkQuality,
940
- SignalStrengthRaw: linkQualityRaw,
941
- UnreachState: deviceUnreachState,
942
- UnreachDP: unreachDP,
943
- DeviceStateSelectorDP: deviceStateSelectorDP,
944
- rssiPeerSelectorDP: rssiPeerSelectorDP,
945
- LastContact: lastContactString,
946
- Status: deviceState,
947
- UpdateDP: deviceUpdateDP,
948
- Upgradable: isUpgradable,
949
- });
950
- };
951
-
952
- if (!this.configListOnlyBattery) {
953
- // Add all devices
954
- setupList();
955
- } else {
956
- // Add only devices with battery in the rawlist
957
- if (!isBatteryDevice) continue;
958
- setupList();
959
- }
960
- } // <-- end of loop
961
- } catch (error) {
962
- this.log.error(`[createData - create data of devices] - ${error}`);
963
- }
964
- } // <-- end of createData
965
-
966
611
  /*=============================================
967
612
  = functions to get data =
968
613
  =============================================*/
@@ -989,7 +634,7 @@ class DeviceWatcher extends utils.Adapter {
989
634
 
990
635
  switch (this.selAdapter[i].adapterID) {
991
636
  case 'fullybrowser':
992
- deviceName = (await this.getInitValue(currDeviceString + this.selAdapter[i].id)) + ' ' + (await this.getInitValue(currDeviceString + this.selAdapter[i].id2));
637
+ deviceName = (await tools.getInitValue(this,currDeviceString + this.selAdapter[i].id)) + ' ' + (await tools.getInitValue(this,currDeviceString + this.selAdapter[i].id2));
993
638
  break;
994
639
 
995
640
  // Get ID with short currDeviceString from objectjson
@@ -1018,7 +663,7 @@ class DeviceWatcher extends utils.Adapter {
1018
663
  case 'mihomeVacuum':
1019
664
  case 'roomba':
1020
665
  folderName = shortCurrDeviceString.slice(shortCurrDeviceString.lastIndexOf('.') + 1);
1021
- deviceID = await this.getInitValue(shortCurrDeviceString + this.selAdapter[i].id);
666
+ deviceID = await tools.getInitValue(this,shortCurrDeviceString + this.selAdapter[i].id);
1022
667
  deviceName = `I${folderName} ${deviceID}`;
1023
668
  break;
1024
669
 
@@ -1026,6 +671,7 @@ class DeviceWatcher extends utils.Adapter {
1026
671
  case 'tado':
1027
672
  case 'wifilight':
1028
673
  case 'fullybrowserV3':
674
+ case 'sonoff':
1029
675
  deviceName = currDeviceString.slice(currDeviceString.lastIndexOf('.') + 1);
1030
676
  break;
1031
677
 
@@ -1049,7 +695,7 @@ class DeviceWatcher extends utils.Adapter {
1049
695
 
1050
696
  // Get ID with main selektor from objectjson
1051
697
  default:
1052
- if (this.selAdapter[i].id !== 'none' || this.selAdapter[i].id !== undefined) deviceName = await this.getInitValue(currDeviceString + this.selAdapter[i].id);
698
+ if (this.selAdapter[i].id !== 'none' || this.selAdapter[i].id !== undefined) deviceName = await tools.getInitValue(this,currDeviceString + this.selAdapter[i].id);
1053
699
  if (deviceName === null || deviceName === undefined) {
1054
700
  if (deviceObject && typeof deviceObject === 'object' && deviceObject.common) {
1055
701
  deviceName = deviceObject.common.name;
@@ -1262,7 +908,7 @@ class DeviceWatcher extends utils.Adapter {
1262
908
  * @param {object} selector - Selector
1263
909
  */
1264
910
  async getLastContact(selector) {
1265
- const lastContact = this.getTimestamp(selector);
911
+ const lastContact = tools.getTimestamp(selector);
1266
912
  let lastContactString;
1267
913
 
1268
914
  lastContactString = `${this.formatDate(new Date(selector), 'hh:mm')}`;
@@ -1282,19 +928,29 @@ class DeviceWatcher extends utils.Adapter {
1282
928
  * @param {string} unreachDP - Datapoint of Unreach
1283
929
  * @param {object} linkQuality - Linkquality Value
1284
930
  * @param {object} deviceUnreachState - State of deviceUnreach datapoint
1285
- * @param {string} deviceStateSelectorDP - Selector of device state (like .state)
1286
- * @param {string} rssiPeerSelectorDP - HM RSSI Peer Datapoint
931
+ * @param {string} deviceStateSelectorHMRPC - Selector of device state (like .state)
932
+ * @param {string} rssiPeerSelectorHMRPC - HM RSSI Peer Datapoint
1287
933
  */
1288
- async getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorDP, rssiPeerSelectorDP) {
934
+ async getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorHMRPC, rssiPeerSelectorHMRPC) {
1289
935
  let lastContactString;
1290
936
  let deviceState = 'Online';
1291
937
 
1292
938
  try {
1293
939
  const deviceTimeSelector = await this.getForeignStateAsync(timeSelector);
1294
940
  const deviceUnreachSelector = await this.getForeignStateAsync(unreachDP);
1295
- const deviceStateSelector = await this.getForeignStateAsync(deviceStateSelectorDP); // for hmrpc devices
1296
- const rssiPeerSelector = await this.getForeignStateAsync(rssiPeerSelectorDP);
1297
- const lastDeviceUnreachStateChange = deviceUnreachSelector != undefined ? this.getTimestamp(deviceUnreachSelector.lc) : this.getTimestamp(timeSelector.ts);
941
+ const deviceStateSelector = await this.getForeignStateAsync(deviceStateSelectorHMRPC); // for hmrpc devices
942
+ const rssiPeerSelector = await this.getForeignStateAsync(rssiPeerSelectorHMRPC);
943
+ const lastDeviceUnreachStateChange = deviceUnreachSelector != undefined ? tools.getTimestamp(deviceUnreachSelector.lc) : tools.getTimestamp(timeSelector.ts);
944
+
945
+ // ignore disabled device from zigbee2MQTT
946
+ if (adapterID === 'zigbee2MQTT') {
947
+ const is_device_disabled = await tools.isDisabledDevice(this, unreachDP.substring(0, unreachDP.lastIndexOf('.')));
948
+
949
+ if (is_device_disabled) {
950
+ return [null, 'disabled', '0%'];
951
+ }
952
+ }
953
+
1298
954
  // If there is no contact since user sets minutes add device in offline list
1299
955
  // calculate to days after 48 hours
1300
956
  switch (unreachDP) {
@@ -1334,7 +990,7 @@ class DeviceWatcher extends utils.Adapter {
1334
990
  = Set Online Status =
1335
991
  =============================================*/
1336
992
  let lastContact;
1337
- if (deviceTimeSelector) lastContact = this.getTimestamp(deviceTimeSelector.ts);
993
+ if (deviceTimeSelector) lastContact = tools.getTimestamp(deviceTimeSelector.ts);
1338
994
 
1339
995
  if (this.configMaxMinutes !== undefined) {
1340
996
  switch (adapterID) {
@@ -1457,38 +1113,6 @@ class DeviceWatcher extends utils.Adapter {
1457
1113
  }
1458
1114
  }
1459
1115
 
1460
- /**
1461
- * when was last contact of device
1462
- */
1463
- async checkLastContact() {
1464
- for (const [deviceID, deviceData] of this.listAllDevicesRaw.entries()) {
1465
- if (deviceData.instancedeviceConnected !== false) {
1466
- const oldContactState = deviceData.Status;
1467
- deviceData.UnreachState = await this.getInitValue(deviceData.UnreachDP);
1468
- const contactData = await this.getOnlineState(
1469
- deviceData.timeSelector,
1470
- deviceData.adapterID,
1471
- deviceData.UnreachDP,
1472
- deviceData.SignalStrength,
1473
- deviceData.UnreachState,
1474
- deviceData.DeviceStateSelectorDP,
1475
- deviceData.rssiPeerSelectorDP,
1476
- );
1477
- if (contactData !== undefined) {
1478
- deviceData.LastContact = contactData[0];
1479
- deviceData.Status = contactData[1];
1480
- deviceData.linkQuality = contactData[2];
1481
- }
1482
- if (this.config.checkSendOfflineMsg && oldContactState !== deviceData.Status && !this.blacklistNotify.includes(deviceData.Path)) {
1483
- // check if the generally deviceData connected state is for a while true
1484
- if (await this.getTimestampConnectionDP(deviceData.instanceDeviceConnectionDP, 50000)) {
1485
- await this.sendStateNotifications('Devices', 'onlineStateDevice', deviceID);
1486
- }
1487
- }
1488
- }
1489
- }
1490
- }
1491
-
1492
1116
  /**
1493
1117
  * @param {any} adapterID
1494
1118
  * @param {string | number | boolean | null} deviceUpdateSelector
@@ -1525,402 +1149,91 @@ class DeviceWatcher extends utils.Adapter {
1525
1149
  }
1526
1150
 
1527
1151
  /**
1528
- * Create Lists
1529
- * @param {string | undefined} [adptName]
1152
+ * fill the lists for user
1153
+ * @param {object} device
1530
1154
  */
1531
- async createLists(adptName) {
1532
- this.linkQualityDevices = [];
1533
- this.batteryPowered = [];
1534
- this.batteryLowPowered = [];
1535
- this.listAllDevicesUserRaw = [];
1536
- this.listAllDevices = [];
1537
- this.offlineDevices = [];
1538
- this.batteryLowPoweredRaw = [];
1539
- this.offlineDevicesRaw = [];
1540
- this.upgradableDevicesRaw = [];
1541
- this.upgradableList = [];
1155
+ async theLists(device) {
1156
+ // Raw List with all devices for user
1157
+ if (device.Status !== 'disabled') {
1158
+
1159
+ this.listAllDevicesUserRaw.push({
1160
+ Device: device.Device,
1161
+ Adapter: device.Adapter,
1162
+ Instance: device.instance,
1163
+ 'Instance connected': device.instancedeviceConnected,
1164
+ isBatteryDevice: device.isBatteryDevice,
1165
+ Battery: device.Battery,
1166
+ BatteryRaw: device.BatteryRaw,
1167
+ BatteryUnitRaw: device.BatteryUnitRaw,
1168
+ isLowBat: device.LowBat,
1169
+ 'Signal strength': device.SignalStrength,
1170
+ 'Signal strength Raw': device.SignalStrengthRaw,
1171
+ 'Last contact': device.LastContact,
1172
+ 'Update Available': device.Upgradable,
1173
+ Status: device.Status,
1174
+ });
1542
1175
 
1543
- if (adptName === undefined) {
1544
- adptName = '';
1545
- }
1176
+ // List with all devices
1177
+ this.listAllDevices.push({
1178
+ [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1179
+ [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1180
+ [translations.Battery[this.config.userSelectedLanguage]]: device.Battery,
1181
+ [translations.Signal_strength[this.config.userSelectedLanguage]]: device.SignalStrength,
1182
+ [translations.Last_Contact[this.config.userSelectedLanguage]]: device.LastContact,
1183
+ [translations.Status[this.config.userSelectedLanguage]]: device.Status,
1184
+ });
1546
1185
 
1547
- for (const deviceData of this.listAllDevicesRaw.values()) {
1548
- /*---------- fill raw lists ----------*/
1549
- // low bat list
1550
- if (deviceData.LowBat && deviceData.Status !== 'Offline') {
1551
- this.batteryLowPoweredRaw.push({
1552
- Path: deviceData.Path,
1553
- Device: deviceData.Device,
1554
- Adapter: deviceData.Adapter,
1555
- Battery: deviceData.Battery,
1186
+ // LinkQuality lists
1187
+ if (device.SignalStrength != ' - ') {
1188
+ this.linkQualityDevices.push({
1189
+ [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1190
+ [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1191
+ [translations.Signal_strength[this.config.userSelectedLanguage]]: device.SignalStrength,
1556
1192
  });
1557
1193
  }
1558
- // offline raw list
1559
- if (deviceData.Status === 'Offline') {
1560
- this.offlineDevicesRaw.push({
1561
- Path: deviceData.Path,
1562
- Device: deviceData.Device,
1563
- Adapter: deviceData.Adapter,
1564
- LastContact: deviceData.LastContact,
1194
+
1195
+ // Battery lists
1196
+ if (device.isBatteryDevice) {
1197
+ this.batteryPowered.push({
1198
+ [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1199
+ [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1200
+ [translations.Battery[this.config.userSelectedLanguage]]: device.Battery,
1201
+ [translations.Status[this.config.userSelectedLanguage]]: device.Status,
1565
1202
  });
1566
1203
  }
1567
1204
 
1568
- // upgradable raw list
1569
- if (deviceData.Upgradable === true) {
1570
- this.upgradableDevicesRaw.push({
1571
- Path: deviceData.Path,
1572
- Device: deviceData.Device,
1573
- Adapter: deviceData.Adapter,
1205
+ // Low Bat lists
1206
+ if (device.LowBat && device.Status !== 'Offline') {
1207
+ this.batteryLowPowered.push({
1208
+ [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1209
+ [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1210
+ [translations.Battery[this.config.userSelectedLanguage]]: device.Battery,
1574
1211
  });
1575
1212
  }
1576
1213
 
1577
- if (adptName === '' && !this.blacklistLists.includes(deviceData.Path)) {
1578
- await this.theLists(deviceData);
1214
+ // Offline List
1215
+ if (device.Status === 'Offline') {
1216
+ this.offlineDevices.push({
1217
+ [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1218
+ [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1219
+ [translations.Last_Contact[this.config.userSelectedLanguage]]: device.LastContact,
1220
+ });
1579
1221
  }
1580
1222
 
1581
- if (this.config.createOwnFolder && adptName !== '') {
1582
- if (!deviceData.adapterID.includes(adptName)) continue;
1583
- /*---------- fill user lists for each adapter ----------*/
1584
- if (this.blacklistAdapterLists.includes(deviceData.Path)) continue;
1585
- await this.theLists(deviceData);
1223
+ // Device update List
1224
+ if (device.Upgradable === true || device.Upgradable === 1) {
1225
+ this.upgradableList.push({
1226
+ [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1227
+ [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1228
+ });
1586
1229
  }
1587
1230
  }
1588
- await this.countDevices();
1589
1231
  }
1590
1232
 
1233
+
1591
1234
  /**
1592
- * fill the lists for user
1593
- * @param {object} device
1594
- */
1595
- async theLists(device) {
1596
- // Raw List with all devices for user
1597
- this.listAllDevicesUserRaw.push({
1598
- Device: device.Device,
1599
- Adapter: device.Adapter,
1600
- Instance: device.instance,
1601
- 'Instance connected': device.instancedeviceConnected,
1602
- isBatteryDevice: device.isBatteryDevice,
1603
- Battery: device.Battery,
1604
- BatteryRaw: device.BatteryRaw,
1605
- BatteryUnitRaw: device.BatteryUnitRaw,
1606
- isLowBat: device.LowBat,
1607
- 'Signal strength': device.SignalStrength,
1608
- 'Signal strength Raw': device.SignalStrengthRaw,
1609
- 'Last contact': device.LastContact,
1610
- 'Update Available': device.Upgradable,
1611
- Status: device.Status,
1612
- });
1613
-
1614
- // List with all devices
1615
- this.listAllDevices.push({
1616
- [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1617
- [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1618
- [translations.Battery[this.config.userSelectedLanguage]]: device.Battery,
1619
- [translations.Signal_strength[this.config.userSelectedLanguage]]: device.SignalStrength,
1620
- [translations.Last_Contact[this.config.userSelectedLanguage]]: device.LastContact,
1621
- [translations.Status[this.config.userSelectedLanguage]]: device.Status,
1622
- });
1623
-
1624
- // LinkQuality lists
1625
- if (device.SignalStrength != ' - ') {
1626
- this.linkQualityDevices.push({
1627
- [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1628
- [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1629
- [translations.Signal_strength[this.config.userSelectedLanguage]]: device.SignalStrength,
1630
- });
1631
- }
1632
-
1633
- // Battery lists
1634
- if (device.isBatteryDevice) {
1635
- this.batteryPowered.push({
1636
- [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1637
- [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1638
- [translations.Battery[this.config.userSelectedLanguage]]: device.Battery,
1639
- [translations.Status[this.config.userSelectedLanguage]]: device.Status,
1640
- });
1641
- }
1642
-
1643
- // Low Bat lists
1644
- if (device.LowBat && device.Status !== 'Offline') {
1645
- this.batteryLowPowered.push({
1646
- [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1647
- [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1648
- [translations.Battery[this.config.userSelectedLanguage]]: device.Battery,
1649
- });
1650
- }
1651
-
1652
- // Offline List
1653
- if (device.Status === 'Offline') {
1654
- this.offlineDevices.push({
1655
- [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1656
- [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1657
- [translations.Last_Contact[this.config.userSelectedLanguage]]: device.LastContact,
1658
- });
1659
- }
1660
-
1661
- // Device update List
1662
- if (device.Upgradable === true || device.Upgradable === 1) {
1663
- this.upgradableList.push({
1664
- [translations.Device[this.config.userSelectedLanguage]]: device.Device,
1665
- [translations.Adapter[this.config.userSelectedLanguage]]: device.Adapter,
1666
- });
1667
- }
1668
- }
1669
-
1670
- /**
1671
- * Count devices for each type
1672
- */
1673
- async countDevices() {
1674
- // Count how many devices with link Quality
1675
- this.linkQualityCount = this.linkQualityDevices.length;
1676
-
1677
- // Count how many devcies are offline
1678
- this.offlineDevicesCount = this.offlineDevices.length;
1679
-
1680
- // Count how many devices are with battery
1681
- this.batteryPoweredCount = this.batteryPowered.length;
1682
-
1683
- // 3d. Count how many devices are with low battery
1684
- this.lowBatteryPoweredCount = this.batteryLowPowered.length;
1685
-
1686
- // Count how many devices are exists
1687
- this.deviceCounter = this.listAllDevices.length;
1688
-
1689
- // Count how many devices has update available
1690
- this.upgradableDevicesCount = this.upgradableList.length;
1691
- }
1692
-
1693
- /**
1694
- * @param {string} [adptName] - Adaptername
1695
- */
1696
- async writeDatapoints(adptName) {
1697
- // fill the datapoints
1698
- this.log.debug(`Start the function: ${this.writeDatapoints.name}`);
1699
-
1700
- try {
1701
- let dpSubFolder;
1702
- //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
1703
- if (adptName) {
1704
- dpSubFolder = adptName + '.';
1705
- } else {
1706
- dpSubFolder = '';
1707
- }
1708
-
1709
- // Write Datapoints for counts
1710
- await this.setStateChangedAsync(`devices.${dpSubFolder}offlineCount`, { val: this.offlineDevicesCount, ack: true });
1711
- await this.setStateChangedAsync(`devices.${dpSubFolder}countAll`, { val: this.deviceCounter, ack: true });
1712
- await this.setStateChangedAsync(`devices.${dpSubFolder}batteryCount`, { val: this.batteryPoweredCount, ack: true });
1713
- await this.setStateChangedAsync(`devices.${dpSubFolder}lowBatteryCount`, { val: this.lowBatteryPoweredCount, ack: true });
1714
- await this.setStateChangedAsync(`devices.${dpSubFolder}upgradableCount`, { val: this.upgradableDevicesCount, ack: true });
1715
- // List all devices
1716
- if (this.deviceCounter === 0) {
1717
- // if no device is count, write the JSON List with default value
1718
- this.listAllDevices = [
1719
- {
1720
- [translations.Device[this.config.userSelectedLanguage]]: '--none--',
1721
- [translations.Adapter[this.config.userSelectedLanguage]]: '',
1722
- [translations.Battery[this.config.userSelectedLanguage]]: '',
1723
- [translations.Signal_strength[this.config.userSelectedLanguage]]: '',
1724
- [translations.Last_Contact[this.config.userSelectedLanguage]]: '',
1725
- [translations.Status[this.config.userSelectedLanguage]]: '',
1726
- },
1727
- ];
1728
- this.listAllDevicesUserRaw = [
1729
- {
1730
- Device: '--none--',
1731
- Adapter: '',
1732
- Instance: '',
1733
- 'Instance connected': '',
1734
- isBatteryDevice: '',
1735
- Battery: '',
1736
- BatteryRaw: '',
1737
- isLowBat: '',
1738
- 'Signal strength': '',
1739
- 'Last contact': '',
1740
- UpdateAvailable: '',
1741
- Status: '',
1742
- },
1743
- ];
1744
- }
1745
- await this.setStateChangedAsync(`devices.${dpSubFolder}listAll`, { val: JSON.stringify(this.listAllDevices), ack: true });
1746
- await this.setStateChangedAsync(`devices.${dpSubFolder}listAllRawJSON`, { val: JSON.stringify(this.listAllDevicesUserRaw), ack: true });
1747
-
1748
- // List link quality
1749
- if (this.linkQualityCount === 0) {
1750
- // if no device is count, write the JSON List with default value
1751
- this.linkQualityDevices = [
1752
- {
1753
- [translations.Device[this.config.userSelectedLanguage]]: '--none--',
1754
- [translations.Adapter[this.config.userSelectedLanguage]]: '',
1755
- [translations.Signal_strength[this.config.userSelectedLanguage]]: '',
1756
- },
1757
- ];
1758
- }
1759
- //write JSON list
1760
- await this.setStateChangedAsync(`devices.${dpSubFolder}linkQualityList`, {
1761
- val: JSON.stringify(this.linkQualityDevices),
1762
- ack: true,
1763
- });
1764
-
1765
- // List offline devices
1766
- if (this.offlineDevicesCount === 0) {
1767
- // if no device is count, write the JSON List with default value
1768
- this.offlineDevices = [
1769
- {
1770
- [translations.Device[this.config.userSelectedLanguage]]: '--none--',
1771
- [translations.Adapter[this.config.userSelectedLanguage]]: '',
1772
- [translations.Last_Contact[this.config.userSelectedLanguage]]: '',
1773
- },
1774
- ];
1775
- }
1776
- //write JSON list
1777
- await this.setStateChangedAsync(`devices.${dpSubFolder}offlineList`, {
1778
- val: JSON.stringify(this.offlineDevices),
1779
- ack: true,
1780
- });
1781
-
1782
- // List updatable
1783
- if (this.upgradableDevicesCount === 0) {
1784
- // if no device is count, write the JSON List with default value
1785
- this.upgradableList = [
1786
- {
1787
- [translations.Device[this.config.userSelectedLanguage]]: '--none--',
1788
- [translations.Adapter[this.config.userSelectedLanguage]]: '',
1789
- [translations.Last_Contact[this.config.userSelectedLanguage]]: '',
1790
- },
1791
- ];
1792
- }
1793
- //write JSON list
1794
- await this.setStateChangedAsync(`devices.${dpSubFolder}upgradableList`, {
1795
- val: JSON.stringify(this.upgradableList),
1796
- ack: true,
1797
- });
1798
-
1799
- // List battery powered
1800
- if (this.batteryPoweredCount === 0) {
1801
- // if no device is count, write the JSON List with default value
1802
- this.batteryPowered = [
1803
- {
1804
- [translations.Device[this.config.userSelectedLanguage]]: '--none--',
1805
- [translations.Adapter[this.config.userSelectedLanguage]]: '',
1806
- [translations.Battery[this.config.userSelectedLanguage]]: '',
1807
- },
1808
- ];
1809
- }
1810
- //write JSON list
1811
- await this.setStateChangedAsync(`devices.${dpSubFolder}batteryList`, {
1812
- val: JSON.stringify(this.batteryPowered),
1813
- ack: true,
1814
- });
1815
-
1816
- // list battery low powered
1817
- if (this.lowBatteryPoweredCount === 0) {
1818
- // if no device is count, write the JSON List with default value
1819
- this.batteryLowPowered = [
1820
- {
1821
- [translations.Device[this.config.userSelectedLanguage]]: '--none--',
1822
- [translations.Adapter[this.config.userSelectedLanguage]]: '',
1823
- [translations.Battery[this.config.userSelectedLanguage]]: '',
1824
- },
1825
- ];
1826
- }
1827
- //write JSON list
1828
- await this.setStateChangedAsync(`devices.${dpSubFolder}lowBatteryList`, {
1829
- val: JSON.stringify(this.batteryLowPowered),
1830
- ack: true,
1831
- });
1832
-
1833
- // set booleans datapoints
1834
- if (this.offlineDevicesCount === 0) {
1835
- await this.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceOffline`, {
1836
- val: false,
1837
- ack: true,
1838
- });
1839
- } else {
1840
- await this.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceOffline`, {
1841
- val: true,
1842
- ack: true,
1843
- });
1844
- }
1845
-
1846
- if (this.lowBatteryPoweredCount === 0) {
1847
- await this.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceLowBat`, {
1848
- val: false,
1849
- ack: true,
1850
- });
1851
- } else {
1852
- await this.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceLowBat`, {
1853
- val: true,
1854
- ack: true,
1855
- });
1856
- }
1857
-
1858
- if (this.upgradableDevicesCount === 0) {
1859
- await this.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceUpdatable`, {
1860
- val: false,
1861
- ack: true,
1862
- });
1863
- } else {
1864
- await this.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceUpdatable`, {
1865
- val: true,
1866
- ack: true,
1867
- });
1868
- }
1869
-
1870
- //write HTML list
1871
- if (this.configCreateHtmlList) {
1872
- await this.setStateChangedAsync(`devices.${dpSubFolder}linkQualityListHTML`, {
1873
- val: await this.createListHTML('linkQualityList', this.linkQualityDevices, this.linkQualityCount, null),
1874
- ack: true,
1875
- });
1876
- await this.setStateChangedAsync(`devices.${dpSubFolder}offlineListHTML`, {
1877
- val: await this.createListHTML('offlineList', this.offlineDevices, this.offlineDevicesCount, null),
1878
- ack: true,
1879
- });
1880
- await this.setStateChangedAsync(`devices.${dpSubFolder}batteryListHTML`, {
1881
- val: await this.createListHTML('batteryList', this.batteryPowered, this.batteryPoweredCount, false),
1882
- ack: true,
1883
- });
1884
- await this.setStateChangedAsync(`devices.${dpSubFolder}lowBatteryListHTML`, {
1885
- val: await this.createListHTML('batteryList', this.batteryLowPowered, this.lowBatteryPoweredCount, true),
1886
- ack: true,
1887
- });
1888
- if (this.config.checkAdapterInstances) {
1889
- await this.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listAllInstancesHTML`, {
1890
- val: await this.createListHTMLInstances('allInstancesList', this.listAllInstances, this.countAllInstances),
1891
- ack: true,
1892
- });
1893
- await this.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listAllActiveInstancesHTML`, {
1894
- val: await this.createListHTMLInstances('allActiveInstancesList', this.listAllActiveInstances, this.countAllActiveInstances),
1895
- ack: true,
1896
- });
1897
- await this.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listInstancesErrorHTML`, {
1898
- val: await this.createListHTMLInstances('errorInstanceList', this.listErrorInstance, this.countErrorInstance),
1899
- ack: true,
1900
- });
1901
- await this.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listDeactivatedInstancesHTML`, {
1902
- val: await this.createListHTMLInstances('deactivatedInstanceList', this.listDeactivatedInstances, this.countDeactivatedInstances),
1903
- ack: true,
1904
- });
1905
- await this.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listAdapterUpdatesHTML`, {
1906
- val: await this.createListHTMLInstances('updateAdapterList', this.listAdapterUpdates, this.countAdapterUpdates),
1907
- ack: true,
1908
- });
1909
- }
1910
- }
1911
-
1912
- // create timestamp of last run
1913
- const lastCheck = this.formatDate(new Date(), 'DD.MM.YYYY') + ' - ' + this.formatDate(new Date(), 'hh:mm:ss');
1914
- await this.setStateChangedAsync('lastCheck', lastCheck, true);
1915
- } catch (error) {
1916
- this.log.error(`[writeDatapoints] - ${error}`);
1917
- }
1918
- this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
1919
- } //<--End of writing Datapoints
1920
-
1921
- /**
1922
- * @param {string | string[]} id
1923
- * @param {ioBroker.State} state
1235
+ * @param {string | string[]} id
1236
+ * @param {ioBroker.State} state
1924
1237
  */
1925
1238
  async renewDeviceData(id, state) {
1926
1239
  let batteryData;
@@ -1973,7 +1286,7 @@ class DeviceWatcher extends utils.Adapter {
1973
1286
  deviceData.BatteryRaw = batteryData[2];
1974
1287
  deviceData.BatteryUnitRaw = batteryData[3];
1975
1288
  if (deviceData.LowBatDP !== 'none') {
1976
- isLowBatValue = await this.getInitValue(deviceData.LowBatDP);
1289
+ isLowBatValue = await tools.getInitValue(this,deviceData.LowBatDP);
1977
1290
  } else {
1978
1291
  isLowBatValue = undefined;
1979
1292
  }
@@ -2036,17 +1349,17 @@ class DeviceWatcher extends utils.Adapter {
2036
1349
  deviceData.UnreachDP,
2037
1350
  deviceData.SignalStrength,
2038
1351
  deviceData.UnreachState,
2039
- deviceData.DeviceStateSelectorDP,
2040
- deviceData.rssiPeerSelectorDP,
1352
+ deviceData.deviceStateSelectorHMRPC,
1353
+ deviceData.rssiPeerSelectorHMRPC,
2041
1354
  );
2042
- if (contactData !== undefined) {
1355
+ if (contactData !== undefined && contactData !== null) {
2043
1356
  deviceData.LastContact = contactData[0];
2044
1357
  deviceData.Status = contactData[1];
2045
1358
  deviceData.SignalStrength = contactData[2];
2046
1359
  }
2047
1360
  if (this.config.checkSendOfflineMsg && oldStatus !== deviceData.Status && !this.blacklistNotify.includes(deviceData.Path)) {
2048
1361
  // check if the generally deviceData connected state is for a while true
2049
- if (await this.getTimestampConnectionDP(deviceData.instanceDeviceConnectionDP, 50000)) {
1362
+ if (await tools.getTimestampConnectionDP(this, deviceData.instanceDeviceConnectionDP, 50000)) {
2050
1363
  await this.sendStateNotifications('Devices', 'onlineStateDevice', deviceID);
2051
1364
  }
2052
1365
  }
@@ -2077,6 +1390,9 @@ class DeviceWatcher extends utils.Adapter {
2077
1390
  try {
2078
1391
  const instanceAliveDP = await this.getForeignStatesAsync(`${instanceObject}.alive`);
2079
1392
 
1393
+ this.adapterUpdatesJsonRaw = await this.getAdapterUpdateData(adapterUpdateListDP);
1394
+
1395
+
2080
1396
  for (const [id] of Object.entries(instanceAliveDP)) {
2081
1397
  if (!(typeof id === 'string' && id.startsWith(`system.adapter.`))) continue;
2082
1398
 
@@ -2085,13 +1401,13 @@ class DeviceWatcher extends utils.Adapter {
2085
1401
 
2086
1402
  // get instance connected to host data
2087
1403
  const instanceConnectedHostDP = `system.adapter.${instanceID}.connected`;
2088
- const instanceConnectedHostVal = await this.getInitValue(instanceConnectedHostDP);
1404
+ const instanceConnectedHostVal = await tools.getInitValue(this,instanceConnectedHostDP);
2089
1405
 
2090
1406
  // get instance connected to device data
2091
1407
  const instanceConnectedDeviceDP = `${instanceID}.info.connection`;
2092
1408
  let instanceConnectedDeviceVal;
2093
1409
  if (instanceConnectedDeviceDP !== undefined && typeof instanceConnectedDeviceDP === 'boolean') {
2094
- instanceConnectedDeviceVal = await this.getInitValue(instanceConnectedDeviceDP);
1410
+ instanceConnectedDeviceVal = await tools.getInitValue(this,instanceConnectedDeviceDP);
2095
1411
  } else {
2096
1412
  instanceConnectedDeviceVal = 'N/A';
2097
1413
  }
@@ -2106,7 +1422,7 @@ class DeviceWatcher extends utils.Adapter {
2106
1422
  const instanceObjectData = await this.getForeignObjectAsync(instanceObjectPath);
2107
1423
  if (instanceObjectData) {
2108
1424
  // @ts-ignore
2109
- adapterName = this.capitalize(instanceObjectData.common.name);
1425
+ adapterName = tools.capitalize(instanceObjectData.common.name);
2110
1426
  adapterVersion = instanceObjectData.common.version;
2111
1427
  instanceMode = instanceObjectData.common.mode;
2112
1428
 
@@ -2115,12 +1431,13 @@ class DeviceWatcher extends utils.Adapter {
2115
1431
  }
2116
1432
  }
2117
1433
 
2118
- await this.getAdapterUpdateData(`admin.*.info.updatesJson`);
2119
1434
 
2120
- if (this.adapterUpdatesJsonRaw.has(adapterName)) {
2121
- for (const adapter of this.adapterUpdatesJsonRaw.values()) {
2122
- adapterAvailableUpdate = adapter.newVersion;
2123
- }
1435
+ const updateEntry = this.adapterUpdatesJsonRaw.find(
1436
+ entry => entry.adapter.toLowerCase() === adapterName.toLowerCase()
1437
+ );
1438
+
1439
+ if (updateEntry) {
1440
+ adapterAvailableUpdate = updateEntry.newVersion;
2124
1441
  } else {
2125
1442
  adapterAvailableUpdate = ' - ';
2126
1443
  }
@@ -2189,9 +1506,9 @@ class DeviceWatcher extends utils.Adapter {
2189
1506
  * @param {string} instanceID
2190
1507
  */
2191
1508
  async checkDaemonIsHealthy(instanceID) {
2192
- const connectedHostState = await this.getInitValue(`system.adapter.${instanceID}.connected`);
2193
- const isAlive = await this.getInitValue(`system.adapter.${instanceID}.alive`);
2194
- let connectedDeviceState = await this.getInitValue(`${instanceID}.info.connection`);
1509
+ const connectedHostState = await tools.getInitValue(this,`system.adapter.${instanceID}.connected`);
1510
+ const isAlive = await tools.getInitValue(this,`system.adapter.${instanceID}.alive`);
1511
+ let connectedDeviceState = await tools.getInitValue(this,`${instanceID}.info.connection`);
2195
1512
  if (connectedDeviceState === undefined) {
2196
1513
  connectedDeviceState = true;
2197
1514
  }
@@ -2219,7 +1536,7 @@ class DeviceWatcher extends utils.Adapter {
2219
1536
  * @param {number} instanceDeactivationTime
2220
1537
  */
2221
1538
  async checkDaemonIsAlive(instanceID, instanceDeactivationTime) {
2222
- let isAlive = await this.getInitValue(`system.adapter.${instanceID}.alive`);
1539
+ let isAlive = await tools.getInitValue(this,`system.adapter.${instanceID}.alive`);
2223
1540
  let daemonIsAlive;
2224
1541
  let isHealthy = false;
2225
1542
  let instanceStatusString = isAlive ? translations.instance_activated[this.config.userSelectedLanguage] : translations.instance_deactivated[this.config.userSelectedLanguage];
@@ -2256,7 +1573,7 @@ class DeviceWatcher extends utils.Adapter {
2256
1573
 
2257
1574
  if (isAliveSchedule) {
2258
1575
  lastUpdate = Math.round((Date.now() - isAliveSchedule.lc) / 1000); // Last state change in seconds
2259
- previousCronRun = this.getPreviousCronRun(scheduleTime); // When was the last cron run
1576
+ previousCronRun = tools.getPreviousCronRun(this, scheduleTime); // When was the last cron run
2260
1577
  if (previousCronRun) {
2261
1578
  lastCronRun = Math.round(previousCronRun / 1000); // change distance to last run in seconds
2262
1579
  diff = lastCronRun - lastUpdate;
@@ -2336,26 +1653,13 @@ class DeviceWatcher extends utils.Adapter {
2336
1653
  return [isAlive, isHealthy, instanceStatusString, connectedToHost, connectedToDevice];
2337
1654
  }
2338
1655
 
2339
- /**
2340
- * create adapter update data
2341
- */
2342
- async createAdapterUpdateData() {
2343
- const adapterUpdateListDP = 'admin.*.info.updatesJson';
2344
- // subscribe to datapoint
2345
- this.subscribeForeignStates(adapterUpdateListDP);
2346
-
2347
- await this.getAdapterUpdateData(adapterUpdateListDP);
2348
-
2349
- await this.createAdapterUpdateList();
2350
- }
2351
-
2352
1656
  /**
2353
1657
  * create adapter update raw lists
2354
1658
  * @param {string} adapterUpdateListDP
2355
1659
  */
2356
1660
  async getAdapterUpdateData(adapterUpdateListDP) {
2357
1661
  // Clear the existing adapter updates data
2358
- this.adapterUpdatesJsonRaw.clear();
1662
+ let adapterUpdatesJsonRaw = [];
2359
1663
 
2360
1664
  // Fetch the adapter updates list
2361
1665
  const adapterUpdatesListVal = await this.getForeignStatesAsync(adapterUpdateListDP);
@@ -2365,20 +1669,22 @@ class DeviceWatcher extends utils.Adapter {
2365
1669
 
2366
1670
  // Extract adapter data from the list
2367
1671
  for (const [id, value] of Object.entries(adapterUpdatesListVal)) {
2368
- adapterJsonList = this.parseData(value.val);
1672
+ adapterJsonList = tools.parseData(value.val);
2369
1673
  adapterUpdatesJsonPath = id;
2370
1674
  }
2371
1675
 
2372
1676
  // Populate the adapter updates data
2373
1677
  for (const [id, adapterData] of Object.entries(adapterJsonList)) {
2374
- this.adapterUpdatesJsonRaw.set(this.capitalize(id), {
2375
- Path: adapterUpdatesJsonPath,
2376
- newVersion: adapterData.availableVersion,
2377
- oldVersion: adapterData.installedVersion,
2378
- });
1678
+ adapterUpdatesJsonRaw.push(
1679
+ {
1680
+ adapter: tools.capitalize(id),
1681
+ newVersion: adapterData.availableVersion,
1682
+ oldVersion: adapterData.installedVersion,
1683
+ }
1684
+ );
2379
1685
  }
2380
1686
 
2381
- return this.adapterUpdatesJsonRaw;
1687
+ return adapterUpdatesJsonRaw;
2382
1688
  }
2383
1689
 
2384
1690
  /**
@@ -2388,13 +1694,14 @@ class DeviceWatcher extends utils.Adapter {
2388
1694
  this.listAdapterUpdates = [];
2389
1695
  this.countAdapterUpdates = 0;
2390
1696
 
2391
- for (const [adapter, updateData] of this.adapterUpdatesJsonRaw) {
1697
+ for (const updateData of this.adapterUpdatesJsonRaw) {
2392
1698
  this.listAdapterUpdates.push({
2393
- [translations.Adapter[this.config.userSelectedLanguage]]: adapter,
1699
+ [translations.Adapter[this.config.userSelectedLanguage]]: updateData.adapter,
2394
1700
  [translations.Available_Version[this.config.userSelectedLanguage]]: updateData.newVersion,
2395
1701
  [translations.Installed_Version[this.config.userSelectedLanguage]]: updateData.oldVersion,
2396
1702
  });
2397
1703
  }
1704
+
2398
1705
  this.countAdapterUpdates = this.listAdapterUpdates.length;
2399
1706
  await this.writeAdapterUpdatesDPs();
2400
1707
  }
@@ -2409,7 +1716,7 @@ class DeviceWatcher extends utils.Adapter {
2409
1716
  if (this.countAdapterUpdates === 0) {
2410
1717
  this.listAdapterUpdates = [
2411
1718
  {
2412
- [translations.Adapter[this.config.userSelectedLanguage]]: '--none--',
1719
+ [translations.Adapter[this.config.userSelectedLanguage]]: '--no updates--',
2413
1720
  [translations.Available_Version[this.config.userSelectedLanguage]]: '',
2414
1721
  [translations.Installed_Version[this.config.userSelectedLanguage]]: '',
2415
1722
  },
@@ -2555,8 +1862,11 @@ class DeviceWatcher extends utils.Adapter {
2555
1862
 
2556
1863
  // Update instances with available adapter updates
2557
1864
  for (const instance of this.listInstanceRaw.values()) {
2558
- if (this.adapterUpdatesJsonRaw.has(instance.Adapter)) {
2559
- const adapterUpdate = this.adapterUpdatesJsonRaw.get(instance.Adapter);
1865
+ const adapterUpdate = this.adapterUpdatesJsonRaw.find(
1866
+ entry => entry.adapter.toLowerCase() === instance.Adapter.toLowerCase()
1867
+ );
1868
+
1869
+ if (adapterUpdate) {
2560
1870
  instance.updateAvailable = adapterUpdate.newVersion;
2561
1871
  } else {
2562
1872
  instance.updateAvailable = ' - ';
@@ -2621,294 +1931,6 @@ class DeviceWatcher extends utils.Adapter {
2621
1931
  }
2622
1932
  }
2623
1933
 
2624
- /**
2625
- * create Datapoints for Instances
2626
- */
2627
- async createDPsForInstances() {
2628
- await this.setObjectNotExistsAsync(`adapterAndInstances`, {
2629
- type: 'channel',
2630
- common: {
2631
- name: {
2632
- en: 'Adapter and Instances',
2633
- de: 'Adapter und Instanzen',
2634
- ru: 'Адаптер и Instances',
2635
- pt: 'Adaptador e instâncias',
2636
- nl: 'Adapter en Instance',
2637
- fr: 'Adaptateur et instances',
2638
- it: 'Adattatore e istanze',
2639
- es: 'Adaptador e instalaciones',
2640
- pl: 'Adapter and Instances',
2641
- // @ts-ignore
2642
- uk: 'Адаптер та інстанції',
2643
- 'zh-cn': '道歉和案',
2644
- },
2645
- },
2646
- native: {},
2647
- });
2648
-
2649
- // Instances
2650
- await this.setObjectNotExistsAsync(`adapterAndInstances.listAllInstances`, {
2651
- type: 'state',
2652
- common: {
2653
- name: {
2654
- en: 'JSON List of all instances',
2655
- de: 'JSON Liste aller Instanzen',
2656
- ru: 'ДЖСОН Список всех инстанций',
2657
- pt: 'J. Lista de todas as instâncias',
2658
- nl: 'JSON List van alle instanties',
2659
- fr: 'JSON Liste de tous les cas',
2660
- it: 'JSON Elenco di tutte le istanze',
2661
- es: 'JSON Lista de todos los casos',
2662
- pl: 'JSON Lista wszystkich instancji',
2663
- // @ts-ignore
2664
- uk: 'Сонце Список всіх екземплярів',
2665
- 'zh-cn': '附 件 所有事例一览表',
2666
- },
2667
- type: 'array',
2668
- role: 'json',
2669
- read: true,
2670
- write: false,
2671
- },
2672
- native: {},
2673
- });
2674
- await this.setObjectNotExistsAsync(`adapterAndInstances.countAllInstances`, {
2675
- type: 'state',
2676
- common: {
2677
- name: {
2678
- en: 'Number of all instances',
2679
- de: 'Anzahl aller Instanzen',
2680
- ru: 'Количество всех инстанций',
2681
- pt: 'Número de todas as instâncias',
2682
- nl: 'Nummer van alle gevallen',
2683
- fr: 'Nombre de cas',
2684
- it: 'Numero di tutte le istanze',
2685
- es: 'Número de casos',
2686
- pl: 'Liczba wszystkich instancji',
2687
- // @ts-ignore
2688
- uk: 'Кількість всіх екземплярів',
2689
- 'zh-cn': '各类案件数目',
2690
- },
2691
- type: 'number',
2692
- role: 'value',
2693
- read: true,
2694
- write: false,
2695
- },
2696
- native: {},
2697
- });
2698
- // Instances
2699
- await this.setObjectNotExistsAsync(`adapterAndInstances.listAllActiveInstances`, {
2700
- type: 'state',
2701
- common: {
2702
- name: {
2703
- en: 'JSON List of all active instances',
2704
- de: 'JSON Liste aller aktiven Instanzen',
2705
- ru: 'ДЖСОН Список всех активных инстанций',
2706
- pt: 'J. Lista de todas as instâncias ativas',
2707
- nl: 'JSON List van alle actieve instanties',
2708
- fr: 'JSON Liste de tous les cas actifs',
2709
- it: 'JSON Elenco di tutte le istanze attive',
2710
- es: 'JSON Lista de todos los casos activos',
2711
- pl: 'JSON Lista wszystkich aktywnych instancji',
2712
- // @ts-ignore
2713
- uk: 'Сонце Список всіх активних екземплярів',
2714
- 'zh-cn': '附 件 所有积极事件清单',
2715
- },
2716
- type: 'array',
2717
- role: 'json',
2718
- read: true,
2719
- write: false,
2720
- },
2721
- native: {},
2722
- });
2723
- await this.setObjectNotExistsAsync(`adapterAndInstances.countAllActiveInstances`, {
2724
- type: 'state',
2725
- common: {
2726
- name: {
2727
- en: 'Number of all active instances',
2728
- de: 'Anzahl aller aktiven Instanzen',
2729
- ru: 'Количество всех активных инстанций',
2730
- pt: 'Número de todas as instâncias ativas',
2731
- nl: 'Nummer van alle actieve instanties',
2732
- fr: 'Nombre de toutes les instances actives',
2733
- it: 'Numero di tutte le istanze attive',
2734
- es: 'Número de casos activos',
2735
- pl: 'Liczba wszystkich czynnych przypadków',
2736
- // @ts-ignore
2737
- uk: 'Кількість всіх активних екземплярів',
2738
- 'zh-cn': '所有积极事件的数目',
2739
- },
2740
- type: 'number',
2741
- role: 'value',
2742
- read: true,
2743
- write: false,
2744
- },
2745
- native: {},
2746
- });
2747
- await this.setObjectNotExistsAsync(`adapterAndInstances.listDeactivatedInstances`, {
2748
- type: 'state',
2749
- common: {
2750
- name: {
2751
- en: 'JSON List of deactivated instances',
2752
- de: 'JSON Liste der deaktivierten Instanzen',
2753
- ru: 'ДЖСОН Список деактивированных инстанций',
2754
- pt: 'J. Lista de instâncias desativadas',
2755
- nl: 'JSON List van gedeactiveerde instanties',
2756
- fr: 'JSON Liste des cas désactivés',
2757
- it: 'JSON Elenco delle istanze disattivate',
2758
- es: 'JSON Lista de casos desactivados',
2759
- pl: 'JSON Lista przypadków deaktywowanych',
2760
- // @ts-ignore
2761
- uk: 'Сонце Перелік деактивованих екземплярів',
2762
- 'zh-cn': '附 件 被动事例清单',
2763
- },
2764
- type: 'array',
2765
- role: 'json',
2766
- read: true,
2767
- write: false,
2768
- },
2769
- native: {},
2770
- });
2771
- await this.setObjectNotExistsAsync(`adapterAndInstances.countDeactivatedInstances`, {
2772
- type: 'state',
2773
- common: {
2774
- name: {
2775
- en: 'Number of deactivated instances',
2776
- de: 'Anzahl deaktivierter Instanzen',
2777
- ru: 'Количество деактивированных инстанций',
2778
- pt: 'Número de instâncias desativadas',
2779
- nl: 'Nummer van gedeactiveerde instanties',
2780
- fr: 'Nombre de cas désactivés',
2781
- it: 'Numero di istanze disattivate',
2782
- es: 'Número de casos desactivados',
2783
- pl: 'Liczba deaktywowanych instancji',
2784
- // @ts-ignore
2785
- uk: 'Кількість деактивованих екземплярів',
2786
- 'zh-cn': 'A. 递解事件的数目',
2787
- },
2788
- type: 'number',
2789
- role: 'value',
2790
- read: true,
2791
- write: false,
2792
- },
2793
- native: {},
2794
- });
2795
- await this.setObjectNotExistsAsync(`adapterAndInstances.listInstancesError`, {
2796
- type: 'state',
2797
- common: {
2798
- name: {
2799
- en: 'JSON list of instances with error',
2800
- de: 'JSON-Liste von Instanzen mit Fehler',
2801
- ru: 'JSON список инстанций с ошибкой',
2802
- pt: 'Lista de instâncias JSON com erro',
2803
- nl: 'JSON lijst met fouten',
2804
- fr: 'Liste des instances avec erreur',
2805
- it: 'Elenco JSON delle istanze con errore',
2806
- es: 'JSON lista de casos con error',
2807
- pl: 'Lista błędów JSON',
2808
- // @ts-ignore
2809
- uk: 'JSON список екземплярів з помилкою',
2810
- 'zh-cn': '联合工作组办公室错误事件清单',
2811
- },
2812
- type: 'array',
2813
- role: 'json',
2814
- read: true,
2815
- write: false,
2816
- },
2817
- native: {},
2818
- });
2819
- await this.setObjectNotExistsAsync(`adapterAndInstances.countInstancesError`, {
2820
- type: 'state',
2821
- common: {
2822
- name: {
2823
- en: 'Count of instances with error',
2824
- de: 'Anzahl der Instanzen mit Fehler',
2825
- ru: 'Количество инстанций с ошибкой',
2826
- pt: 'Contagem de instâncias com erro',
2827
- nl: 'Graaf van instoringen met fouten',
2828
- fr: 'Nombre de cas avec erreur',
2829
- it: 'Conteggio di istanze con errore',
2830
- es: 'Cuenta de casos con error',
2831
- pl: 'Liczba przykładów w przypadku błędów',
2832
- // @ts-ignore
2833
- uk: 'Кількість екземплярів з помилкою',
2834
- 'zh-cn': '发生错误的情况',
2835
- },
2836
- type: 'number',
2837
- role: 'value',
2838
- read: true,
2839
- write: false,
2840
- },
2841
- native: {},
2842
- });
2843
-
2844
- // Adapter
2845
- await this.setObjectNotExistsAsync(`adapterAndInstances.listAdapterUpdates`, {
2846
- type: 'state',
2847
- common: {
2848
- name: {
2849
- en: 'JSON list of adapters with available updates',
2850
- de: 'JSON-Liste der Adapter mit verfügbaren Updates',
2851
- ru: 'JSON список адаптеров с доступными обновлениями',
2852
- pt: 'Lista de adaptadores JSON com atualizações disponíveis',
2853
- nl: 'JSON lijst met beschikbare updates',
2854
- fr: 'Liste JSON des adaptateurs avec mises à jour disponibles',
2855
- it: 'Elenco di adattatori JSON con aggiornamenti disponibili',
2856
- es: 'JSON lista de adaptadores con actualizaciones disponibles',
2857
- pl: 'JSON lista adapterów z dostępnymi aktualizacjami',
2858
- // @ts-ignore
2859
- uk: 'JSON список адаптерів з доступними оновленнями',
2860
- 'zh-cn': '附录A',
2861
- },
2862
- type: 'array',
2863
- role: 'json',
2864
- read: true,
2865
- write: false,
2866
- },
2867
- native: {},
2868
- });
2869
- await this.setObjectNotExistsAsync(`adapterAndInstances.countAdapterUpdates`, {
2870
- type: 'state',
2871
- common: {
2872
- name: {
2873
- en: 'Number of adapters with available updates',
2874
- de: 'Anzahl der Adapter mit verfügbaren Updates',
2875
- ru: 'Количество адаптеров с доступными обновлениями',
2876
- pt: 'Número de adaptadores com atualizações disponíveis',
2877
- nl: 'Nummer van adapters met beschikbare updates',
2878
- fr: "Nombre d'adaptateurs avec mises à jour disponibles",
2879
- it: 'Numero di adattatori con aggiornamenti disponibili',
2880
- es: 'Número de adaptadores con actualizaciones disponibles',
2881
- pl: 'Liczba adapterów z dostępną aktualizacją',
2882
- // @ts-ignore
2883
- uk: 'Кількість адаптерів з доступними оновленнями',
2884
- 'zh-cn': '更新的适应者人数',
2885
- },
2886
- type: 'number',
2887
- role: 'value',
2888
- read: true,
2889
- write: false,
2890
- },
2891
- native: {},
2892
- });
2893
- }
2894
-
2895
- /**
2896
- * delete Datapoints for Instances
2897
- */
2898
- async deleteDPsForInstances() {
2899
- await this.delObjectAsync(`adapterAndInstances`);
2900
- await this.delObjectAsync(`adapterAndInstances.listAllInstances`);
2901
- await this.delObjectAsync(`adapterAndInstances.countAllInstances`);
2902
- await this.delObjectAsync(`adapterAndInstances.listAllActiveInstances`);
2903
- await this.delObjectAsync(`adapterAndInstances.countAllActiveInstances`);
2904
- await this.delObjectAsync(`adapterAndInstances.listDeactivatedInstances`);
2905
- await this.delObjectAsync(`adapterAndInstances.countDeactivatedInstances`);
2906
- await this.delObjectAsync(`adapterAndInstances.listInstancesError`);
2907
- await this.delObjectAsync(`adapterAndInstances.countInstancesError`);
2908
- await this.delObjectAsync(`adapterAndInstances.listAdapterUpdates`);
2909
- await this.delObjectAsync(`adapterAndInstances.countAdapterUpdates`);
2910
- }
2911
-
2912
1934
  /*=============================================
2913
1935
  = functions to send notifications =
2914
1936
  =============================================*/
@@ -2922,7 +1944,7 @@ class DeviceWatcher extends utils.Adapter {
2922
1944
  if (this.config.instancePushover) {
2923
1945
  try {
2924
1946
  //first check if instance is living
2925
- const pushoverAliveState = await this.getInitValue('system.adapter.' + this.config.instancePushover + '.alive');
1947
+ const pushoverAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instancePushover + '.alive');
2926
1948
 
2927
1949
  if (!pushoverAliveState) {
2928
1950
  this.log.warn('Pushover instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -2944,7 +1966,7 @@ class DeviceWatcher extends utils.Adapter {
2944
1966
  if (this.config.instanceTelegram) {
2945
1967
  try {
2946
1968
  //first check if instance is living
2947
- const telegramAliveState = await this.getInitValue('system.adapter.' + this.config.instanceTelegram + '.alive');
1969
+ const telegramAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceTelegram + '.alive');
2948
1970
 
2949
1971
  if (!telegramAliveState) {
2950
1972
  this.log.warn('Telegram instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -2964,7 +1986,7 @@ class DeviceWatcher extends utils.Adapter {
2964
1986
  if (this.config.instanceWhatsapp) {
2965
1987
  try {
2966
1988
  //first check if instance is living
2967
- const whatsappAliveState = await this.getInitValue('system.adapter.' + this.config.instanceWhatsapp + '.alive');
1989
+ const whatsappAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceWhatsapp + '.alive');
2968
1990
 
2969
1991
  if (!whatsappAliveState) {
2970
1992
  this.log.warn('Whatsapp instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -2983,7 +2005,7 @@ class DeviceWatcher extends utils.Adapter {
2983
2005
  if (this.config.instanceMatrix) {
2984
2006
  try {
2985
2007
  //first check if instance is living
2986
- const matrixAliveState = await this.getInitValue('system.adapter.' + this.config.instanceMatrix + '.alive');
2008
+ const matrixAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceMatrix + '.alive');
2987
2009
 
2988
2010
  if (!matrixAliveState) {
2989
2011
  this.log.warn('Matrix instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -3002,7 +2024,7 @@ class DeviceWatcher extends utils.Adapter {
3002
2024
  if (this.config.instanceSignal) {
3003
2025
  try {
3004
2026
  //first check if instance is living
3005
- const signalAliveState = await this.getInitValue('system.adapter.' + this.config.instanceSignal + '.alive');
2027
+ const signalAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceSignal + '.alive');
3006
2028
 
3007
2029
  if (!signalAliveState) {
3008
2030
  this.log.warn('Signal instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -3021,7 +2043,7 @@ class DeviceWatcher extends utils.Adapter {
3021
2043
  if (this.config.instanceEmail) {
3022
2044
  try {
3023
2045
  //first check if instance is living
3024
- const eMailAliveState = await this.getInitValue('system.adapter.' + this.config.instanceEmail + '.alive');
2046
+ const eMailAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceEmail + '.alive');
3025
2047
 
3026
2048
  if (!eMailAliveState) {
3027
2049
  this.log.warn('eMail instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -3041,7 +2063,7 @@ class DeviceWatcher extends utils.Adapter {
3041
2063
  if (this.config.instanceJarvis) {
3042
2064
  try {
3043
2065
  //first check if instance is living
3044
- const jarvisAliveState = await this.getInitValue('system.adapter.' + this.config.instanceJarvis + '.alive');
2066
+ const jarvisAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceJarvis + '.alive');
3045
2067
 
3046
2068
  if (!jarvisAliveState) {
3047
2069
  this.log.warn('Jarvis instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -3061,7 +2083,7 @@ class DeviceWatcher extends utils.Adapter {
3061
2083
  if (this.config.instanceLovelace) {
3062
2084
  try {
3063
2085
  //first check if instance is living
3064
- const lovelaceAliveState = await this.getInitValue('system.adapter.' + this.config.instanceLovelace + '.alive');
2086
+ const lovelaceAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceLovelace + '.alive');
3065
2087
 
3066
2088
  if (!lovelaceAliveState) {
3067
2089
  this.log.warn('Lovelace instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -3081,7 +2103,7 @@ class DeviceWatcher extends utils.Adapter {
3081
2103
  if (this.config.instanceSynochat) {
3082
2104
  try {
3083
2105
  //first check if instance is living
3084
- const synochatAliveState = await this.getInitValue('system.adapter.' + this.config.instanceSynochat + '.alive');
2106
+ const synochatAliveState = await tools.getInitValue(this,'system.adapter.' + this.config.instanceSynochat + '.alive');
3085
2107
 
3086
2108
  if (!synochatAliveState) {
3087
2109
  this.log.warn('Synochat instance is not running. Message could not be sent. Please check your instance configuration.');
@@ -3326,1053 +2348,6 @@ class DeviceWatcher extends utils.Adapter {
3326
2348
  }
3327
2349
  }
3328
2350
 
3329
- /*=============================================
3330
- = functions to create html lists =
3331
- =============================================*/
3332
- /**
3333
- * @param {string} type - type of list
3334
- * @param {object} devices - Device
3335
- * @param {number} deviceCount - Counted devices
3336
- * @param {object} isLowBatteryList - list Low Battery Devices
3337
- */
3338
- async createListHTML(type, devices, deviceCount, isLowBatteryList) {
3339
- let html;
3340
- switch (type) {
3341
- case 'linkQualityList':
3342
- devices = devices.sort((a, b) => {
3343
- a = a.Device || '';
3344
- b = b.Device || '';
3345
- return a.localeCompare(b);
3346
- });
3347
- html = `<center>
3348
- <b>${[translations.Link_quality_devices[this.config.userSelectedLanguage]]}:<font> ${deviceCount}</b><small></small></font>
3349
- <p></p>
3350
- </center>
3351
- <table width=100%>
3352
- <tr>
3353
- <th align=left>${[translations.Device[this.config.userSelectedLanguage]]}</th>
3354
- <th align=center width=120>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3355
- <th align=right>${[translations.Signal_strength[this.config.userSelectedLanguage]]}</th>
3356
- </tr>
3357
- <tr>
3358
- <td colspan="5"><hr></td>
3359
- </tr>`;
3360
-
3361
- for (const device of devices) {
3362
- html += `<tr>
3363
- <td><font>${device[translations.Device[this.config.userSelectedLanguage]]}</font></td>
3364
- <td align=center><font>${device[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3365
- <td align=right><font>${device[translations.Signal_strength[this.config.userSelectedLanguage]]}</font></td>
3366
- </tr>`;
3367
- }
3368
-
3369
- html += '</table>';
3370
- break;
3371
-
3372
- case 'offlineList':
3373
- devices = devices.sort((a, b) => {
3374
- a = a.Device || '';
3375
- b = b.Device || '';
3376
- return a.localeCompare(b);
3377
- });
3378
- html = `<center>
3379
- <b>${[translations.offline_devices[this.config.userSelectedLanguage]]}: <font color=${deviceCount === 0 ? '#3bcf0e' : 'orange'}>${deviceCount}</b><small></small></font>
3380
- <p></p>
3381
- </center>
3382
- <table width=100%>
3383
- <tr>
3384
- <th align=left>${[translations.Device[this.config.userSelectedLanguage]]}</th>
3385
- <th align=center width=120>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3386
- <th align=center>${[translations.Last_Contact[this.config.userSelectedLanguage]]}</th>
3387
- </tr>
3388
- <tr>
3389
- <td colspan="5"><hr></td>
3390
- </tr>`;
3391
-
3392
- for (const device of devices) {
3393
- html += `<tr>
3394
- <td><font>${device[translations.Device[this.config.userSelectedLanguage]]}</font></td>
3395
- <td align=center><font>${device[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3396
- <td align=center><font color=orange>${device[translations.Last_Contact[this.config.userSelectedLanguage]]}</font></td>
3397
- </tr>`;
3398
- }
3399
-
3400
- html += '</table>';
3401
- break;
3402
-
3403
- case 'batteryList':
3404
- devices = devices.sort((a, b) => {
3405
- a = a.Device || '';
3406
- b = b.Device || '';
3407
- return a.localeCompare(b);
3408
- });
3409
- html = `<center>
3410
- <b>${isLowBatteryList === true ? `${[translations.low[this.config.userSelectedLanguage]]} ` : ''}${[translations.battery_devices[this.config.userSelectedLanguage]]}:
3411
- <font color=${isLowBatteryList === true ? (deviceCount > 0 ? 'orange' : '#3bcf0e') : ''}>${deviceCount}</b></font>
3412
- <p></p>
3413
- </center>
3414
- <table width=100%>
3415
- <tr>
3416
- <th align=left>${[translations.Device[this.config.userSelectedLanguage]]}</th>
3417
- <th align=center width=120>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3418
- <th align=${isLowBatteryList ? 'center' : 'right'}>${[translations.Battery[this.config.userSelectedLanguage]]}</th>
3419
- </tr>
3420
- <tr>
3421
- <td colspan="5"><hr></td>
3422
- </tr>`;
3423
- for (const device of devices) {
3424
- html += `<tr>
3425
- <td><font>${device[translations.Device[this.config.userSelectedLanguage]]}</font></td>
3426
- <td align=center><font>${device[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>`;
3427
-
3428
- if (isLowBatteryList) {
3429
- html += `<td align=center><font color=orange>${device[translations.Battery[this.config.userSelectedLanguage]]}</font></td>`;
3430
- } else {
3431
- html += `<td align=right><font color=#3bcf0e>${device[translations.Battery[this.config.userSelectedLanguage]]}</font></td>`;
3432
- }
3433
- html += `</tr>`;
3434
- }
3435
-
3436
- html += '</table>';
3437
- break;
3438
- }
3439
- return html;
3440
- }
3441
-
3442
- /**
3443
- * @param {string} type - type of list
3444
- * @param {object} instances - Instance
3445
- * @param {number} instancesCount - Counted devices
3446
- */
3447
- async createListHTMLInstances(type, instances, instancesCount) {
3448
- let html;
3449
- switch (type) {
3450
- case 'allInstancesList':
3451
- instances = instances.sort((a, b) => {
3452
- a = a.Instance || '';
3453
- b = b.Instance || '';
3454
- return a.localeCompare(b);
3455
- });
3456
- html = `<center>
3457
- <b>${[translations.All_Instances[this.config.userSelectedLanguage]]}:<font> ${instancesCount}</b><small></small></font>
3458
- <p></p>
3459
- </center>
3460
- <table width=100%>
3461
- <tr>
3462
- <th align=left>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3463
- <th align=center>${[translations.Instance[this.config.userSelectedLanguage]]}</th>
3464
- <th align=center width=180>${[translations.Status[this.config.userSelectedLanguage]]}</th>
3465
- </tr>
3466
- <tr>
3467
- <td colspan="5"><hr></td>
3468
- </tr>`;
3469
-
3470
- for (const instanceData of instances) {
3471
- html += `<tr>
3472
- <td><font>${instanceData[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3473
- <td align=center><font>${instanceData[translations.Instance[this.config.userSelectedLanguage]]}</font></td>
3474
- <td align=center><font>${instanceData[translations.Status[this.config.userSelectedLanguage]]}</font></td>
3475
- </tr>`;
3476
- }
3477
-
3478
- html += '</table>';
3479
- break;
3480
-
3481
- case 'allActiveInstancesList':
3482
- instances = instances.sort((a, b) => {
3483
- a = a.Instance || '';
3484
- b = b.Instances || '';
3485
- return a.localeCompare(b);
3486
- });
3487
- html = `<center>
3488
- <b>${[translations.Active_Instances[this.config.userSelectedLanguage]]}: <font> ${instancesCount}</b><small></small></font>
3489
- <p></p>
3490
- </center>
3491
- <table width=100%>
3492
- <tr>
3493
- <th align=left>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3494
- <th align=center>${[translations.Instance[this.config.userSelectedLanguage]]}</th>
3495
- <th align=center width=180>${[translations.Status[this.config.userSelectedLanguage]]}</th>
3496
- </tr>
3497
- <tr>
3498
- <td colspan="5"><hr></td>
3499
- </tr>`;
3500
-
3501
- for (const instanceData of instances) {
3502
- html += `<tr>
3503
- <td><font>${instanceData[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3504
- <td align=center><font>${instanceData[translations.Instance[this.config.userSelectedLanguage]]}</font></td>
3505
- <td align=center><font color=orange>${instanceData[translations.Status[this.config.userSelectedLanguage]]}</font></td>
3506
- </tr>`;
3507
- }
3508
-
3509
- html += '</table>';
3510
- break;
3511
-
3512
- case 'errorInstanceList':
3513
- instances = instances.sort((a, b) => {
3514
- a = a.Instance || '';
3515
- b = b.Instances || '';
3516
- return a.localeCompare(b);
3517
- });
3518
- html = `<center>
3519
- <b>${[translations.Error_Instances[this.config.userSelectedLanguage]]}: <font color=${instancesCount === 0 ? '#3bcf0e' : 'orange'}>${instancesCount}</b><small></small></font>
3520
- <p></p>
3521
- </center>
3522
- <table width=100%>
3523
- <tr>
3524
- <th align=left>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3525
- <th align=center>${[translations.Instance[this.config.userSelectedLanguage]]}</th>
3526
- <th align=center width=180>${[translations.Status[this.config.userSelectedLanguage]]}</th>
3527
- </tr>
3528
- <tr>
3529
- <td colspan="5"><hr></td>
3530
- </tr>`;
3531
-
3532
- for (const instanceData of instances) {
3533
- html += `<tr>
3534
- <td><font>${instanceData[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3535
- <td align=center><font>${instanceData[translations.Instance[this.config.userSelectedLanguage]]}</font></td>
3536
- <td align=center><font color=orange>${instanceData[translations.Status[this.config.userSelectedLanguage]]}</font></td>
3537
- </tr>`;
3538
- }
3539
-
3540
- html += '</table>';
3541
- break;
3542
-
3543
- case 'deactivatedInstanceList':
3544
- instances = instances.sort((a, b) => {
3545
- a = a.Instance || '';
3546
- b = b.Instances || '';
3547
- return a.localeCompare(b);
3548
- });
3549
- html = `<center>
3550
- <b>${[translations.Deactivated_Instances[this.config.userSelectedLanguage]]}: <font color=${instancesCount === 0 ? '#3bcf0e' : 'orange'}>${instancesCount}</b><small></small></font>
3551
- <p></p>
3552
- </center>
3553
- <table width=100%>
3554
- <tr>
3555
- <th align=left>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3556
- <th align=center>${[translations.Instance[this.config.userSelectedLanguage]]}</th>
3557
- <th align=center width=180>${[translations.Status[this.config.userSelectedLanguage]]}</th>
3558
- </tr>
3559
- <tr>
3560
- <td colspan="5"><hr></td>
3561
- </tr>`;
3562
-
3563
- for (const instanceData of instances) {
3564
- if (!instanceData.isAlive) {
3565
- html += `<tr>
3566
- <td><font>${instanceData[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3567
- <td align=center><font>${instanceData[translations.Instance[this.config.userSelectedLanguage]]}</font></td>
3568
- <td align=center><font color=orange>${instanceData[translations.Status[this.config.userSelectedLanguage]]}</font></td>
3569
- </tr>`;
3570
- }
3571
- }
3572
-
3573
- html += '</table>';
3574
- break;
3575
-
3576
- case 'updateAdapterList':
3577
- html = `<center>
3578
- <b>${[translations.Updatable_adapters[this.config.userSelectedLanguage]]}: <font color=${instancesCount === 0 ? '#3bcf0e' : 'orange'}>${instancesCount}</b><small></small></font>
3579
- <p></p>
3580
- </center>
3581
- <table width=100%>
3582
- <tr>
3583
- <th align=left>${[translations.Adapter[this.config.userSelectedLanguage]]}</th>
3584
- <th align=center>${[translations.Installed_Version[this.config.userSelectedLanguage]]}</th>
3585
- <th align=center>${[translations.Available_Version[this.config.userSelectedLanguage]]}</th>
3586
- </tr>
3587
- <tr>
3588
- <td colspan="5"><hr></td>
3589
- </tr>`;
3590
-
3591
- for (const instanceData of instances.values()) {
3592
- if (instanceData.updateAvailable !== ' - ') {
3593
- html += `<tr>
3594
- <td><font>${instanceData[translations.Adapter[this.config.userSelectedLanguage]]}</font></td>
3595
- <td align=center><font>${instanceData[translations.Installed_Version[this.config.userSelectedLanguage]]}</font></td>
3596
- <td align=center><font color=orange>${instanceData[translations.Available_Version[this.config.userSelectedLanguage]]}</font></td>
3597
- </tr>`;
3598
- }
3599
- }
3600
-
3601
- html += '</table>';
3602
- break;
3603
- }
3604
- return html;
3605
- }
3606
-
3607
- /*=============================================
3608
- = create datapoints for each adapter =
3609
- =============================================*/
3610
-
3611
- /**
3612
- * @param {object} adptName - Adaptername of devices
3613
- */
3614
- async createDPsForEachAdapter(adptName) {
3615
- await this.setObjectNotExistsAsync(`devices.${adptName}`, {
3616
- type: 'channel',
3617
- common: {
3618
- name: adptName,
3619
- },
3620
- native: {},
3621
- });
3622
-
3623
- await this.setObjectNotExistsAsync(`devices.${adptName}.offlineCount`, {
3624
- type: 'state',
3625
- common: {
3626
- name: {
3627
- en: 'Number of devices offline',
3628
- de: 'Anzahl der Geräte offline',
3629
- ru: 'Количество устройств offline',
3630
- pt: 'Número de dispositivos offline',
3631
- nl: 'Nummer van apparatuur offline',
3632
- fr: 'Nombre de dispositifs hors ligne',
3633
- it: 'Numero di dispositivi offline',
3634
- es: 'Número de dispositivos sin conexión',
3635
- pl: 'Ilość urządzeń offline',
3636
- 'zh-cn': '线内装置数量',
3637
- },
3638
- type: 'number',
3639
- role: 'value',
3640
- read: true,
3641
- write: false,
3642
- },
3643
- native: {},
3644
- });
3645
-
3646
- await this.setObjectNotExistsAsync(`devices.${adptName}.offlineList`, {
3647
- type: 'state',
3648
- common: {
3649
- name: {
3650
- en: 'List of offline devices',
3651
- de: 'Liste der Offline-Geräte',
3652
- ru: 'Список оффлайн устройств',
3653
- pt: 'Lista de dispositivos off-line',
3654
- nl: 'List van offline apparatuur',
3655
- fr: 'Liste des dispositifs hors ligne',
3656
- it: 'Elenco dei dispositivi offline',
3657
- es: 'Lista de dispositivos sin conexión',
3658
- pl: 'Lista urządzeń offline',
3659
- 'zh-cn': '线装置清单',
3660
- },
3661
- type: 'array',
3662
- role: 'json',
3663
- read: true,
3664
- write: false,
3665
- },
3666
- native: {},
3667
- });
3668
-
3669
- await this.setObjectNotExistsAsync(`devices.${adptName}.oneDeviceOffline`, {
3670
- type: 'state',
3671
- common: {
3672
- name: {
3673
- en: 'Is one device with offline',
3674
- de: 'Ist ein Gerät mit Offline',
3675
- ru: 'Это одно устройство с offline',
3676
- pt: 'É um dispositivo com offline',
3677
- nl: 'Is een apparaat met offline',
3678
- fr: 'Est un appareil avec hors ligne',
3679
- it: 'È un dispositivo con offline',
3680
- es: 'Es un dispositivo sin conexión',
3681
- pl: 'Jest to jeden urządzenie z offlinem',
3682
- // @ts-ignore
3683
- uk: 'Є один пристрій з автономним',
3684
- 'zh-cn': '一处有线装置',
3685
- },
3686
- type: 'boolean',
3687
- role: 'state',
3688
- read: true,
3689
- write: false,
3690
- def: false,
3691
- },
3692
- native: {},
3693
- });
3694
-
3695
- await this.setObjectNotExistsAsync(`devices.${adptName}.listAllRawJSON`, {
3696
- type: 'state',
3697
- common: {
3698
- name: {
3699
- en: 'JSON RAW List of all devices',
3700
- de: 'JSON RAW Liste aller Geräte',
3701
- ru: 'ДЖСОН РАВ Список всех устройств',
3702
- pt: 'JSON RAW Lista de todos os dispositivos',
3703
- nl: 'JSON RAW List van alle apparaten',
3704
- fr: 'JSON RAW Liste de tous les dispositifs',
3705
- it: 'JSON RAW Elenco di tutti i dispositivi',
3706
- es: 'JSON RAW Lista de todos los dispositivos',
3707
- pl: 'JSON RAW Lista wszystkich urządzeń',
3708
- // @ts-ignore
3709
- uk: 'ДЖСОН РАВ Список всіх пристроїв',
3710
- 'zh-cn': 'JSONRAW 所有装置清单',
3711
- },
3712
- type: 'array',
3713
- role: 'json',
3714
- read: true,
3715
- write: false,
3716
- },
3717
- native: {},
3718
- });
3719
-
3720
- await this.setObjectNotExistsAsync(`devices.${adptName}.listAll`, {
3721
- type: 'state',
3722
- common: {
3723
- name: {
3724
- en: 'List of all devices',
3725
- de: 'Liste aller Geräte',
3726
- ru: 'Список всех устройств',
3727
- pt: 'Lista de todos os dispositivos',
3728
- nl: 'List van alle apparaten',
3729
- fr: 'Liste de tous les dispositifs',
3730
- it: 'Elenco di tutti i dispositivi',
3731
- es: 'Lista de todos los dispositivos',
3732
- pl: 'Lista wszystkich urządzeń',
3733
- 'zh-cn': '所有装置清单',
3734
- },
3735
- type: 'array',
3736
- role: 'json',
3737
- read: true,
3738
- write: false,
3739
- },
3740
- native: {},
3741
- });
3742
-
3743
- await this.setObjectNotExistsAsync(`devices.${adptName}.linkQualityList`, {
3744
- type: 'state',
3745
- common: {
3746
- name: {
3747
- en: 'List of devices with signal strength',
3748
- de: 'Liste der Geräte mit Signalstärke',
3749
- ru: 'Список устройств с силой сигнала',
3750
- pt: 'Lista de dispositivos com força de sinal',
3751
- nl: 'List van apparaten met signaalkracht',
3752
- fr: 'Liste des dispositifs avec force de signal',
3753
- it: 'Elenco dei dispositivi con forza del segnale',
3754
- es: 'Lista de dispositivos con fuerza de señal',
3755
- pl: 'Lista urządzeń z siłą sygnałową',
3756
- 'zh-cn': '具有信号实力的装置清单',
3757
- },
3758
- type: 'array',
3759
- role: 'json',
3760
- read: true,
3761
- write: false,
3762
- },
3763
- native: {},
3764
- });
3765
-
3766
- await this.setObjectNotExistsAsync(`devices.${adptName}.countAll`, {
3767
- type: 'state',
3768
- common: {
3769
- name: {
3770
- en: 'Number of all devices',
3771
- de: 'Anzahl aller Geräte',
3772
- ru: 'Количество всех устройств',
3773
- pt: 'Número de todos os dispositivos',
3774
- nl: 'Nummer van alle apparaten',
3775
- fr: 'Nombre de tous les appareils',
3776
- it: 'Numero di tutti i dispositivi',
3777
- es: 'Número de todos los dispositivos',
3778
- pl: 'Ilość wszystkich urządzeń',
3779
- 'zh-cn': '所有装置的数目',
3780
- },
3781
- type: 'number',
3782
- role: 'value',
3783
- read: true,
3784
- write: false,
3785
- },
3786
- native: {},
3787
- });
3788
-
3789
- await this.setObjectNotExistsAsync(`devices.${adptName}.batteryList`, {
3790
- type: 'state',
3791
- common: {
3792
- name: {
3793
- en: 'List of devices with battery state',
3794
- de: 'Liste der Geräte mit Batteriezustand',
3795
- ru: 'Список устройств с состоянием батареи',
3796
- pt: 'Lista de dispositivos com estado da bateria',
3797
- nl: 'List van apparaten met batterij staat',
3798
- fr: 'Liste des appareils avec état de batterie',
3799
- it: 'Elenco dei dispositivi con stato della batteria',
3800
- es: 'Lista de dispositivos con estado de batería',
3801
- pl: 'Lista urządzeń z baterią stanową',
3802
- 'zh-cn': '电池国装置清单',
3803
- },
3804
- type: 'array',
3805
- role: 'json',
3806
- read: true,
3807
- write: false,
3808
- },
3809
- native: {},
3810
- });
3811
-
3812
- await this.setObjectNotExistsAsync(`devices.${adptName}.lowBatteryList`, {
3813
- type: 'state',
3814
- common: {
3815
- name: {
3816
- en: 'List of devices with low battery state',
3817
- de: 'Liste der Geräte mit niedrigem Batteriezustand',
3818
- ru: 'Список устройств с низким состоянием батареи',
3819
- pt: 'Lista de dispositivos com baixo estado da bateria',
3820
- nl: 'List van apparaten met lage batterij staat',
3821
- fr: 'Liste des appareils à faible état de batterie',
3822
- it: 'Elenco di dispositivi con stato di batteria basso',
3823
- es: 'Lista de dispositivos con estado de batería bajo',
3824
- pl: 'Lista urządzeń o niskim stanie baterii',
3825
- 'zh-cn': '低电池国家装置清单',
3826
- },
3827
- type: 'array',
3828
- role: 'json',
3829
- read: true,
3830
- write: false,
3831
- },
3832
- native: {},
3833
- });
3834
-
3835
- await this.setObjectNotExistsAsync(`devices.${adptName}.lowBatteryCount`, {
3836
- type: 'state',
3837
- common: {
3838
- name: {
3839
- en: 'Number of devices with low battery',
3840
- de: 'Anzahl der Geräte mit niedriger Batterie',
3841
- ru: 'Количество устройств c низкой батареей',
3842
- pt: 'Número de dispositivos com bateria baixa',
3843
- nl: 'Nummer van apparaten met lage batterij',
3844
- fr: 'Nombre de dispositifs avec batterie basse',
3845
- it: 'Numero di dispositivi con batteria bassa',
3846
- es: 'Número de dispositivos con batería baja',
3847
- pl: 'Liczba urządzeń z niską baterią',
3848
- 'zh-cn': '低电池的装置数量',
3849
- },
3850
- type: 'number',
3851
- role: 'value',
3852
- read: true,
3853
- write: false,
3854
- },
3855
- native: {},
3856
- });
3857
-
3858
- await this.setObjectNotExistsAsync(`devices.${adptName}.oneDeviceLowBat`, {
3859
- type: 'state',
3860
- common: {
3861
- name: {
3862
- en: 'Is one device with low battery',
3863
- de: 'Ist ein Gerät mit niedrigem Akku',
3864
- ru: 'Один прибор с низкой батареей',
3865
- pt: 'É um dispositivo com bateria baixa',
3866
- nl: 'Is een apparaat met lage batterijen',
3867
- fr: 'Est un appareil avec batterie basse',
3868
- it: 'È un dispositivo con batteria bassa',
3869
- es: 'Es un dispositivo con batería baja',
3870
- pl: 'Jest to jeden urządzenie z niską baterią',
3871
- // @ts-ignore
3872
- uk: 'Є одним пристроєм з низьких акумуляторів',
3873
- 'zh-cn': '低电池的装置',
3874
- },
3875
- type: 'boolean',
3876
- role: 'state',
3877
- read: true,
3878
- write: false,
3879
- def: false,
3880
- },
3881
- native: {},
3882
- });
3883
-
3884
- await this.setObjectNotExistsAsync(`devices.${adptName}.batteryCount`, {
3885
- type: 'state',
3886
- common: {
3887
- name: {
3888
- en: 'Number of devices with battery',
3889
- de: 'Anzahl der Geräte mit Batterie',
3890
- ru: 'Количество устройств c батареей',
3891
- pt: 'Número de dispositivos com bateria',
3892
- nl: 'Nummer van apparaten met batterij',
3893
- fr: 'Nombre de dispositifs avec batterie',
3894
- it: 'Numero di dispositivi con batteria',
3895
- es: 'Número de dispositivos con batería',
3896
- pl: 'Liczba urządzeń z baterią',
3897
- 'zh-cn': '电池的装置数量',
3898
- },
3899
- type: 'number',
3900
- role: 'value',
3901
- read: true,
3902
- write: false,
3903
- },
3904
- native: {},
3905
- });
3906
-
3907
- await this.setObjectNotExistsAsync(`devices.${adptName}.upgradableCount`, {
3908
- type: 'state',
3909
- common: {
3910
- name: {
3911
- en: 'Number of devices with available updates ',
3912
- de: 'Anzahl der Geräte mit verfügbaren Updates',
3913
- ru: 'Количество устройств с доступными обновлениями',
3914
- pt: 'Número de dispositivos com atualizações disponíveis',
3915
- nl: 'Nummer van apparatuur met beschikbare updates',
3916
- fr: 'Nombre de dispositifs avec mises à jour disponibles',
3917
- it: 'Numero di dispositivi con aggiornamenti disponibili',
3918
- es: 'Número de dispositivos con actualizaciones disponibles',
3919
- pl: 'Liczba urządzeń z dostępną aktualizacją',
3920
- // @ts-ignore
3921
- uk: 'Кількість пристроїв з доступними оновленнями',
3922
- 'zh-cn': '现有更新的装置数目',
3923
- },
3924
- type: 'number',
3925
- role: 'value',
3926
- read: true,
3927
- write: false,
3928
- },
3929
- native: {},
3930
- });
3931
-
3932
- await this.setObjectNotExistsAsync(`devices.${adptName}.upgradableList`, {
3933
- type: 'state',
3934
- common: {
3935
- name: {
3936
- en: 'JSON List of devices with available updates ',
3937
- de: 'JSON Liste der Geräte mit verfügbaren Updates',
3938
- ru: 'ДЖСОН Список устройств с доступными обновлениями',
3939
- pt: 'J. Lista de dispositivos com atualizações disponíveis',
3940
- nl: 'JSON List van apparatuur met beschikbare updates',
3941
- fr: 'JSON Liste des appareils avec mises à jour disponibles',
3942
- it: 'JSON Elenco dei dispositivi con aggiornamenti disponibili',
3943
- es: 'JSON Lista de dispositivos con actualizaciones disponibles',
3944
- pl: 'JSON Lista urządzeń korzystających z aktualizacji',
3945
- // @ts-ignore
3946
- uk: 'Сонце Перелік пристроїв з доступними оновленнями',
3947
- 'zh-cn': '附 件 现有最新设备清单',
3948
- },
3949
- type: 'array',
3950
- role: 'json',
3951
- read: true,
3952
- write: false,
3953
- },
3954
- native: {},
3955
- });
3956
-
3957
- await this.setObjectNotExistsAsync(`devices.${adptName}.oneDeviceUpdatable`, {
3958
- type: 'state',
3959
- common: {
3960
- name: {
3961
- en: 'Is one device updatable',
3962
- de: 'Ist ein Gerät aufnehmbar',
3963
- ru: 'Одно устройство обновляется',
3964
- pt: 'É um dispositivo updatable',
3965
- nl: 'Is een apparaat updat',
3966
- fr: "Est-ce qu'un appareil est indéfectible",
3967
- it: 'È un dispositivo updatable',
3968
- es: 'Es un dispositivo actualizado',
3969
- pl: 'Jest to jedno urządzenie updatable',
3970
- // @ts-ignore
3971
- uk: 'Є одним пристроєм',
3972
- 'zh-cn': '一台装置',
3973
- },
3974
- type: 'boolean',
3975
- role: 'state',
3976
- read: true,
3977
- write: false,
3978
- def: false,
3979
- },
3980
- native: {},
3981
- });
3982
- }
3983
-
3984
- /**
3985
- * delete datapoints for each adapter
3986
- * @param {object} adptName - Adaptername of devices
3987
- */
3988
- async deleteDPsForEachAdapter(adptName) {
3989
- await this.delObjectAsync(`devices.${adptName}`);
3990
- await this.delObjectAsync(`devices.${adptName}.offlineCount`);
3991
- await this.delObjectAsync(`devices.${adptName}.offlineList`);
3992
- await this.delObjectAsync(`devices.${adptName}.oneDeviceOffline`);
3993
- await this.delObjectAsync(`devices.${adptName}.listAllRawJSON`);
3994
- await this.delObjectAsync(`devices.${adptName}.listAll`);
3995
- await this.delObjectAsync(`devices.${adptName}.linkQualityList`);
3996
- await this.delObjectAsync(`devices.${adptName}.countAll`);
3997
- await this.delObjectAsync(`devices.${adptName}.batteryList`);
3998
- await this.delObjectAsync(`devices.${adptName}.lowBatteryList`);
3999
- await this.delObjectAsync(`devices.${adptName}.lowBatteryCount`);
4000
- await this.delObjectAsync(`devices.${adptName}.oneDeviceLowBat`);
4001
- await this.delObjectAsync(`devices.${adptName}.batteryCount`);
4002
- await this.delObjectAsync(`devices.${adptName}.upgradableCount`);
4003
- await this.delObjectAsync(`devices.${adptName}.upgradableList`);
4004
- await this.delObjectAsync(`devices.${adptName}.oneDeviceUpdatable`);
4005
- }
4006
-
4007
- /**
4008
- * create HTML list datapoints
4009
- * @param {object} [adptName] - Adaptername of devices
4010
- **/
4011
- async createHtmlListDatapoints(adptName) {
4012
- let dpSubFolder;
4013
- //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
4014
- if (adptName) {
4015
- dpSubFolder = `${adptName}.`;
4016
- } else {
4017
- dpSubFolder = '';
4018
- }
4019
-
4020
- await this.setObjectNotExistsAsync(`devices.${dpSubFolder}offlineListHTML`, {
4021
- type: 'state',
4022
- common: {
4023
- name: {
4024
- en: 'HTML List of offline devices',
4025
- de: 'HTML Liste der Offline-Geräte',
4026
- ru: 'HTML Список оффлайн устройств',
4027
- pt: 'HTML Lista de dispositivos off-line',
4028
- nl: 'HTML List van offline apparatuur',
4029
- fr: 'HTML Liste des dispositifs hors ligne',
4030
- it: 'HTML Elenco dei dispositivi offline',
4031
- es: 'HTML Lista de dispositivos sin conexión',
4032
- pl: 'HTML Lista urządzeń offline',
4033
- 'zh-cn': 'HTML 线装置清单',
4034
- },
4035
- type: 'string',
4036
- role: 'html',
4037
- read: true,
4038
- write: false,
4039
- },
4040
- native: {},
4041
- });
4042
-
4043
- await this.setObjectNotExistsAsync(`devices.${dpSubFolder}linkQualityListHTML`, {
4044
- type: 'state',
4045
- common: {
4046
- name: {
4047
- en: 'HTML List of devices with signal strength',
4048
- de: 'HTML Liste der Geräte mit Signalstärke',
4049
- ru: 'HTML Список устройств с силой сигнала',
4050
- pt: 'HTML Lista de dispositivos com força de sinal',
4051
- nl: 'HTML List van apparaten met signaalkracht',
4052
- fr: 'HTML Liste des dispositifs avec force de signal',
4053
- it: 'HTML Elenco dei dispositivi con forza del segnale',
4054
- es: 'HTML Lista de dispositivos con fuerza de señal',
4055
- pl: 'HTML Lista urządzeń z siłą sygnałową',
4056
- 'zh-cn': 'HTML 具有信号实力的装置清单',
4057
- },
4058
- type: 'string',
4059
- role: 'value',
4060
- read: true,
4061
- write: false,
4062
- },
4063
- native: {},
4064
- });
4065
-
4066
- await this.setObjectNotExistsAsync(`devices.${dpSubFolder}batteryListHTML`, {
4067
- type: 'state',
4068
- common: {
4069
- name: {
4070
- en: 'HTML List of devices with battery state',
4071
- de: 'HTML Liste der Geräte mit Batteriezustand',
4072
- ru: 'HTML Список устройств с состоянием батареи',
4073
- pt: 'HTML Lista de dispositivos com estado da bateria',
4074
- nl: 'HTML List van apparaten met batterij staat',
4075
- fr: 'HTML Liste des appareils avec état de batterie',
4076
- it: 'HTML Elenco dei dispositivi con stato della batteria',
4077
- es: 'HTML Lista de dispositivos con estado de batería',
4078
- pl: 'HTML Lista urządzeń z baterią stanową',
4079
- 'zh-cn': 'HTML 电池国装置清单',
4080
- },
4081
- type: 'string',
4082
- role: 'html',
4083
- read: true,
4084
- write: false,
4085
- },
4086
- native: {},
4087
- });
4088
-
4089
- await this.setObjectNotExistsAsync(`devices.${dpSubFolder}lowBatteryListHTML`, {
4090
- type: 'state',
4091
- common: {
4092
- name: {
4093
- en: 'HTML List of devices with low battery state',
4094
- de: 'HTML Liste der Geräte mit niedrigem Batteriezustand',
4095
- ru: 'HTML Список устройств с низким состоянием батареи',
4096
- pt: 'HTML Lista de dispositivos com baixo estado da bateria',
4097
- nl: 'HTML List van apparaten met lage batterij staat',
4098
- fr: 'HTML Liste des appareils à faible état de batterie',
4099
- it: 'HTML Elenco di dispositivi con stato di batteria basso',
4100
- es: 'HTML Lista de dispositivos con estado de batería bajo',
4101
- pl: 'HTML Lista urządzeń o niskim stanie baterii',
4102
- 'zh-cn': 'HTML 低电池国家装置清单',
4103
- },
4104
- type: 'string',
4105
- role: 'html',
4106
- read: true,
4107
- write: false,
4108
- },
4109
- native: {},
4110
- });
4111
- }
4112
-
4113
- /**
4114
- * delete html datapoints
4115
- * @param {object} [adptName] - Adaptername of devices
4116
- **/
4117
- async deleteHtmlListDatapoints(adptName) {
4118
- // delete the datapoints in subfolders with the adaptername otherwise delete the dP's in the root folder
4119
- let dpSubFolder;
4120
- if (adptName) {
4121
- dpSubFolder = `${adptName}.`;
4122
- } else {
4123
- dpSubFolder = '';
4124
- }
4125
-
4126
- await this.delObjectAsync(`devices.${dpSubFolder}offlineListHTML`);
4127
- await this.delObjectAsync(`devices.${dpSubFolder}linkQualityListHTML`);
4128
- await this.delObjectAsync(`devices.${dpSubFolder}batteryListHTML`);
4129
- await this.delObjectAsync(`devices.${dpSubFolder}lowBatteryListHTML`);
4130
- }
4131
-
4132
- /**
4133
- * create HTML list datapoints for instances
4134
- **/
4135
- async createHtmlListDatapointsInstances() {
4136
- await this.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists`, {
4137
- type: 'channel',
4138
- common: {
4139
- name: {
4140
- en: 'HTML lists for adapter and instances',
4141
- de: 'HTML-Listen für Adapter und Instanzen',
4142
- ru: 'HTML-списки для адаптеров и инстанций',
4143
- pt: 'Listas HTML para adaptador e instâncias',
4144
- nl: 'HTML lijsten voor adapter en instituut',
4145
- fr: "Listes HTML pour l'adaptateur et les instances",
4146
- it: 'Elenchi HTML per adattatore e istanze',
4147
- es: 'Listas HTML para adaptador y casos',
4148
- pl: 'Listy HTML dla adaptera i instancji',
4149
- // @ts-ignore
4150
- uk: 'Списки HTML для адаптерів та екземплярів',
4151
- 'zh-cn': 'HTML名单',
4152
- },
4153
- },
4154
- native: {},
4155
- });
4156
- await this.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listAllInstancesHTML`, {
4157
- type: 'state',
4158
- common: {
4159
- name: {
4160
- en: 'HTML List of all instances',
4161
- de: 'HTML Liste aller Instanzen',
4162
- ru: 'HTML Список всех инстанций',
4163
- pt: 'HTML Lista de todas as instâncias',
4164
- nl: 'HTM List van alle instanties',
4165
- fr: 'HTML Liste de tous les cas',
4166
- it: 'HTML Elenco di tutte le istanze',
4167
- es: 'HTML Lista de todos los casos',
4168
- pl: 'HTML Lista wszystkich instancji',
4169
- // @ts-ignore
4170
- uk: 'Українська Список всіх екземплярів',
4171
- 'zh-cn': 'HTML 所有事例一览表',
4172
- },
4173
- type: 'string',
4174
- role: 'html',
4175
- read: true,
4176
- write: false,
4177
- },
4178
- native: {},
4179
- });
4180
-
4181
- await this.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listAllActiveInstancesHTML`, {
4182
- type: 'state',
4183
- common: {
4184
- name: {
4185
- en: 'HTML List of all active instances',
4186
- de: 'HTML Liste aller aktiven Instanzen',
4187
- ru: 'HTML Список всех активных инстанций',
4188
- pt: 'HTML Lista de todas as instâncias ativas',
4189
- nl: 'HTM List van alle actieve instanties',
4190
- fr: 'HTML Liste de tous les cas actifs',
4191
- it: 'HTML Elenco di tutte le istanze attive',
4192
- es: 'HTML Lista de todos los casos activos',
4193
- pl: 'HTML Lista wszystkich aktywnych instancji',
4194
- // @ts-ignore
4195
- uk: 'Українська Список всіх активних екземплярів',
4196
- 'zh-cn': 'HTML 所有积极事件清单',
4197
- },
4198
- type: 'string',
4199
- role: 'value',
4200
- read: true,
4201
- write: false,
4202
- },
4203
- native: {},
4204
- });
4205
-
4206
- await this.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listDeactivatedInstancesHTML`, {
4207
- type: 'state',
4208
- common: {
4209
- name: {
4210
- en: 'HTML List of all deactivated instances',
4211
- de: 'HTML Liste aller deaktivierten Instanzen',
4212
- ru: 'HTML Список всех деактивированных инстанций',
4213
- pt: 'HTML Lista de todas as instâncias desativadas',
4214
- nl: 'HTM List van alle gedeactiveerde instanties',
4215
- fr: 'HTML Liste de tous les cas désactivés',
4216
- it: 'HTML Elenco di tutte le istanze disattivate',
4217
- es: 'HTML Lista de todos los casos desactivados',
4218
- pl: 'HTML Lista wszystkich przypadków deaktywowanych',
4219
- // @ts-ignore
4220
- uk: 'Українська Список всіх деактивованих екземплярів',
4221
- 'zh-cn': 'HTML 所有违犯事件清单',
4222
- },
4223
- type: 'string',
4224
- role: 'html',
4225
- read: true,
4226
- write: false,
4227
- },
4228
- native: {},
4229
- });
4230
-
4231
- await this.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listInstancesErrorHTML`, {
4232
- type: 'state',
4233
- common: {
4234
- name: {
4235
- en: 'HTML List of instances with error',
4236
- de: 'HTML Liste der Fälle mit Fehler',
4237
- ru: 'HTML Список инстанций с ошибкой',
4238
- pt: 'HTML Lista de casos com erro',
4239
- nl: 'HTM List van instoringen met fouten',
4240
- fr: 'HTML Liste des instances avec erreur',
4241
- it: 'HTML Elenco delle istanze con errore',
4242
- es: 'HTML Lista de casos con error',
4243
- pl: 'HTML Lista przykładów z błądem',
4244
- // @ts-ignore
4245
- uk: 'Українська Список екземплярів з помилкою',
4246
- 'zh-cn': 'HTML 出现错误的情况清单',
4247
- },
4248
- type: 'string',
4249
- role: 'html',
4250
- read: true,
4251
- write: false,
4252
- },
4253
- native: {},
4254
- });
4255
- await this.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listAdapterUpdatesHTML`, {
4256
- type: 'state',
4257
- common: {
4258
- name: {
4259
- en: 'HTML list of adapters with available updates',
4260
- de: 'HTML-Liste der Adapter mit verfügbaren Updates',
4261
- ru: 'HTML список адаптеров с доступными обновлениями',
4262
- pt: 'Lista HTML de adaptadores com atualizações disponíveis',
4263
- nl: 'HTML lijst met beschikbare updates',
4264
- fr: 'Liste HTML des adaptateurs avec mises à jour disponibles',
4265
- it: 'Elenco HTML degli adattatori con aggiornamenti disponibili',
4266
- es: 'Lista HTML de adaptadores con actualizaciones disponibles',
4267
- pl: 'Lista adapterów HTML z dostępnymi aktualizacjami',
4268
- // @ts-ignore
4269
- uk: 'HTML список адаптерів з доступними оновленнями',
4270
- 'zh-cn': 'HTML 可供更新的适应者名单',
4271
- },
4272
- type: 'string',
4273
- role: 'html',
4274
- read: true,
4275
- write: false,
4276
- },
4277
- native: {},
4278
- });
4279
- }
4280
-
4281
- /**
4282
- * delete html datapoints for instances
4283
- **/
4284
- async deleteHtmlListDatapointsInstances() {
4285
- await this.delObjectAsync(`adapterAndInstances.HTML_Lists.listAllInstancesHTML`);
4286
- await this.delObjectAsync(`adapterAndInstances.HTML_Lists.listAllActiveInstancesHTML`);
4287
- await this.delObjectAsync(`adapterAndInstances.HTML_Lists.listDeactivatedInstancesHTML`);
4288
- await this.delObjectAsync(`adapterAndInstances.HTML_Lists.listInstancesErrorHTML`);
4289
- await this.delObjectAsync(`adapterAndInstances.HTML_Lists.listAdapterUpdatesHTML`);
4290
- await this.delObjectAsync(`adapterAndInstances.HTML_Lists`);
4291
- }
4292
-
4293
- /*=============================================
4294
- = help functions =
4295
- =============================================*/
4296
-
4297
- /**
4298
- * @param {string} id - id which should be capitalize
4299
- */
4300
- capitalize(id) {
4301
- //make the first letter uppercase
4302
- return id && id[0].toUpperCase() + id.slice(1);
4303
- }
4304
-
4305
- /**
4306
- * @param {number} dpValue - get Time of this datapoint
4307
- */
4308
- getTimestamp(dpValue) {
4309
- const time = new Date();
4310
- return (dpValue = Math.round((time.getTime() - dpValue) / 1000 / 60));
4311
- }
4312
-
4313
- /**
4314
- * @param {string} dp - get Time of this datapoint
4315
- * @param {number} ms - milliseconds
4316
- */
4317
- async getTimestampConnectionDP(dp, ms) {
4318
- const time = new Date();
4319
- const dpValue = await this.getForeignStateAsync(dp);
4320
- if (dpValue) {
4321
- if (!dpValue.val) return false;
4322
-
4323
- const dpLastStateChange = Math.round(time.getTime() - dpValue.lc); // calculate in ms
4324
- if (dpLastStateChange >= ms) {
4325
- return true;
4326
- } else {
4327
- return false;
4328
- }
4329
- }
4330
- }
4331
-
4332
- /**
4333
- * @param {object} obj - State of datapoint
4334
- */
4335
- async getInitValue(obj) {
4336
- //state can be null or undefinded
4337
- const foreignState = await this.getForeignStateAsync(obj);
4338
- if (foreignState) return foreignState.val;
4339
- }
4340
-
4341
- /**
4342
- * @param {object} obj - State of own datapoint
4343
- */
4344
- async getOwnInitValue(obj) {
4345
- //state can be null or undefinded for own states
4346
- const stateVal = await this.getStateAsync(obj);
4347
- if (stateVal) return stateVal.val;
4348
- }
4349
-
4350
- /**
4351
- * @param {object} data - object
4352
- */
4353
- parseData(data) {
4354
- if (!data) return {};
4355
- if (typeof data === 'object') return data;
4356
- if (typeof data === 'string') return JSON.parse(data);
4357
- return {};
4358
- }
4359
-
4360
- /**
4361
- * Get previous run of cron job schedule
4362
- * Requires cron-parser!
4363
- * Inspired by https://stackoverflow.com/questions/68134104/
4364
- * @param {string} lastCronRun
4365
- */
4366
- getPreviousCronRun(lastCronRun) {
4367
- try {
4368
- const interval = cronParser.parseExpression(lastCronRun);
4369
- const previous = interval.prev();
4370
- return Math.floor(Date.now() - previous.getTime()); // in ms
4371
- } catch (error) {
4372
- this.log.error(`[getPreviousCronRun] - ${error}`);
4373
- }
4374
- }
4375
-
4376
2351
  /**
4377
2352
  * @param {() => void} callback
4378
2353
  */