iobroker.device-watcher 2.12.3 → 2.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/crud.js ADDED
@@ -0,0 +1,1932 @@
1
+ const translations = require("./translations");
2
+ const tools = require("./tools");
3
+
4
+ /**
5
+ * @param {object} adptName - Adaptername of devices
6
+ */
7
+ async function createDPsForEachAdapter(adaptr, adptName) {
8
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}`, {
9
+ type: 'channel',
10
+ common: {
11
+ name: adptName,
12
+ },
13
+ native: {},
14
+ });
15
+
16
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.offlineCount`, {
17
+ type: 'state',
18
+ common: {
19
+ name: {
20
+ en: 'Number of devices offline',
21
+ de: 'Anzahl der Geräte offline',
22
+ ru: 'Количество устройств оффлайн',
23
+ pt: 'Número de dispositivos offline',
24
+ nl: 'Aantal offline apparaten',
25
+ fr: 'Nombre de dispositifs hors ligne',
26
+ it: 'Numero di dispositivi offline',
27
+ es: 'Número de dispositivos sin conexión',
28
+ pl: 'Liczba urządzeń offline',
29
+ 'zh-cn': '离线设备数量',
30
+ },
31
+ type: 'number',
32
+ role: 'value',
33
+ read: true,
34
+ write: false,
35
+ },
36
+ native: {},
37
+ });
38
+
39
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.offlineList`, {
40
+ type: 'state',
41
+ common: {
42
+ name: {
43
+ en: 'List of offline devices',
44
+ de: 'Liste der Offline-Geräte',
45
+ ru: 'Список оффлайн устройств',
46
+ pt: 'Lista de dispositivos offline',
47
+ nl: 'Lijst van offline apparaten',
48
+ fr: 'Liste des dispositifs hors ligne',
49
+ it: 'Elenco dei dispositivi offline',
50
+ es: 'Lista de dispositivos sin conexión',
51
+ pl: 'Lista urządzeń offline',
52
+ 'zh-cn': '离线设备列表',
53
+ },
54
+ type: 'array',
55
+ role: 'json',
56
+ read: true,
57
+ write: false,
58
+ },
59
+ native: {},
60
+ });
61
+
62
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.oneDeviceOffline`, {
63
+ type: 'state',
64
+ common: {
65
+ name: {
66
+ en: 'Is one device offline',
67
+ de: 'Ist ein Gerät offline',
68
+ ru: 'Есть ли одно устройство оффлайн',
69
+ pt: 'Há um dispositivo offline',
70
+ nl: 'Is er een apparaat offline',
71
+ fr: 'Y a-t-il un appareil hors ligne',
72
+ it: 'C\'è un dispositivo offline',
73
+ es: '¿Hay un dispositivo sin conexión?',
74
+ pl: 'Czy jedno urządzenie jest offline',
75
+ uk: 'Чи є один пристрій офлайн',
76
+ 'zh-cn': '是否有一台设备离线',
77
+ },
78
+ type: 'boolean',
79
+ role: 'state',
80
+ read: true,
81
+ write: false,
82
+ def: false,
83
+ },
84
+ native: {},
85
+ });
86
+
87
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.listAllRawJSON`, {
88
+ type: 'state',
89
+ common: {
90
+ name: {
91
+ en: 'JSON RAW List of all devices',
92
+ de: 'JSON RAW Liste aller Geräte',
93
+ ru: 'JSON RAW Список всех устройств',
94
+ pt: 'JSON RAW Lista de todos os dispositivos',
95
+ nl: 'JSON RAW Lijst van alle apparaten',
96
+ fr: 'JSON RAW Liste de tous les dispositifs',
97
+ it: 'JSON RAW Elenco di tutti i dispositivi',
98
+ es: 'JSON RAW Lista de todos los dispositivos',
99
+ pl: 'JSON RAW Lista wszystkich urządzeń',
100
+ uk: 'JSON RAW Список усіх пристроїв',
101
+ 'zh-cn': 'JSON RAW 所有设备列表',
102
+ },
103
+ type: 'array',
104
+ role: 'json',
105
+ read: true,
106
+ write: false,
107
+ },
108
+ native: {},
109
+ });
110
+
111
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.listAll`, {
112
+ type: 'state',
113
+ common: {
114
+ name: {
115
+ en: 'List of all devices',
116
+ de: 'Liste aller Geräte',
117
+ ru: 'Список всех устройств',
118
+ pt: 'Lista de todos os dispositivos',
119
+ nl: 'Lijst van alle apparaten',
120
+ fr: 'Liste de tous les dispositifs',
121
+ it: 'Elenco di tutti i dispositivi',
122
+ es: 'Lista de todos los dispositivos',
123
+ pl: 'Lista wszystkich urządzeń',
124
+ 'zh-cn': '所有设备的列表',
125
+ },
126
+ type: 'array',
127
+ role: 'json',
128
+ read: true,
129
+ write: false,
130
+ },
131
+ native: {},
132
+ });
133
+
134
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.linkQualityList`, {
135
+ type: 'state',
136
+ common: {
137
+ name: {
138
+ en: 'List of devices with signal strength',
139
+ de: 'Liste der Geräte mit Signalstärke',
140
+ ru: 'Список устройств с уровнем сигнала',
141
+ pt: 'Lista de dispositivos com força de sinal',
142
+ nl: 'Lijst van apparaten met signaalkracht',
143
+ fr: 'Liste des dispositifs avec force de signal',
144
+ it: 'Elenco dei dispositivi con forza del segnale',
145
+ es: 'Lista de dispositivos con fuerza de señal',
146
+ pl: 'Lista urządzeń z siłą sygnału',
147
+ 'zh-cn': '具有信号强度的设备列表',
148
+ },
149
+ type: 'array',
150
+ role: 'json',
151
+ read: true,
152
+ write: false,
153
+ },
154
+ native: {},
155
+ });
156
+
157
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.countAll`, {
158
+ type: 'state',
159
+ common: {
160
+ name: {
161
+ en: 'Number of all devices',
162
+ de: 'Anzahl aller Geräte',
163
+ ru: 'Количество всех устройств',
164
+ pt: 'Número de todos os dispositivos',
165
+ nl: 'Aantal van alle apparaten',
166
+ fr: 'Nombre de tous les appareils',
167
+ it: 'Numero di tutti i dispositivi',
168
+ es: 'Número de todos los dispositivos',
169
+ pl: 'Liczba wszystkich urządzeń',
170
+ 'zh-cn': '所有设备的数量',
171
+ },
172
+ type: 'number',
173
+ role: 'value',
174
+ read: true,
175
+ write: false,
176
+ },
177
+ native: {},
178
+ });
179
+
180
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.batteryList`, {
181
+ type: 'state',
182
+ common: {
183
+ name: {
184
+ en: 'List of devices with battery state',
185
+ de: 'Liste der Geräte mit Batteriezustand',
186
+ ru: 'Список устройств с состоянием батареи',
187
+ pt: 'Lista de dispositivos com estado da bateria',
188
+ nl: 'Lijst van apparaten met batterijstatus',
189
+ fr: 'Liste des appareils avec état de batterie',
190
+ it: 'Elenco dei dispositivi con stato della batteria',
191
+ es: 'Lista de dispositivos con estado de batería',
192
+ pl: 'Lista urządzeń ze stanem baterii',
193
+ 'zh-cn': '具有电池状态的设备列表',
194
+ },
195
+ type: 'array',
196
+ role: 'json',
197
+ read: true,
198
+ write: false,
199
+ },
200
+ native: {},
201
+ });
202
+
203
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.lowBatteryList`, {
204
+ type: 'state',
205
+ common: {
206
+ name: {
207
+ en: 'List of devices with low battery state',
208
+ de: 'Liste der Geräte mit niedrigem Batteriezustand',
209
+ ru: 'Список устройств с низким уровнем заряда батареи',
210
+ pt: 'Lista de dispositivos com baixo estado da bateria',
211
+ nl: 'Lijst van apparaten met lage batterijstatus',
212
+ fr: 'Liste des appareils à faible état de batterie',
213
+ it: 'Elenco di dispositivi con stato di batteria basso',
214
+ es: 'Lista de dispositivos con estado de batería bajo',
215
+ pl: 'Lista urządzeń o niskim stanie baterii',
216
+ 'zh-cn': '低电量设备列表',
217
+ },
218
+ type: 'array',
219
+ role: 'json',
220
+ read: true,
221
+ write: false,
222
+ },
223
+ native: {},
224
+ });
225
+
226
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.lowBatteryCount`, {
227
+ type: 'state',
228
+ common: {
229
+ name: {
230
+ en: 'Number of devices with low battery',
231
+ de: 'Anzahl der Geräte mit niedriger Batterie',
232
+ ru: 'Количество устройств с низким зарядом батареи',
233
+ pt: 'Número de dispositivos com bateria baixa',
234
+ nl: 'Aantal apparaten met lage batterij',
235
+ fr: 'Nombre de dispositifs avec batterie faible',
236
+ it: 'Numero di dispositivi con batteria scarica',
237
+ es: 'Número de dispositivos con batería baja',
238
+ pl: 'Liczba urządzeń z niskim poziomem baterii',
239
+ 'zh-cn': '低电量设备的数量',
240
+ },
241
+ type: 'number',
242
+ role: 'value',
243
+ read: true,
244
+ write: false,
245
+ },
246
+ native: {},
247
+ });
248
+
249
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.oneDeviceLowBat`, {
250
+ type: 'state',
251
+ common: {
252
+ name: {
253
+ en: 'Is one device with low battery',
254
+ de: 'Ist ein Gerät mit niedrigem Akku',
255
+ ru: 'Есть ли устройство с низким зарядом батареи',
256
+ pt: 'É um dispositivo com bateria baixa',
257
+ nl: 'Is er een apparaat met lage batterij',
258
+ fr: 'Y a-t-il un appareil avec batterie faible',
259
+ it: 'C\'è un dispositivo con batteria scarica',
260
+ es: '¿Hay un dispositivo con batería baja?',
261
+ pl: 'Czy jest jedno urządzenie z niskim poziomem baterii',
262
+ uk: 'Чи є пристрій з низьким зарядом батареї',
263
+ 'zh-cn': '是否有设备电量低',
264
+ },
265
+ type: 'boolean',
266
+ role: 'state',
267
+ read: true,
268
+ write: false,
269
+ def: false,
270
+ },
271
+ native: {},
272
+ });
273
+
274
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.batteryCount`, {
275
+ type: 'state',
276
+ common: {
277
+ name: {
278
+ en: 'Number of devices with battery',
279
+ de: 'Anzahl der Geräte mit Batterie',
280
+ ru: 'Количество устройств с батареей',
281
+ pt: 'Número de dispositivos com bateria',
282
+ nl: 'Aantal apparaten met batterij',
283
+ fr: 'Nombre de dispositifs avec batterie',
284
+ it: 'Numero di dispositivi con batteria',
285
+ es: 'Número de dispositivos con batería',
286
+ pl: 'Liczba urządzeń z baterią',
287
+ 'zh-cn': '带电池的设备数量',
288
+ },
289
+ type: 'number',
290
+ role: 'value',
291
+ read: true,
292
+ write: false,
293
+ },
294
+ native: {},
295
+ });
296
+
297
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.upgradableCount`, {
298
+ type: 'state',
299
+ common: {
300
+ name: {
301
+ en: 'Number of devices with available updates',
302
+ de: 'Anzahl der Geräte mit verfügbaren Updates',
303
+ ru: 'Количество устройств с доступными обновлениями',
304
+ pt: 'Número de dispositivos com atualizações disponíveis',
305
+ nl: 'Aantal apparaten met beschikbare updates',
306
+ fr: 'Nombre de dispositifs avec mises à jour disponibles',
307
+ it: 'Numero di dispositivi con aggiornamenti disponibili',
308
+ es: 'Número de dispositivos con actualizaciones disponibles',
309
+ pl: 'Liczba urządzeń z dostępnymi aktualizacjami',
310
+ uk: 'Кількість пристроїв з доступними оновленнями',
311
+ 'zh-cn': '具有可用更新的设备数量',
312
+ },
313
+ type: 'number',
314
+ role: 'value',
315
+ read: true,
316
+ write: false,
317
+ },
318
+ native: {},
319
+ });
320
+
321
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.upgradableList`, {
322
+ type: 'state',
323
+ common: {
324
+ name: {
325
+ en: 'JSON List of devices with available updates',
326
+ de: 'JSON Liste der Geräte mit verfügbaren Updates',
327
+ ru: 'JSON список устройств с доступными обновлениями',
328
+ pt: 'JSON Lista de dispositivos com atualizações disponíveis',
329
+ nl: 'JSON Lijst van apparaten met beschikbare updates',
330
+ fr: 'JSON Liste des appareils avec mises à jour disponibles',
331
+ it: 'JSON Elenco dei dispositivi con aggiornamenti disponibili',
332
+ es: 'JSON Lista de dispositivos con actualizaciones disponibles',
333
+ pl: 'JSON Lista urządzeń z dostępnymi aktualizacjami',
334
+ uk: 'JSON список пристроїв з доступними оновленнями',
335
+ 'zh-cn': '具有可用更新的设备的 JSON 列表',
336
+ },
337
+ type: 'array',
338
+ role: 'json',
339
+ read: true,
340
+ write: false,
341
+ },
342
+ native: {},
343
+ });
344
+
345
+ await adaptr.setObjectNotExistsAsync(`devices.${adptName}.oneDeviceUpdatable`, {
346
+ type: 'state',
347
+ common: {
348
+ name: {
349
+ en: 'Is one device updatable',
350
+ de: 'Ist ein Gerät aktualisierbar',
351
+ ru: 'Можно ли обновить одно устройство',
352
+ pt: 'É um dispositivo atualizável',
353
+ nl: 'Is er een apparaat dat kan worden bijgewerkt',
354
+ fr: "Y a-t-il un appareil qui peut être mis à jour",
355
+ it: 'C\'è un dispositivo aggiornabile',
356
+ es: '¿Hay un dispositivo actualizable?',
357
+ pl: 'Czy jest jedno urządzenie do zaktualizowania',
358
+ uk: 'Чи є пристрій, який можна оновити',
359
+ 'zh-cn': '是否有设备可更新',
360
+ },
361
+ type: 'boolean',
362
+ role: 'state',
363
+ read: true,
364
+ write: false,
365
+ def: false,
366
+ },
367
+ native: {},
368
+ });
369
+ }
370
+
371
+ /**
372
+ * delete datapoints for each adapter
373
+ * @param {object} adptName - Adaptername of devices
374
+ */
375
+ async function deleteDPsForEachAdapter(adaptr, adptName) {
376
+ await adaptr.delObjectAsync(`devices.${adptName}`);
377
+ await adaptr.delObjectAsync(`devices.${adptName}.offlineCount`);
378
+ await adaptr.delObjectAsync(`devices.${adptName}.offlineList`);
379
+ await adaptr.delObjectAsync(`devices.${adptName}.oneDeviceOffline`);
380
+ await adaptr.delObjectAsync(`devices.${adptName}.listAllRawJSON`);
381
+ await adaptr.delObjectAsync(`devices.${adptName}.listAll`);
382
+ await adaptr.delObjectAsync(`devices.${adptName}.linkQualityList`);
383
+ await adaptr.delObjectAsync(`devices.${adptName}.countAll`);
384
+ await adaptr.delObjectAsync(`devices.${adptName}.batteryList`);
385
+ await adaptr.delObjectAsync(`devices.${adptName}.lowBatteryList`);
386
+ await adaptr.delObjectAsync(`devices.${adptName}.lowBatteryCount`);
387
+ await adaptr.delObjectAsync(`devices.${adptName}.oneDeviceLowBat`);
388
+ await adaptr.delObjectAsync(`devices.${adptName}.batteryCount`);
389
+ await adaptr.delObjectAsync(`devices.${adptName}.upgradableCount`);
390
+ await adaptr.delObjectAsync(`devices.${adptName}.upgradableList`);
391
+ await adaptr.delObjectAsync(`devices.${adptName}.oneDeviceUpdatable`);
392
+ }
393
+
394
+ /**
395
+ * create HTML list datapoints
396
+ * @param {object} [adptName] - Adaptername of devices
397
+ **/
398
+ async function createHtmlListDatapoints(adaptr, adptName) {
399
+ let dpSubFolder;
400
+ //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
401
+ if (adptName) {
402
+ dpSubFolder = `${adptName}.`;
403
+ } else {
404
+ dpSubFolder = '';
405
+ }
406
+
407
+ await adaptr.setObjectNotExistsAsync(`devices.${dpSubFolder}offlineListHTML`, {
408
+ type: 'state',
409
+ common: {
410
+ name: {
411
+ en: 'HTML List of offline devices',
412
+ de: 'HTML Liste der Offline-Geräte',
413
+ ru: 'HTML список оффлайн устройств',
414
+ pt: 'HTML Lista de dispositivos offline',
415
+ nl: 'HTML Lijst van offline apparaten',
416
+ fr: 'HTML Liste des dispositifs hors ligne',
417
+ it: 'HTML Elenco dei dispositivi offline',
418
+ es: 'HTML Lista de dispositivos sin conexión',
419
+ pl: 'HTML Lista urządzeń offline',
420
+ 'zh-cn': 'HTML 离线设备列表',
421
+ },
422
+ type: 'string',
423
+ role: 'html',
424
+ read: true,
425
+ write: false,
426
+ },
427
+ native: {},
428
+ });
429
+
430
+ await adaptr.setObjectNotExistsAsync(`devices.${dpSubFolder}linkQualityListHTML`, {
431
+ type: 'state',
432
+ common: {
433
+ name: {
434
+ en: 'HTML List of devices with signal strength',
435
+ de: 'HTML Liste der Geräte mit Signalstärke',
436
+ ru: 'HTML список устройств с уровнем сигнала',
437
+ pt: 'HTML Lista de dispositivos com força de sinal',
438
+ nl: 'HTML Lijst van apparaten met signaalkracht',
439
+ fr: 'HTML Liste des dispositifs avec force de signal',
440
+ it: 'HTML Elenco dei dispositivi con forza del segnale',
441
+ es: 'HTML Lista de dispositivos con fuerza de señal',
442
+ pl: 'HTML Lista urządzeń z siłą sygnału',
443
+ 'zh-cn': 'HTML 具有信号强度的设备列表',
444
+ },
445
+ type: 'string',
446
+ role: 'value',
447
+ read: true,
448
+ write: false,
449
+ },
450
+ native: {},
451
+ });
452
+
453
+ await adaptr.setObjectNotExistsAsync(`devices.${dpSubFolder}batteryListHTML`, {
454
+ type: 'state',
455
+ common: {
456
+ name: {
457
+ en: 'HTML List of devices with battery state',
458
+ de: 'HTML Liste der Geräte mit Batteriezustand',
459
+ ru: 'HTML список устройств с состоянием батареи',
460
+ pt: 'HTML Lista de dispositivos com estado da bateria',
461
+ nl: 'HTML Lijst van apparaten met batterijstatus',
462
+ fr: 'HTML Liste des appareils avec état de batterie',
463
+ it: 'HTML Elenco dei dispositivi con stato della batteria',
464
+ es: 'HTML Lista de dispositivos con estado de batería',
465
+ pl: 'HTML Lista urządzeń ze stanem baterii',
466
+ 'zh-cn': 'HTML 具有电池状态的设备列表',
467
+ },
468
+ type: 'string',
469
+ role: 'html',
470
+ read: true,
471
+ write: false,
472
+ },
473
+ native: {},
474
+ });
475
+
476
+ await adaptr.setObjectNotExistsAsync(`devices.${dpSubFolder}lowBatteryListHTML`, {
477
+ type: 'state',
478
+ common: {
479
+ name: {
480
+ en: 'HTML List of devices with low battery state',
481
+ de: 'HTML Liste der Geräte mit niedrigem Batteriezustand',
482
+ ru: 'HTML список устройств с низким уровнем заряда батареи',
483
+ pt: 'HTML Lista de dispositivos com baixo estado da bateria',
484
+ nl: 'HTML Lijst van apparaten met lage batterijstatus',
485
+ fr: 'HTML Liste des appareils à faible état de batterie',
486
+ it: 'HTML Elenco di dispositivi con stato di batteria basso',
487
+ es: 'HTML Lista de dispositivos con estado de batería bajo',
488
+ pl: 'HTML Lista urządzeń o niskim stanie baterii',
489
+ 'zh-cn': 'HTML 低电量设备列表',
490
+ },
491
+ type: 'string',
492
+ role: 'html',
493
+ read: true,
494
+ write: false,
495
+ },
496
+ native: {},
497
+ });
498
+ }
499
+
500
+ /**
501
+ * delete html datapoints
502
+ * @param {object} [adptName] - Adaptername of devices
503
+ **/
504
+ async function deleteHtmlListDatapoints(adaptr, adptName) {
505
+ // delete the datapoints in subfolders with the adaptername otherwise delete the dP's in the root folder
506
+ let dpSubFolder;
507
+ if (adptName) {
508
+ dpSubFolder = `${adptName}.`;
509
+ } else {
510
+ dpSubFolder = '';
511
+ }
512
+
513
+ await adaptr.delObjectAsync(`devices.${dpSubFolder}offlineListHTML`);
514
+ await adaptr.delObjectAsync(`devices.${dpSubFolder}linkQualityListHTML`);
515
+ await adaptr.delObjectAsync(`devices.${dpSubFolder}batteryListHTML`);
516
+ await adaptr.delObjectAsync(`devices.${dpSubFolder}lowBatteryListHTML`);
517
+ }
518
+
519
+ /**
520
+ * create HTML list datapoints for instances
521
+ **/
522
+ async function createHtmlListDatapointsInstances(adaptr) {
523
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists`, {
524
+ type: 'channel',
525
+ common: {
526
+ name: {
527
+ en: 'HTML lists for adapter and instances',
528
+ de: 'HTML-Listen für Adapter und Instanzen',
529
+ ru: 'HTML списки для адаптера и экземпляров',
530
+ pt: 'Listas HTML para adaptador e instâncias',
531
+ nl: 'HTML lijsten voor adapter en instanties',
532
+ fr: "Listes HTML pour l'adaptateur et les instances",
533
+ it: 'Elenchi HTML per adattatore e istanze',
534
+ es: 'Listas HTML para adaptador e instancias',
535
+ pl: 'Listy HTML dla adaptera i instancji',
536
+ uk: 'HTML списки для адаптера та екземплярів',
537
+ 'zh-cn': '适配器和实例的 HTML 列表',
538
+ },
539
+ },
540
+ native: {},
541
+ });
542
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listAllInstancesHTML`, {
543
+ type: 'state',
544
+ common: {
545
+ name: {
546
+ en: 'HTML List of all instances',
547
+ de: 'HTML Liste aller Instanzen',
548
+ ru: 'HTML список всех экземпляров',
549
+ pt: 'HTML Lista de todas as instâncias',
550
+ nl: 'HTML Lijst van alle instanties',
551
+ fr: 'HTML Liste de toutes les instances',
552
+ it: 'HTML Elenco di tutte le istanze',
553
+ es: 'HTML Lista de todas las instancias',
554
+ pl: 'HTML Lista wszystkich instancji',
555
+ uk: 'HTML список усіх екземплярів',
556
+ 'zh-cn': 'HTML 所有实例的列表',
557
+ },
558
+ type: 'string',
559
+ role: 'html',
560
+ read: true,
561
+ write: false,
562
+ },
563
+ native: {},
564
+ });
565
+
566
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listAllActiveInstancesHTML`, {
567
+ type: 'state',
568
+ common: {
569
+ name: {
570
+ en: 'HTML List of all active instances',
571
+ de: 'HTML Liste aller aktiven Instanzen',
572
+ ru: 'HTML список всех активных экземпляров',
573
+ pt: 'HTML Lista de todas as instâncias ativas',
574
+ nl: 'HTML Lijst van alle actieve instanties',
575
+ fr: 'HTML Liste de toutes les instances actives',
576
+ it: 'HTML Elenco di tutte le istanze attive',
577
+ es: 'HTML Lista de todas las instancias activas',
578
+ pl: 'HTML Lista wszystkich aktywnych instancji',
579
+ uk: 'HTML список усіх активних екземплярів',
580
+ 'zh-cn': 'HTML 所有活动实例的列表',
581
+ },
582
+ type: 'string',
583
+ role: 'value',
584
+ read: true,
585
+ write: false,
586
+ },
587
+ native: {},
588
+ });
589
+
590
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listDeactivatedInstancesHTML`, {
591
+ type: 'state',
592
+ common: {
593
+ name: {
594
+ en: 'HTML List of all deactivated instances',
595
+ de: 'HTML Liste aller deaktivierten Instanzen',
596
+ ru: 'HTML список всех деактивированных экземпляров',
597
+ pt: 'HTML Lista de todas as instâncias desativadas',
598
+ nl: 'HTML Lijst van alle gedeactiveerde instanties',
599
+ fr: 'HTML Liste de toutes les instances désactivées',
600
+ it: 'HTML Elenco di tutte le istanze disattivate',
601
+ es: 'HTML Lista de todas las instancias desactivadas',
602
+ pl: 'HTML Lista wszystkich dezaktywowanych instancji',
603
+ uk: 'HTML список усіх деактивованих екземплярів',
604
+ 'zh-cn': 'HTML 所有已停用实例的列表',
605
+ },
606
+ type: 'string',
607
+ role: 'html',
608
+ read: true,
609
+ write: false,
610
+ },
611
+ native: {},
612
+ });
613
+
614
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listInstancesErrorHTML`, {
615
+ type: 'state',
616
+ common: {
617
+ name: {
618
+ en: 'HTML List of instances with error',
619
+ de: 'HTML Liste der Instanzen mit Fehler',
620
+ ru: 'HTML список экземпляров с ошибкой',
621
+ pt: 'HTML Lista de instâncias com erro',
622
+ nl: 'HTML Lijst van instanties met fouten',
623
+ fr: 'HTML Liste des instances avec erreur',
624
+ it: 'HTML Elenco delle istanze con errore',
625
+ es: 'HTML Lista de instancias con error',
626
+ pl: 'HTML Lista instancji z błędem',
627
+ uk: 'HTML список екземплярів з помилкою',
628
+ 'zh-cn': 'HTML 含错误实例的列表',
629
+ },
630
+ type: 'string',
631
+ role: 'html',
632
+ read: true,
633
+ write: false,
634
+ },
635
+ native: {},
636
+ });
637
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.HTML_Lists.listAdapterUpdatesHTML`, {
638
+ type: 'state',
639
+ common: {
640
+ name: {
641
+ en: 'HTML list of adapters with available updates',
642
+ de: 'HTML-Liste der Adapter mit verfügbaren Updates',
643
+ ru: 'HTML список адаптеров с доступными обновлениями',
644
+ pt: 'Lista HTML de adaptadores com atualizações disponíveis',
645
+ nl: 'HTML lijst van adapters met beschikbare updates',
646
+ fr: 'Liste HTML des adaptateurs avec mises à jour disponibles',
647
+ it: 'Elenco HTML degli adattatori con aggiornamenti disponibili',
648
+ es: 'Lista HTML de adaptadores con actualizaciones disponibles',
649
+ pl: 'Lista adapterów HTML z dostępnymi aktualizacjami',
650
+ uk: 'HTML список адаптерів з доступними оновленнями',
651
+ 'zh-cn': 'HTML 具有可用更新的适配器列表',
652
+ },
653
+ type: 'string',
654
+ role: 'html',
655
+ read: true,
656
+ write: false,
657
+ },
658
+ native: {},
659
+ });
660
+ }
661
+
662
+ /**
663
+ * delete html datapoints for instances
664
+ **/
665
+ async function deleteHtmlListDatapointsInstances(adaptr) {
666
+ await adaptr.delObjectAsync(`adapterAndInstances.HTML_Lists.listAllInstancesHTML`);
667
+ await adaptr.delObjectAsync(`adapterAndInstances.HTML_Lists.listAllActiveInstancesHTML`);
668
+ await adaptr.delObjectAsync(`adapterAndInstances.HTML_Lists.listDeactivatedInstancesHTML`);
669
+ await adaptr.delObjectAsync(`adapterAndInstances.HTML_Lists.listInstancesErrorHTML`);
670
+ await adaptr.delObjectAsync(`adapterAndInstances.HTML_Lists.listAdapterUpdatesHTML`);
671
+ await adaptr.delObjectAsync(`adapterAndInstances.HTML_Lists`);
672
+ }
673
+
674
+
675
+ /*=============================================
676
+ = functions to create html lists =
677
+ =============================================*/
678
+ /**
679
+ * @param {string} type - type of list
680
+ * @param {object} devices - Device
681
+ * @param {number} deviceCount - Counted devices
682
+ * @param {object} isLowBatteryList - list Low Battery Devices
683
+ */
684
+ async function createListHTML(adaptr, type, devices, deviceCount, isLowBatteryList) {
685
+ let html;
686
+ switch (type) {
687
+ case 'linkQualityList':
688
+ devices = devices.sort((a, b) => {
689
+ a = a.Device || '';
690
+ b = b.Device || '';
691
+ return a.localeCompare(b);
692
+ });
693
+ html = `<center>
694
+ <b>${[translations.Link_quality_devices[adaptr.config.userSelectedLanguage]]}:<font> ${deviceCount}</b><small></small></font>
695
+ <p></p>
696
+ </center>
697
+ <table width=100%>
698
+ <tr>
699
+ <th align=left>${[translations.Device[adaptr.config.userSelectedLanguage]]}</th>
700
+ <th align=center width=120>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
701
+ <th align=right>${[translations.Signal_strength[adaptr.config.userSelectedLanguage]]}</th>
702
+ </tr>
703
+ <tr>
704
+ <td colspan="5"><hr></td>
705
+ </tr>`;
706
+
707
+ for (const device of devices) {
708
+ html += `<tr>
709
+ <td><font>${device[translations.Device[adaptr.config.userSelectedLanguage]]}</font></td>
710
+ <td align=center><font>${device[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
711
+ <td align=right><font>${device[translations.Signal_strength[adaptr.config.userSelectedLanguage]]}</font></td>
712
+ </tr>`;
713
+ }
714
+
715
+ html += '</table>';
716
+ break;
717
+
718
+ case 'offlineList':
719
+ devices = devices.sort((a, b) => {
720
+ a = a.Device || '';
721
+ b = b.Device || '';
722
+ return a.localeCompare(b);
723
+ });
724
+ html = `<center>
725
+ <b>${[translations.offline_devices[adaptr.config.userSelectedLanguage]]}: <font color=${deviceCount === 0 ? '#3bcf0e' : 'orange'}>${deviceCount}</b><small></small></font>
726
+ <p></p>
727
+ </center>
728
+ <table width=100%>
729
+ <tr>
730
+ <th align=left>${[translations.Device[adaptr.config.userSelectedLanguage]]}</th>
731
+ <th align=center width=120>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
732
+ <th align=center>${[translations.Last_Contact[adaptr.config.userSelectedLanguage]]}</th>
733
+ </tr>
734
+ <tr>
735
+ <td colspan="5"><hr></td>
736
+ </tr>`;
737
+
738
+ for (const device of devices) {
739
+ html += `<tr>
740
+ <td><font>${device[translations.Device[adaptr.config.userSelectedLanguage]]}</font></td>
741
+ <td align=center><font>${device[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
742
+ <td align=center><font color=orange>${device[translations.Last_Contact[adaptr.config.userSelectedLanguage]]}</font></td>
743
+ </tr>`;
744
+ }
745
+
746
+ html += '</table>';
747
+ break;
748
+
749
+ case 'batteryList':
750
+ devices = devices.sort((a, b) => {
751
+ a = a.Device || '';
752
+ b = b.Device || '';
753
+ return a.localeCompare(b);
754
+ });
755
+ html = `<center>
756
+ <b>${isLowBatteryList === true ? `${[translations.low[adaptr.config.userSelectedLanguage]]} ` : ''}${[translations.battery_devices[adaptr.config.userSelectedLanguage]]}:
757
+ <font color=${isLowBatteryList === true ? (deviceCount > 0 ? 'orange' : '#3bcf0e') : ''}>${deviceCount}</b></font>
758
+ <p></p>
759
+ </center>
760
+ <table width=100%>
761
+ <tr>
762
+ <th align=left>${[translations.Device[adaptr.config.userSelectedLanguage]]}</th>
763
+ <th align=center width=120>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
764
+ <th align=${isLowBatteryList ? 'center' : 'right'}>${[translations.Battery[adaptr.config.userSelectedLanguage]]}</th>
765
+ </tr>
766
+ <tr>
767
+ <td colspan="5"><hr></td>
768
+ </tr>`;
769
+ for (const device of devices) {
770
+ html += `<tr>
771
+ <td><font>${device[translations.Device[adaptr.config.userSelectedLanguage]]}</font></td>
772
+ <td align=center><font>${device[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>`;
773
+
774
+ if (isLowBatteryList) {
775
+ html += `<td align=center><font color=orange>${device[translations.Battery[adaptr.config.userSelectedLanguage]]}</font></td>`;
776
+ } else {
777
+ html += `<td align=right><font color=#3bcf0e>${device[translations.Battery[adaptr.config.userSelectedLanguage]]}</font></td>`;
778
+ }
779
+ html += `</tr>`;
780
+ }
781
+
782
+ html += '</table>';
783
+ break;
784
+ }
785
+ return html;
786
+ }
787
+
788
+ /**
789
+ * @param {string} type - type of list
790
+ * @param {object} instances - Instance
791
+ * @param {number} instancesCount - Counted devices
792
+ */
793
+ async function createListHTMLInstances(adaptr, type, instances, instancesCount) {
794
+ let html;
795
+ switch (type) {
796
+ case 'allInstancesList':
797
+ instances = instances.sort((a, b) => {
798
+ a = a.Instance || '';
799
+ b = b.Instance || '';
800
+ return a.localeCompare(b);
801
+ });
802
+ html = `<center>
803
+ <b>${[translations.All_Instances[adaptr.config.userSelectedLanguage]]}:<font> ${instancesCount}</b><small></small></font>
804
+ <p></p>
805
+ </center>
806
+ <table width=100%>
807
+ <tr>
808
+ <th align=left>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
809
+ <th align=center>${[translations.Instance[adaptr.config.userSelectedLanguage]]}</th>
810
+ <th align=center width=180>${[translations.Status[adaptr.config.userSelectedLanguage]]}</th>
811
+ </tr>
812
+ <tr>
813
+ <td colspan="5"><hr></td>
814
+ </tr>`;
815
+
816
+ for (const instanceData of instances) {
817
+ html += `<tr>
818
+ <td><font>${instanceData[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
819
+ <td align=center><font>${instanceData[translations.Instance[adaptr.config.userSelectedLanguage]]}</font></td>
820
+ <td align=center><font>${instanceData[translations.Status[adaptr.config.userSelectedLanguage]]}</font></td>
821
+ </tr>`;
822
+ }
823
+
824
+ html += '</table>';
825
+ break;
826
+
827
+ case 'allActiveInstancesList':
828
+ instances = instances.sort((a, b) => {
829
+ a = a.Instance || '';
830
+ b = b.Instances || '';
831
+ return a.localeCompare(b);
832
+ });
833
+ html = `<center>
834
+ <b>${[translations.Active_Instances[adaptr.config.userSelectedLanguage]]}: <font> ${instancesCount}</b><small></small></font>
835
+ <p></p>
836
+ </center>
837
+ <table width=100%>
838
+ <tr>
839
+ <th align=left>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
840
+ <th align=center>${[translations.Instance[adaptr.config.userSelectedLanguage]]}</th>
841
+ <th align=center width=180>${[translations.Status[adaptr.config.userSelectedLanguage]]}</th>
842
+ </tr>
843
+ <tr>
844
+ <td colspan="5"><hr></td>
845
+ </tr>`;
846
+
847
+ for (const instanceData of instances) {
848
+ html += `<tr>
849
+ <td><font>${instanceData[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
850
+ <td align=center><font>${instanceData[translations.Instance[adaptr.config.userSelectedLanguage]]}</font></td>
851
+ <td align=center><font color=orange>${instanceData[translations.Status[adaptr.config.userSelectedLanguage]]}</font></td>
852
+ </tr>`;
853
+ }
854
+
855
+ html += '</table>';
856
+ break;
857
+
858
+ case 'errorInstanceList':
859
+ instances = instances.sort((a, b) => {
860
+ a = a.Instance || '';
861
+ b = b.Instances || '';
862
+ return a.localeCompare(b);
863
+ });
864
+ html = `<center>
865
+ <b>${[translations.Error_Instances[adaptr.config.userSelectedLanguage]]}: <font color=${instancesCount === 0 ? '#3bcf0e' : 'orange'}>${instancesCount}</b><small></small></font>
866
+ <p></p>
867
+ </center>
868
+ <table width=100%>
869
+ <tr>
870
+ <th align=left>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
871
+ <th align=center>${[translations.Instance[adaptr.config.userSelectedLanguage]]}</th>
872
+ <th align=center width=180>${[translations.Status[adaptr.config.userSelectedLanguage]]}</th>
873
+ </tr>
874
+ <tr>
875
+ <td colspan="5"><hr></td>
876
+ </tr>`;
877
+
878
+ for (const instanceData of instances) {
879
+ html += `<tr>
880
+ <td><font>${instanceData[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
881
+ <td align=center><font>${instanceData[translations.Instance[adaptr.config.userSelectedLanguage]]}</font></td>
882
+ <td align=center><font color=orange>${instanceData[translations.Status[adaptr.config.userSelectedLanguage]]}</font></td>
883
+ </tr>`;
884
+ }
885
+
886
+ html += '</table>';
887
+ break;
888
+
889
+ case 'deactivatedInstanceList':
890
+ instances = instances.sort((a, b) => {
891
+ a = a.Instance || '';
892
+ b = b.Instances || '';
893
+ return a.localeCompare(b);
894
+ });
895
+ html = `<center>
896
+ <b>${[translations.Deactivated_Instances[adaptr.config.userSelectedLanguage]]}: <font color=${instancesCount === 0 ? '#3bcf0e' : 'orange'}>${instancesCount}</b><small></small></font>
897
+ <p></p>
898
+ </center>
899
+ <table width=100%>
900
+ <tr>
901
+ <th align=left>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
902
+ <th align=center>${[translations.Instance[adaptr.config.userSelectedLanguage]]}</th>
903
+ <th align=center width=180>${[translations.Status[adaptr.config.userSelectedLanguage]]}</th>
904
+ </tr>
905
+ <tr>
906
+ <td colspan="5"><hr></td>
907
+ </tr>`;
908
+
909
+ for (const instanceData of instances) {
910
+ if (!instanceData.isAlive) {
911
+ html += `<tr>
912
+ <td><font>${instanceData[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
913
+ <td align=center><font>${instanceData[translations.Instance[adaptr.config.userSelectedLanguage]]}</font></td>
914
+ <td align=center><font color=orange>${instanceData[translations.Status[adaptr.config.userSelectedLanguage]]}</font></td>
915
+ </tr>`;
916
+ }
917
+ }
918
+
919
+ html += '</table>';
920
+ break;
921
+
922
+ case 'updateAdapterList':
923
+ html = `<center>
924
+ <b>${[translations.Updatable_adapters[adaptr.config.userSelectedLanguage]]}: <font color=${instancesCount === 0 ? '#3bcf0e' : 'orange'}>${instancesCount}</b><small></small></font>
925
+ <p></p>
926
+ </center>
927
+ <table width=100%>
928
+ <tr>
929
+ <th align=left>${[translations.Adapter[adaptr.config.userSelectedLanguage]]}</th>
930
+ <th align=center>${[translations.Installed_Version[adaptr.config.userSelectedLanguage]]}</th>
931
+ <th align=center>${[translations.Available_Version[adaptr.config.userSelectedLanguage]]}</th>
932
+ </tr>
933
+ <tr>
934
+ <td colspan="5"><hr></td>
935
+ </tr>`;
936
+
937
+ for (const instanceData of instances.values()) {
938
+ if (instanceData.updateAvailable !== ' - ') {
939
+ html += `<tr>
940
+ <td><font>${instanceData[translations.Adapter[adaptr.config.userSelectedLanguage]]}</font></td>
941
+ <td align=center><font>${instanceData[translations.Installed_Version[adaptr.config.userSelectedLanguage]]}</font></td>
942
+ <td align=center><font color=orange>${instanceData[translations.Available_Version[adaptr.config.userSelectedLanguage]]}</font></td>
943
+ </tr>`;
944
+ }
945
+ }
946
+
947
+ html += '</table>';
948
+ break;
949
+ }
950
+ return html;
951
+ }
952
+
953
+
954
+ /**
955
+ * create blacklist
956
+ */
957
+ async function createBlacklist(adaptr) {
958
+ adaptr.log.debug(`Start the function createBlacklist`);
959
+
960
+ // DEVICES
961
+ const myBlacklist = adaptr.config.tableBlacklist;
962
+ if (myBlacklist.length >= 1) {
963
+ for (const i in myBlacklist) {
964
+ try {
965
+ const blacklistParse = tools.parseData(myBlacklist[i].devices);
966
+ // push devices in list to ignor device in lists
967
+ if (myBlacklist[i].checkIgnorLists) {
968
+ adaptr.blacklistLists.push(blacklistParse.path);
969
+ }
970
+ if (myBlacklist[i].checkIgnorAdapterLists) {
971
+ adaptr.blacklistAdapterLists.push(blacklistParse.path);
972
+ }
973
+ // push devices in list to ignor device in notifications
974
+ if (myBlacklist[i].checkIgnorNotify) {
975
+ adaptr.blacklistNotify.push(blacklistParse.path);
976
+ }
977
+ } catch (error) {
978
+ adaptr.log.error(`[createBlacklist] - ${error}`);
979
+ }
980
+ if (adaptr.blacklistLists.length >= 1) adaptr.log.info(`Found devices/services on blacklist for lists: ${adaptr.blacklistLists}`);
981
+ if (adaptr.blacklistAdapterLists.length >= 1) adaptr.log.info(`Found devices/services on blacklist for own adapter lists: ${adaptr.blacklistAdapterLists}`);
982
+ if (adaptr.blacklistNotify.length >= 1) adaptr.log.info(`Found devices/services on blacklist for notifications: ${adaptr.blacklistNotify}`);
983
+ }
984
+ }
985
+
986
+ // INSTANCES
987
+ const myBlacklistInstances = adaptr.config.tableBlacklistInstances;
988
+ if (myBlacklistInstances.length >= 1) {
989
+ for (const i in myBlacklistInstances) {
990
+ try {
991
+ const blacklistParse = tools.parseData(myBlacklistInstances[i].instances);
992
+ // push devices in list to ignor device in lists
993
+ if (myBlacklistInstances[i].checkIgnorLists) {
994
+ adaptr.blacklistInstancesLists.push(blacklistParse.instanceID);
995
+ }
996
+ // push devices in list to ignor device in notifications
997
+ if (myBlacklistInstances[i].checkIgnorNotify) {
998
+ adaptr.blacklistInstancesNotify.push(blacklistParse.instanceID);
999
+ }
1000
+ } catch (error) {
1001
+ adaptr.log.error(`[createBlacklist] - ${error}`);
1002
+ }
1003
+ }
1004
+ if (adaptr.blacklistInstancesLists.length >= 1) adaptr.log.info(`Found instances items on blacklist for lists: ${adaptr.blacklistInstancesLists}`);
1005
+ if (adaptr.blacklistInstancesNotify.length >= 1) adaptr.log.info(`Found instances items on blacklist for notifications: ${adaptr.blacklistInstancesNotify}`);
1006
+ }
1007
+ }
1008
+
1009
+ /**
1010
+ * create list with time for instances
1011
+ */
1012
+ async function createTimeListInstances(adaptr) {
1013
+ // INSTANCES
1014
+ const userTimeListInstances = adaptr.config.tableTimeInstance;
1015
+ if (userTimeListInstances.length >= 1) {
1016
+ for (const i in userTimeListInstances) {
1017
+ try {
1018
+ const userTimeListparse = tools.parseData(userTimeListInstances[i].instancesTime);
1019
+ // push devices in list to ignor device in lists
1020
+ adaptr.userTimeInstancesList.set(userTimeListparse.instanceName, {
1021
+ deactivationTime: userTimeListInstances[i].deactivationTime,
1022
+ errorTime: userTimeListInstances[i].errorTime,
1023
+ });
1024
+ } catch (error) {
1025
+ adaptr.log.error(`[createTimeListInstances] - ${error}`);
1026
+ }
1027
+ }
1028
+ if (adaptr.userTimeInstancesList.size >= 1) adaptr.log.info(`Found instances items on lists for timesettings: ${Array.from(adaptr.userTimeInstancesList.keys())}`);
1029
+ }
1030
+ }
1031
+
1032
+ /**
1033
+ * @param {object} i - Device Object
1034
+ */
1035
+ async function createData(adaptr, i) {
1036
+ try {
1037
+ const devices = await adaptr.getForeignStatesAsync(adaptr.selAdapter[i].Selektor);
1038
+ const adapterID = adaptr.selAdapter[i].adapterID;
1039
+
1040
+ /*---------- Start of loop ----------*/
1041
+ for (const [id] of Object.entries(devices)) {
1042
+ if (id.endsWith('.')) continue;
1043
+ const mainSelector = id;
1044
+
1045
+ /*=============================================
1046
+ = get Instanz =
1047
+ =============================================*/
1048
+ const instance = id.slice(0, id.indexOf('.') + 2);
1049
+
1050
+ const instanceDeviceConnectionDP = `${instance}.info.connection`;
1051
+ const instancedeviceConnected = await tools.getInitValue(adaptr, instanceDeviceConnectionDP);
1052
+ adaptr.subscribeForeignStates(instanceDeviceConnectionDP);
1053
+ adaptr.subscribeForeignObjects(`${adaptr.selAdapter[i].Selektor}`);
1054
+ // adaptr.subscribeForeignObjects('*');
1055
+ //adaptr.subscribeForeignStates('*');
1056
+ /*=============================================
1057
+ = Get device name =
1058
+ =============================================*/
1059
+ const deviceName = await adaptr.getDeviceName(id, i);
1060
+
1061
+ /*=============================================
1062
+ = Get adapter name =
1063
+ =============================================*/
1064
+ const adapter = adaptr.selAdapter[i].adapter;
1065
+
1066
+ /*=============================================
1067
+ = Get path to datapoints =
1068
+ =============================================*/
1069
+ const currDeviceString = id.slice(0, id.lastIndexOf('.') + 1 - 1);
1070
+ const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
1071
+
1072
+ // subscribe to object device path
1073
+ adaptr.subscribeForeignStates(currDeviceString);
1074
+
1075
+ /*=============================================
1076
+ = Get signal strength =
1077
+ =============================================*/
1078
+ let deviceQualityDP = currDeviceString + adaptr.selAdapter[i].rssiState;
1079
+ let deviceQualityState;
1080
+
1081
+ switch (adapterID) {
1082
+ case 'mihomeVacuum':
1083
+ deviceQualityDP = shortCurrDeviceString + adaptr.selAdapter[i].rssiState;
1084
+ deviceQualityState = await adaptr.getForeignStateAsync(deviceQualityDP);
1085
+ break;
1086
+
1087
+ case 'netatmo':
1088
+ deviceQualityState = await adaptr.getForeignStateAsync(deviceQualityDP);
1089
+ if (!deviceQualityState) {
1090
+ deviceQualityDP = currDeviceString + adaptr.selAdapter[i].rfState;
1091
+ deviceQualityState = await adaptr.getForeignStateAsync(deviceQualityDP);
1092
+ }
1093
+ break;
1094
+
1095
+ default:
1096
+ deviceQualityState = await adaptr.getForeignStateAsync(deviceQualityDP);
1097
+ break;
1098
+ }
1099
+ //subscribe to states
1100
+ adaptr.subscribeForeignStates(deviceQualityDP);
1101
+
1102
+ const signalData = await adaptr.calculateSignalStrength(deviceQualityState, adapterID);
1103
+ let linkQuality = signalData[0];
1104
+ const linkQualityRaw = signalData[1];
1105
+
1106
+ /*=============================================
1107
+ = Get battery data =
1108
+ =============================================*/
1109
+ let deviceBatteryStateDP;
1110
+ let deviceBatteryState;
1111
+ let batteryHealth;
1112
+ let batteryHealthRaw;
1113
+ let batteryUnitRaw;
1114
+ let lowBatIndicator;
1115
+ let isBatteryDevice;
1116
+ let isLowBatDP;
1117
+ let faultReportingDP;
1118
+ let faultReportingState;
1119
+
1120
+ const deviceChargerStateDP = currDeviceString + adaptr.selAdapter[i].charger;
1121
+ const deviceChargerState = await tools.getInitValue(adaptr, deviceChargerStateDP);
1122
+
1123
+ if (deviceChargerState === undefined || deviceChargerState === false) {
1124
+ // Get battery states
1125
+ switch (adapterID) {
1126
+ case 'hmrpc':
1127
+ deviceBatteryStateDP = currDeviceString + adaptr.selAdapter[i].battery;
1128
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1129
+
1130
+ if (deviceBatteryState === undefined) {
1131
+ deviceBatteryStateDP = shortCurrDeviceString + adaptr.selAdapter[i].hmDNBattery;
1132
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1133
+ }
1134
+ break;
1135
+ case 'hueExt':
1136
+ case 'mihomeVacuum':
1137
+ case 'mqttNuki':
1138
+ case 'loqedSmartLock':
1139
+ deviceBatteryStateDP = shortCurrDeviceString + adaptr.selAdapter[i].battery;
1140
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1141
+
1142
+ if (deviceBatteryState === undefined) {
1143
+ deviceBatteryStateDP = shortCurrDeviceString + adaptr.selAdapter[i].battery2;
1144
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1145
+ }
1146
+ break;
1147
+ default:
1148
+ deviceBatteryStateDP = currDeviceString + adaptr.selAdapter[i].battery;
1149
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1150
+
1151
+ if (deviceBatteryState === undefined) {
1152
+ deviceBatteryStateDP = currDeviceString + adaptr.selAdapter[i].battery2;
1153
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1154
+
1155
+ if (deviceBatteryState === undefined) {
1156
+ deviceBatteryStateDP = currDeviceString + adaptr.selAdapter[i].battery3;
1157
+ deviceBatteryState = await tools.getInitValue(adaptr, deviceBatteryStateDP);
1158
+ }
1159
+ }
1160
+ break;
1161
+ }
1162
+
1163
+ // Get low bat states
1164
+ isLowBatDP = currDeviceString + adaptr.selAdapter[i].isLowBat;
1165
+ let deviceLowBatState = await tools.getInitValue(adaptr, isLowBatDP);
1166
+
1167
+ if (deviceLowBatState === undefined) {
1168
+ isLowBatDP = currDeviceString + adaptr.selAdapter[i].isLowBat2;
1169
+ deviceLowBatState = await tools.getInitValue(adaptr, isLowBatDP);
1170
+
1171
+ if (deviceLowBatState === undefined) {
1172
+ isLowBatDP = currDeviceString + adaptr.selAdapter[i].isLowBat3;
1173
+ deviceLowBatState = await tools.getInitValue(adaptr, isLowBatDP);
1174
+ }
1175
+ }
1176
+ if (deviceLowBatState === undefined) isLowBatDP = 'none';
1177
+
1178
+ faultReportingDP = shortCurrDeviceString + adaptr.selAdapter[i].faultReporting;
1179
+ faultReportingState = await tools.getInitValue(adaptr, faultReportingDP);
1180
+
1181
+ //subscribe to states
1182
+ adaptr.subscribeForeignStates(deviceBatteryStateDP);
1183
+ adaptr.subscribeForeignStates(isLowBatDP);
1184
+ adaptr.subscribeForeignStates(faultReportingDP);
1185
+
1186
+ const batteryData = await adaptr.getBatteryData(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
1187
+ batteryHealth = batteryData[0];
1188
+ batteryHealthRaw = batteryData[2];
1189
+ batteryUnitRaw = batteryData[3];
1190
+ isBatteryDevice = batteryData[1];
1191
+
1192
+ if (isBatteryDevice) {
1193
+ lowBatIndicator = await adaptr.setLowbatIndicator(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
1194
+ }
1195
+ }
1196
+
1197
+ /*=============================================
1198
+ = Get last contact of device =
1199
+ =============================================*/
1200
+ let unreachDP = currDeviceString + adaptr.selAdapter[i].reach;
1201
+ const deviceStateSelectorHMRPC = shortCurrDeviceString + adaptr.selAdapter[i].stateValue;
1202
+ const rssiPeerSelectorHMRPC = currDeviceString + adaptr.selAdapter[i].rssiPeerState;
1203
+ let timeSelector = currDeviceString + adaptr.selAdapter[i].timeSelector;
1204
+
1205
+ const timeSelectorState = await tools.getInitValue(adaptr, timeSelector);
1206
+ if (timeSelectorState === undefined) {
1207
+ timeSelector = shortCurrDeviceString + adaptr.selAdapter[i].timeSelector;
1208
+ }
1209
+
1210
+ let deviceUnreachState = await tools.getInitValue(adaptr, unreachDP);
1211
+ if (deviceUnreachState === undefined) {
1212
+ unreachDP = shortCurrDeviceString + adaptr.selAdapter[i].reach;
1213
+ deviceUnreachState = await tools.getInitValue(adaptr, shortCurrDeviceString + adaptr.selAdapter[i].reach);
1214
+ }
1215
+
1216
+ // subscribe to states
1217
+ adaptr.subscribeForeignStates(timeSelector);
1218
+ adaptr.subscribeForeignStates(unreachDP);
1219
+ adaptr.subscribeForeignStates(deviceStateSelectorHMRPC);
1220
+ adaptr.subscribeForeignStates(rssiPeerSelectorHMRPC);
1221
+
1222
+ const onlineState = await adaptr.getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorHMRPC, rssiPeerSelectorHMRPC);
1223
+ let deviceState;
1224
+ let lastContactString;
1225
+
1226
+ if (onlineState !== undefined && onlineState !== null) {
1227
+ lastContactString = onlineState[0];
1228
+ deviceState = onlineState[1];
1229
+ linkQuality = onlineState[2];
1230
+ }
1231
+
1232
+ /*=============================================
1233
+ = Get update data =
1234
+ =============================================*/
1235
+ let isUpgradable;
1236
+ let deviceUpdateDP;
1237
+
1238
+ if (adaptr.config.checkSendDeviceUpgrade) {
1239
+ deviceUpdateDP = currDeviceString + adaptr.selAdapter[i].upgrade;
1240
+ let deviceUpdateSelector = await tools.getInitValue(adaptr, deviceUpdateDP);
1241
+ if (deviceUpdateSelector === undefined) {
1242
+ deviceUpdateDP = shortCurrDeviceString + adaptr.selAdapter[i].upgrade;
1243
+ deviceUpdateSelector = await tools.getInitValue(adaptr, deviceUpdateDP);
1244
+ if (deviceUpdateSelector === undefined) {
1245
+ const shortShortCurrDeviceString = shortCurrDeviceString.slice(0, shortCurrDeviceString.lastIndexOf('.') + 1 - 1);
1246
+ deviceUpdateDP = shortShortCurrDeviceString + adaptr.selAdapter[i].upgrade;
1247
+ deviceUpdateSelector = await tools.getInitValue(adaptr, deviceUpdateDP);
1248
+ }
1249
+ }
1250
+
1251
+ if (deviceUpdateSelector !== undefined) {
1252
+ isUpgradable = await adaptr.checkDeviceUpdate(adapterID, deviceUpdateSelector);
1253
+ } else {
1254
+ isUpgradable = ' - ';
1255
+ }
1256
+
1257
+ // subscribe to states
1258
+ adaptr.subscribeForeignStates(deviceUpdateDP);
1259
+ // adaptr.subscribeForeignStates('*');
1260
+ }
1261
+
1262
+ /*=============================================
1263
+ = Fill Raw Lists =
1264
+ =============================================*/
1265
+ const setupList = () => {
1266
+ adaptr.listAllDevicesRaw.set(currDeviceString, {
1267
+ Path: id,
1268
+ mainSelector: mainSelector,
1269
+ instanceDeviceConnectionDP: instanceDeviceConnectionDP,
1270
+ instancedeviceConnected: instancedeviceConnected,
1271
+ instance: instance,
1272
+ Device: deviceName,
1273
+ adapterID: adapterID,
1274
+ Adapter: adapter,
1275
+ timeSelector: timeSelector,
1276
+ isBatteryDevice: isBatteryDevice,
1277
+ Battery: batteryHealth,
1278
+ BatteryRaw: batteryHealthRaw,
1279
+ BatteryUnitRaw: batteryUnitRaw,
1280
+ batteryDP: deviceBatteryStateDP,
1281
+ LowBat: lowBatIndicator,
1282
+ LowBatDP: isLowBatDP,
1283
+ faultReport: faultReportingState,
1284
+ faultReportDP: faultReportingDP,
1285
+ SignalStrengthDP: deviceQualityDP,
1286
+ SignalStrength: linkQuality,
1287
+ SignalStrengthRaw: linkQualityRaw,
1288
+ UnreachState: deviceUnreachState,
1289
+ UnreachDP: unreachDP,
1290
+ deviceStateSelectorHMRPC: deviceStateSelectorHMRPC,
1291
+ rssiPeerSelectorHMRPC: rssiPeerSelectorHMRPC,
1292
+ LastContact: lastContactString,
1293
+ Status: deviceState,
1294
+ UpdateDP: deviceUpdateDP,
1295
+ Upgradable: isUpgradable,
1296
+ });
1297
+ };
1298
+
1299
+ if (!adaptr.configListOnlyBattery) {
1300
+ // Add all devices
1301
+ setupList();
1302
+ } else {
1303
+ // Add only devices with battery in the rawlist
1304
+ if (!isBatteryDevice) {
1305
+ continue;
1306
+ }
1307
+
1308
+ setupList();
1309
+ }
1310
+ } // <-- end of loop
1311
+ } catch (error) {
1312
+ adaptr.log.error(`[createData - create data of devices] - ${error}`);
1313
+ }
1314
+ } // <-- end of createData
1315
+
1316
+
1317
+ /**
1318
+ * Create Lists
1319
+ * @param {string | undefined} [adptName]
1320
+ */
1321
+ async function createLists(adaptr, adptName) {
1322
+ adaptr.linkQualityDevices = [];
1323
+ adaptr.batteryPowered = [];
1324
+ adaptr.batteryLowPowered = [];
1325
+ adaptr.listAllDevicesUserRaw = [];
1326
+ adaptr.listAllDevices = [];
1327
+ adaptr.offlineDevices = [];
1328
+ adaptr.batteryLowPoweredRaw = [];
1329
+ adaptr.offlineDevicesRaw = [];
1330
+ adaptr.upgradableDevicesRaw = [];
1331
+ adaptr.upgradableList = [];
1332
+
1333
+ if (adptName === undefined) {
1334
+ adptName = '';
1335
+ }
1336
+
1337
+ for (const deviceData of adaptr.listAllDevicesRaw.values()) {
1338
+ /*---------- fill raw lists ----------*/
1339
+ // low bat list
1340
+ if (deviceData.LowBat && deviceData.Status !== 'Offline') {
1341
+ adaptr.batteryLowPoweredRaw.push({
1342
+ Path: deviceData.Path,
1343
+ Device: deviceData.Device,
1344
+ Adapter: deviceData.Adapter,
1345
+ Battery: deviceData.Battery,
1346
+ });
1347
+ }
1348
+ // offline raw list
1349
+ if (deviceData.Status === 'Offline') {
1350
+ adaptr.offlineDevicesRaw.push({
1351
+ Path: deviceData.Path,
1352
+ Device: deviceData.Device,
1353
+ Adapter: deviceData.Adapter,
1354
+ LastContact: deviceData.LastContact,
1355
+ });
1356
+ }
1357
+
1358
+ // upgradable raw list
1359
+ if (deviceData.Upgradable === true) {
1360
+ adaptr.upgradableDevicesRaw.push({
1361
+ Path: deviceData.Path,
1362
+ Device: deviceData.Device,
1363
+ Adapter: deviceData.Adapter,
1364
+ });
1365
+ }
1366
+
1367
+ if (adptName === '' && !adaptr.blacklistLists.includes(deviceData.Path)) {
1368
+ await adaptr.theLists(deviceData);
1369
+ }
1370
+
1371
+ if (adaptr.config.createOwnFolder && adptName !== '') {
1372
+ if (!deviceData.adapterID.includes(adptName)) continue;
1373
+ /*---------- fill user lists for each adapter ----------*/
1374
+ if (adaptr.blacklistAdapterLists.includes(deviceData.Path)) continue;
1375
+ await adaptr.theLists(deviceData);
1376
+ }
1377
+ }
1378
+ await tools.countDevices(adaptr);
1379
+ }
1380
+
1381
+
1382
+ /**
1383
+ * @param {string} [adptName] - Adaptername
1384
+ */
1385
+ async function writeDatapoints(adaptr, adptName) {
1386
+ // fill the datapoints
1387
+ adaptr.log.debug(`Start the function writeDatapoints`);
1388
+
1389
+ try {
1390
+ let dpSubFolder;
1391
+ //write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
1392
+ if (adptName) {
1393
+ dpSubFolder = adptName + '.';
1394
+ } else {
1395
+ dpSubFolder = '';
1396
+ }
1397
+
1398
+ // Write Datapoints for counts
1399
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}offlineCount`, { val: adaptr.offlineDevicesCount, ack: true });
1400
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}countAll`, { val: adaptr.deviceCounter, ack: true });
1401
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}batteryCount`, { val: adaptr.batteryPoweredCount, ack: true });
1402
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}lowBatteryCount`, { val: adaptr.lowBatteryPoweredCount, ack: true });
1403
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}upgradableCount`, { val: adaptr.upgradableDevicesCount, ack: true });
1404
+ // List all devices
1405
+ if (adaptr.deviceCounter === 0) {
1406
+ // if no device is count, write the JSON List with default value
1407
+ adaptr.listAllDevices = [
1408
+ {
1409
+ [translations.Device[adaptr.config.userSelectedLanguage]]: '--none--',
1410
+ [translations.Adapter[adaptr.config.userSelectedLanguage]]: '',
1411
+ [translations.Battery[adaptr.config.userSelectedLanguage]]: '',
1412
+ [translations.Signal_strength[adaptr.config.userSelectedLanguage]]: '',
1413
+ [translations.Last_Contact[adaptr.config.userSelectedLanguage]]: '',
1414
+ [translations.Status[adaptr.config.userSelectedLanguage]]: '',
1415
+ },
1416
+ ];
1417
+ adaptr.listAllDevicesUserRaw = [
1418
+ {
1419
+ Device: '--none--',
1420
+ Adapter: '',
1421
+ Instance: '',
1422
+ 'Instance connected': '',
1423
+ isBatteryDevice: '',
1424
+ Battery: '',
1425
+ BatteryRaw: '',
1426
+ isLowBat: '',
1427
+ 'Signal strength': '',
1428
+ 'Last contact': '',
1429
+ UpdateAvailable: '',
1430
+ Status: '',
1431
+ },
1432
+ ];
1433
+ }
1434
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}listAll`, { val: JSON.stringify(adaptr.listAllDevices), ack: true });
1435
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}listAllRawJSON`, { val: JSON.stringify(adaptr.listAllDevicesUserRaw), ack: true });
1436
+
1437
+ // List link quality
1438
+ if (adaptr.linkQualityCount === 0) {
1439
+ // if no device is count, write the JSON List with default value
1440
+ adaptr.linkQualityDevices = [
1441
+ {
1442
+ [translations.Device[adaptr.config.userSelectedLanguage]]: '--none--',
1443
+ [translations.Adapter[adaptr.config.userSelectedLanguage]]: '',
1444
+ [translations.Signal_strength[adaptr.config.userSelectedLanguage]]: '',
1445
+ },
1446
+ ];
1447
+ }
1448
+ //write JSON list
1449
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}linkQualityList`, {
1450
+ val: JSON.stringify(adaptr.linkQualityDevices),
1451
+ ack: true,
1452
+ });
1453
+
1454
+ // List offline devices
1455
+ if (adaptr.offlineDevicesCount === 0) {
1456
+ // if no device is count, write the JSON List with default value
1457
+ adaptr.offlineDevices = [
1458
+ {
1459
+ [translations.Device[adaptr.config.userSelectedLanguage]]: '--none--',
1460
+ [translations.Adapter[adaptr.config.userSelectedLanguage]]: '',
1461
+ [translations.Last_Contact[adaptr.config.userSelectedLanguage]]: '',
1462
+ },
1463
+ ];
1464
+ }
1465
+ //write JSON list
1466
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}offlineList`, {
1467
+ val: JSON.stringify(adaptr.offlineDevices),
1468
+ ack: true,
1469
+ });
1470
+
1471
+ // List updatable
1472
+ if (adaptr.upgradableDevicesCount === 0) {
1473
+ // if no device is count, write the JSON List with default value
1474
+ adaptr.upgradableList = [
1475
+ {
1476
+ [translations.Device[adaptr.config.userSelectedLanguage]]: '--none--',
1477
+ [translations.Adapter[adaptr.config.userSelectedLanguage]]: '',
1478
+ [translations.Last_Contact[adaptr.config.userSelectedLanguage]]: '',
1479
+ },
1480
+ ];
1481
+ }
1482
+ //write JSON list
1483
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}upgradableList`, {
1484
+ val: JSON.stringify(adaptr.upgradableList),
1485
+ ack: true,
1486
+ });
1487
+
1488
+ // List battery powered
1489
+ if (adaptr.batteryPoweredCount === 0) {
1490
+ // if no device is count, write the JSON List with default value
1491
+ adaptr.batteryPowered = [
1492
+ {
1493
+ [translations.Device[adaptr.config.userSelectedLanguage]]: '--none--',
1494
+ [translations.Adapter[adaptr.config.userSelectedLanguage]]: '',
1495
+ [translations.Battery[adaptr.config.userSelectedLanguage]]: '',
1496
+ },
1497
+ ];
1498
+ }
1499
+ //write JSON list
1500
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}batteryList`, {
1501
+ val: JSON.stringify(adaptr.batteryPowered),
1502
+ ack: true,
1503
+ });
1504
+
1505
+ // list battery low powered
1506
+ if (adaptr.lowBatteryPoweredCount === 0) {
1507
+ // if no device is count, write the JSON List with default value
1508
+ adaptr.batteryLowPowered = [
1509
+ {
1510
+ [translations.Device[adaptr.config.userSelectedLanguage]]: '--none--',
1511
+ [translations.Adapter[adaptr.config.userSelectedLanguage]]: '',
1512
+ [translations.Battery[adaptr.config.userSelectedLanguage]]: '',
1513
+ },
1514
+ ];
1515
+ }
1516
+ //write JSON list
1517
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}lowBatteryList`, {
1518
+ val: JSON.stringify(adaptr.batteryLowPowered),
1519
+ ack: true,
1520
+ });
1521
+
1522
+ // set booleans datapoints
1523
+ if (adaptr.offlineDevicesCount === 0) {
1524
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceOffline`, {
1525
+ val: false,
1526
+ ack: true,
1527
+ });
1528
+ } else {
1529
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceOffline`, {
1530
+ val: true,
1531
+ ack: true,
1532
+ });
1533
+ }
1534
+
1535
+ if (adaptr.lowBatteryPoweredCount === 0) {
1536
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceLowBat`, {
1537
+ val: false,
1538
+ ack: true,
1539
+ });
1540
+ } else {
1541
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceLowBat`, {
1542
+ val: true,
1543
+ ack: true,
1544
+ });
1545
+ }
1546
+
1547
+ if (adaptr.upgradableDevicesCount === 0) {
1548
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceUpdatable`, {
1549
+ val: false,
1550
+ ack: true,
1551
+ });
1552
+ } else {
1553
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}oneDeviceUpdatable`, {
1554
+ val: true,
1555
+ ack: true,
1556
+ });
1557
+ }
1558
+
1559
+ //write HTML list
1560
+ if (adaptr.configCreateHtmlList) {
1561
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}linkQualityListHTML`, {
1562
+ val: await this.createListHTML(adaptr, 'linkQualityList', adaptr.linkQualityDevices, adaptr.linkQualityCount, null),
1563
+ ack: true,
1564
+ });
1565
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}offlineListHTML`, {
1566
+ val: await this.createListHTML(adaptr, 'offlineList', adaptr.offlineDevices, adaptr.offlineDevicesCount, null),
1567
+ ack: true,
1568
+ });
1569
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}batteryListHTML`, {
1570
+ val: await this.createListHTML(adaptr, 'batteryList', adaptr.batteryPowered, adaptr.batteryPoweredCount, false),
1571
+ ack: true,
1572
+ });
1573
+ await adaptr.setStateChangedAsync(`devices.${dpSubFolder}lowBatteryListHTML`, {
1574
+ val: await this.createListHTML(adaptr, 'batteryList', adaptr.batteryLowPowered, adaptr.lowBatteryPoweredCount, true),
1575
+ ack: true,
1576
+ });
1577
+
1578
+ if (adaptr.config.checkAdapterInstances) {
1579
+ await adaptr.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listAllInstancesHTML`, {
1580
+ val: await this.createListHTMLInstances(adaptr, 'allInstancesList', adaptr.listAllInstances, adaptr.countAllInstances),
1581
+ ack: true,
1582
+ });
1583
+ await adaptr.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listAllActiveInstancesHTML`, {
1584
+ val: await this.createListHTMLInstances(adaptr, 'allActiveInstancesList', adaptr.listAllActiveInstances, adaptr.countAllActiveInstances),
1585
+ ack: true,
1586
+ });
1587
+ await adaptr.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listInstancesErrorHTML`, {
1588
+ val: await this.createListHTMLInstances(adaptr, 'errorInstanceList', adaptr.listErrorInstance, adaptr.countErrorInstance),
1589
+ ack: true,
1590
+ });
1591
+ await adaptr.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listDeactivatedInstancesHTML`, {
1592
+ val: await this.createListHTMLInstances(adaptr, 'deactivatedInstanceList', adaptr.listDeactivatedInstances, adaptr.countDeactivatedInstances),
1593
+ ack: true,
1594
+ });
1595
+ await adaptr.setStateChangedAsync(`adapterAndInstances.HTML_Lists.listAdapterUpdatesHTML`, {
1596
+ val: await this.createListHTMLInstances(adaptr, 'updateAdapterList', adaptr.listAdapterUpdates, adaptr.countAdapterUpdates),
1597
+ ack: true,
1598
+ });
1599
+ }
1600
+ }
1601
+
1602
+ // create timestamp of last run
1603
+ const lastCheck = adaptr.formatDate(new Date(), 'DD.MM.YYYY') + ' - ' + adaptr.formatDate(new Date(), 'hh:mm:ss');
1604
+ await adaptr.setStateChangedAsync('lastCheck', lastCheck, true);
1605
+ } catch (error) {
1606
+ adaptr.log.error(`[writeDatapoints] - ${error}`);
1607
+ }
1608
+ } //<--End of writing Datapoints
1609
+
1610
+
1611
+ /**
1612
+ * create Datapoints for Instances
1613
+ */
1614
+ async function createDPsForInstances(adaptr) {
1615
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances`, {
1616
+ type: 'channel',
1617
+ common: {
1618
+ name: {
1619
+ en: 'Adapter and Instances',
1620
+ de: 'Adapter und Instanzen',
1621
+ ru: '??????? ? Instances',
1622
+ pt: 'Adaptador e instâncias',
1623
+ nl: 'Adapter en Instance',
1624
+ fr: 'Adaptateur et instances',
1625
+ it: 'Adattatore e istanze',
1626
+ es: 'Adaptador e instalaciones',
1627
+ pl: 'Adapter and Instances',
1628
+ // @ts-ignore
1629
+ uk: '??????? ?? ?????????',
1630
+ 'zh-cn': '????',
1631
+ },
1632
+ },
1633
+ native: {},
1634
+ });
1635
+
1636
+ // Instances
1637
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.listAllInstances`, {
1638
+ type: 'state',
1639
+ common: {
1640
+ name: {
1641
+ en: 'JSON List of all instances',
1642
+ de: 'JSON Liste aller Instanzen',
1643
+ ru: '????? ?????? ???? ?????????',
1644
+ pt: 'J. Lista de todas as instâncias',
1645
+ nl: 'JSON List van alle instanties',
1646
+ fr: 'JSON Liste de tous les cas',
1647
+ it: 'JSON Elenco di tutte le istanze',
1648
+ es: 'JSON Lista de todos los casos',
1649
+ pl: 'JSON Lista wszystkich instancji',
1650
+ // @ts-ignore
1651
+ uk: '????? ?????? ???? ???????????',
1652
+ 'zh-cn': '? ? ???????',
1653
+ },
1654
+ type: 'array',
1655
+ role: 'json',
1656
+ read: true,
1657
+ write: false,
1658
+ },
1659
+ native: {},
1660
+ });
1661
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.countAllInstances`, {
1662
+ type: 'state',
1663
+ common: {
1664
+ name: {
1665
+ en: 'Number of all instances',
1666
+ de: 'Anzahl aller Instanzen',
1667
+ ru: '?????????? ???? ?????????',
1668
+ pt: 'Número de todas as instâncias',
1669
+ nl: 'Nummer van alle gevallen',
1670
+ fr: 'Nombre de cas',
1671
+ it: 'Numero di tutte le istanze',
1672
+ es: 'Número de casos',
1673
+ pl: 'Liczba wszystkich instancji',
1674
+ // @ts-ignore
1675
+ uk: '????????? ???? ???????????',
1676
+ 'zh-cn': '??????',
1677
+ },
1678
+ type: 'number',
1679
+ role: 'value',
1680
+ read: true,
1681
+ write: false,
1682
+ },
1683
+ native: {},
1684
+ });
1685
+ // Instances
1686
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.listAllActiveInstances`, {
1687
+ type: 'state',
1688
+ common: {
1689
+ name: {
1690
+ en: 'JSON List of all active instances',
1691
+ de: 'JSON Liste aller aktiven Instanzen',
1692
+ ru: '????? ?????? ???? ???????? ?????????',
1693
+ pt: 'J. Lista de todas as instâncias ativas',
1694
+ nl: 'JSON List van alle actieve instanties',
1695
+ fr: 'JSON Liste de tous les cas actifs',
1696
+ it: 'JSON Elenco di tutte le istanze attive',
1697
+ es: 'JSON Lista de todos los casos activos',
1698
+ pl: 'JSON Lista wszystkich aktywnych instancji',
1699
+ // @ts-ignore
1700
+ uk: '????? ?????? ???? ???????? ???????????',
1701
+ 'zh-cn': '? ? ????????',
1702
+ },
1703
+ type: 'array',
1704
+ role: 'json',
1705
+ read: true,
1706
+ write: false,
1707
+ },
1708
+ native: {},
1709
+ });
1710
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.countAllActiveInstances`, {
1711
+ type: 'state',
1712
+ common: {
1713
+ name: {
1714
+ en: 'Number of all active instances',
1715
+ de: 'Anzahl aller aktiven Instanzen',
1716
+ ru: '?????????? ???? ???????? ?????????',
1717
+ pt: 'Número de todas as instâncias ativas',
1718
+ nl: 'Nummer van alle actieve instanties',
1719
+ fr: 'Nombre de toutes les instances actives',
1720
+ it: 'Numero di tutte le istanze attive',
1721
+ es: 'Número de casos activos',
1722
+ pl: 'Liczba wszystkich czynnych przypadków',
1723
+ // @ts-ignore
1724
+ uk: '????????? ???? ???????? ???????????',
1725
+ 'zh-cn': '?????????',
1726
+ },
1727
+ type: 'number',
1728
+ role: 'value',
1729
+ read: true,
1730
+ write: false,
1731
+ },
1732
+ native: {},
1733
+ });
1734
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.listDeactivatedInstances`, {
1735
+ type: 'state',
1736
+ common: {
1737
+ name: {
1738
+ en: 'JSON List of deactivated instances',
1739
+ de: 'JSON Liste der deaktivierten Instanzen',
1740
+ ru: '????? ?????? ???????????????? ?????????',
1741
+ pt: 'J. Lista de instâncias desativadas',
1742
+ nl: 'JSON List van gedeactiveerde instanties',
1743
+ fr: 'JSON Liste des cas désactivés',
1744
+ it: 'JSON Elenco delle istanze disattivate',
1745
+ es: 'JSON Lista de casos desactivados',
1746
+ pl: 'JSON Lista przypadków deaktywowanych',
1747
+ // @ts-ignore
1748
+ uk: '????? ??????? ????????????? ???????????',
1749
+ 'zh-cn': '? ? ??????',
1750
+ },
1751
+ type: 'array',
1752
+ role: 'json',
1753
+ read: true,
1754
+ write: false,
1755
+ },
1756
+ native: {},
1757
+ });
1758
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.countDeactivatedInstances`, {
1759
+ type: 'state',
1760
+ common: {
1761
+ name: {
1762
+ en: 'Number of deactivated instances',
1763
+ de: 'Anzahl deaktivierter Instanzen',
1764
+ ru: '?????????? ???????????????? ?????????',
1765
+ pt: 'Número de instâncias desativadas',
1766
+ nl: 'Nummer van gedeactiveerde instanties',
1767
+ fr: 'Nombre de cas désactivés',
1768
+ it: 'Numero di istanze disattivate',
1769
+ es: 'Número de casos desactivados',
1770
+ pl: 'Liczba deaktywowanych instancji',
1771
+ // @ts-ignore
1772
+ uk: '????????? ????????????? ???????????',
1773
+ 'zh-cn': 'A. ???????',
1774
+ },
1775
+ type: 'number',
1776
+ role: 'value',
1777
+ read: true,
1778
+ write: false,
1779
+ },
1780
+ native: {},
1781
+ });
1782
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.listInstancesError`, {
1783
+ type: 'state',
1784
+ common: {
1785
+ name: {
1786
+ en: 'JSON list of instances with error',
1787
+ de: 'JSON-Liste von Instanzen mit Fehler',
1788
+ ru: 'JSON ?????? ????????? ? ???????',
1789
+ pt: 'Lista de instâncias JSON com erro',
1790
+ nl: 'JSON lijst met fouten',
1791
+ fr: 'Liste des instances avec erreur',
1792
+ it: 'Elenco JSON delle istanze con errore',
1793
+ es: 'JSON lista de casos con error',
1794
+ pl: 'Lista b??dów JSON',
1795
+ // @ts-ignore
1796
+ uk: 'JSON ?????? ??????????? ? ????????',
1797
+ 'zh-cn': '??????????????',
1798
+ },
1799
+ type: 'array',
1800
+ role: 'json',
1801
+ read: true,
1802
+ write: false,
1803
+ },
1804
+ native: {},
1805
+ });
1806
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.countInstancesError`, {
1807
+ type: 'state',
1808
+ common: {
1809
+ name: {
1810
+ en: 'Count of instances with error',
1811
+ de: 'Anzahl der Instanzen mit Fehler',
1812
+ ru: '?????????? ????????? ? ???????',
1813
+ pt: 'Contagem de instâncias com erro',
1814
+ nl: 'Graaf van instoringen met fouten',
1815
+ fr: 'Nombre de cas avec erreur',
1816
+ it: 'Conteggio di istanze con errore',
1817
+ es: 'Cuenta de casos con error',
1818
+ pl: 'Liczba przyk?adów w przypadku b??dów',
1819
+ // @ts-ignore
1820
+ uk: '????????? ??????????? ? ????????',
1821
+ 'zh-cn': '???????',
1822
+ },
1823
+ type: 'number',
1824
+ role: 'value',
1825
+ read: true,
1826
+ write: false,
1827
+ },
1828
+ native: {},
1829
+ });
1830
+
1831
+ // Adapter
1832
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.listAdapterUpdates`, {
1833
+ type: 'state',
1834
+ common: {
1835
+ name: {
1836
+ en: 'JSON list of adapters with available updates',
1837
+ de: 'JSON-Liste der Adapter mit verfügbaren Updates',
1838
+ ru: 'JSON ?????? ????????? ? ?????????? ????????????',
1839
+ pt: 'Lista de adaptadores JSON com atualizações disponíveis',
1840
+ nl: 'JSON lijst met beschikbare updates',
1841
+ fr: 'Liste JSON des adaptateurs avec mises à jour disponibles',
1842
+ it: 'Elenco di adattatori JSON con aggiornamenti disponibili',
1843
+ es: 'JSON lista de adaptadores con actualizaciones disponibles',
1844
+ pl: 'JSON lista adapterów z dost?pnymi aktualizacjami',
1845
+ // @ts-ignore
1846
+ uk: 'JSON ?????? ????????? ? ?????????? ???????????',
1847
+ 'zh-cn': '??A',
1848
+ },
1849
+ type: 'array',
1850
+ role: 'json',
1851
+ read: true,
1852
+ write: false,
1853
+ },
1854
+ native: {},
1855
+ });
1856
+ await adaptr.setObjectNotExistsAsync(`adapterAndInstances.countAdapterUpdates`, {
1857
+ type: 'state',
1858
+ common: {
1859
+ name: {
1860
+ en: 'Number of adapters with available updates',
1861
+ de: 'Anzahl der Adapter mit verfügbaren Updates',
1862
+ ru: '?????????? ????????? ? ?????????? ????????????',
1863
+ pt: 'Número de adaptadores com atualizações disponíveis',
1864
+ nl: 'Nummer van adapters met beschikbare updates',
1865
+ fr: "Nombre d'adaptateurs avec mises à jour disponibles",
1866
+ it: 'Numero di adattatori con aggiornamenti disponibili',
1867
+ es: 'Número de adaptadores con actualizaciones disponibles',
1868
+ pl: 'Liczba adapterów z dost?pn? aktualizacj?',
1869
+ // @ts-ignore
1870
+ uk: '????????? ????????? ? ?????????? ???????????',
1871
+ 'zh-cn': '????????',
1872
+ },
1873
+ type: 'number',
1874
+ role: 'value',
1875
+ read: true,
1876
+ write: false,
1877
+ },
1878
+ native: {},
1879
+ });
1880
+ }
1881
+
1882
+ /**
1883
+ * delete Datapoints for Instances
1884
+ */
1885
+ async function deleteDPsForInstances(adaptr) {
1886
+ await adaptr.delObjectAsync(`adapterAndInstances`);
1887
+ await adaptr.delObjectAsync(`adapterAndInstances.listAllInstances`);
1888
+ await adaptr.delObjectAsync(`adapterAndInstances.countAllInstances`);
1889
+ await adaptr.delObjectAsync(`adapterAndInstances.listAllActiveInstances`);
1890
+ await adaptr.delObjectAsync(`adapterAndInstances.countAllActiveInstances`);
1891
+ await adaptr.delObjectAsync(`adapterAndInstances.listDeactivatedInstances`);
1892
+ await adaptr.delObjectAsync(`adapterAndInstances.countDeactivatedInstances`);
1893
+ await adaptr.delObjectAsync(`adapterAndInstances.listInstancesError`);
1894
+ await adaptr.delObjectAsync(`adapterAndInstances.countInstancesError`);
1895
+ await adaptr.delObjectAsync(`adapterAndInstances.listAdapterUpdates`);
1896
+ await adaptr.delObjectAsync(`adapterAndInstances.countAdapterUpdates`);
1897
+ }
1898
+
1899
+ /**
1900
+ * create adapter update data
1901
+ */
1902
+ async function createAdapterUpdateData(adaptr, adapterUpdateListDP) {
1903
+
1904
+ // subscribe to datapoint
1905
+ adaptr.subscribeForeignStates(adapterUpdateListDP);
1906
+
1907
+ await adaptr.getAdapterUpdateData(adapterUpdateListDP);
1908
+
1909
+ await adaptr.createAdapterUpdateList();
1910
+ }
1911
+
1912
+
1913
+ module.exports = {
1914
+ createDPsForEachAdapter,
1915
+ deleteDPsForEachAdapter,
1916
+ createHtmlListDatapoints,
1917
+ deleteHtmlListDatapoints,
1918
+ createHtmlListDatapointsInstances,
1919
+ deleteHtmlListDatapointsInstances,
1920
+ createListHTML,
1921
+ createListHTMLInstances,
1922
+ createBlacklist,
1923
+ createTimeListInstances,
1924
+ createData,
1925
+ createLists,
1926
+ writeDatapoints,
1927
+ createDPsForInstances,
1928
+ deleteDPsForInstances,
1929
+ createAdapterUpdateData,
1930
+
1931
+ };
1932
+