iobroker.device-watcher 2.3.1 → 2.4.0
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/README.md +31 -21
- package/admin/jsonConfig.json +38 -0
- package/io-package.json +18 -14
- package/lib/arrApart.js +39 -3
- package/main.js +656 -610
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -10,7 +10,7 @@ const schedule = require('node-schedule');
|
|
|
10
10
|
const arrApart = require('./lib/arrApart.js'); // list of supported adapters
|
|
11
11
|
|
|
12
12
|
// Sentry error reporting, disable when testing code!
|
|
13
|
-
const enableSendSentry =
|
|
13
|
+
const enableSendSentry = true;
|
|
14
14
|
|
|
15
15
|
// indicator if the adapter is running or not (for intervall/shedule)
|
|
16
16
|
let isUnloaded = false;
|
|
@@ -32,7 +32,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
32
32
|
this.blacklistLists = [];
|
|
33
33
|
this.blacklistAdapterLists = [];
|
|
34
34
|
this.blacklistNotify = [];
|
|
35
|
-
this.
|
|
35
|
+
this.selAdapter = [];
|
|
36
36
|
this.adapterSelected = [];
|
|
37
37
|
this.upgradableList = [];
|
|
38
38
|
|
|
@@ -40,6 +40,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
40
40
|
this.listAllDevicesRaw = [];
|
|
41
41
|
this.batteryLowPoweredRaw = [];
|
|
42
42
|
this.offlineDevicesRaw = [];
|
|
43
|
+
this.upgradableDevicesRaw = [];
|
|
43
44
|
|
|
44
45
|
// counts
|
|
45
46
|
this.offlineDevicesCount = 0;
|
|
@@ -65,14 +66,12 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
65
66
|
async onReady() {
|
|
66
67
|
this.log.debug(`Adapter ${adapterName} was started`);
|
|
67
68
|
|
|
68
|
-
isUnloaded = false;
|
|
69
|
-
|
|
70
69
|
try {
|
|
71
70
|
this.listOnlyBattery = this.config.listOnlyBattery;
|
|
72
71
|
this.createOwnFolder = this.config.createOwnFolder;
|
|
73
72
|
this.createHtmlList = this.config.createHtmlList;
|
|
74
73
|
|
|
75
|
-
this.
|
|
74
|
+
this.configSetAdapter = {
|
|
76
75
|
alexa2: this.config.alexa2Devices,
|
|
77
76
|
apcups: this.config.apcupsDevices,
|
|
78
77
|
ble: this.config.bleDevices,
|
|
@@ -86,6 +85,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
86
85
|
harmony: this.config.harmonyDevices,
|
|
87
86
|
hmiP: this.config.hmiPDevices,
|
|
88
87
|
hmrpc: this.config.hmrpcDevices,
|
|
88
|
+
homeconnect: this.config.homeconnectDevices,
|
|
89
89
|
hs100: this.config.hs100Devices,
|
|
90
90
|
hue: this.config.hueDevices,
|
|
91
91
|
hueExt: this.config.hueExtDevices,
|
|
@@ -106,6 +106,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
106
106
|
ping: this.config.pingDevices,
|
|
107
107
|
roomba: this.config.roombaDevices,
|
|
108
108
|
shelly: this.config.shellyDevices,
|
|
109
|
+
smartgarden: this.config.smartgardenDevices,
|
|
109
110
|
sonoff: this.config.sonoffDevices,
|
|
110
111
|
sonos: this.config.sonosDevices,
|
|
111
112
|
sureflap: this.config.sureflapDevices,
|
|
@@ -121,7 +122,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
121
122
|
zwave: this.config.zwaveDevices,
|
|
122
123
|
};
|
|
123
124
|
|
|
124
|
-
this.
|
|
125
|
+
this.configMaxMinutes = {
|
|
125
126
|
alexa2: this.config.alexa2MaxMinutes,
|
|
126
127
|
apcups: this.config.apcupsMaxMinutes,
|
|
127
128
|
ble: this.config.bleMaxMinutes,
|
|
@@ -135,6 +136,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
135
136
|
harmony: this.config.harmonyMaxMinutes,
|
|
136
137
|
hmiP: this.config.hmiPMaxMinutes,
|
|
137
138
|
hmrpc: this.config.hmrpcMaxMinutes,
|
|
139
|
+
homeconnect: this.config.homeconnectMaxMinutes,
|
|
138
140
|
hs100: this.config.hs100MaxMinutes,
|
|
139
141
|
hue: this.config.hueMaxMinutes,
|
|
140
142
|
hueExt: this.config.hueextMaxMinutes,
|
|
@@ -155,6 +157,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
155
157
|
ping: this.config.pingMaxMinutes,
|
|
156
158
|
roomba: this.config.roombaMaxMinutes,
|
|
157
159
|
shelly: this.config.shellyMaxMinutes,
|
|
160
|
+
smartgarden: this.config.smartgardenMaxMinutes,
|
|
158
161
|
sonoff: this.config.sonoffMaxMinutes,
|
|
159
162
|
sonos: this.config.sonosMaxMinutes,
|
|
160
163
|
sureflap: this.config.sureflapMaxMinutes,
|
|
@@ -171,20 +174,16 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
171
174
|
};
|
|
172
175
|
|
|
173
176
|
for (const [id] of Object.entries(arrApart)) {
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.adapterSelected.push(await this.capitalize(id));
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
return; // cancel run if unloaded was called.
|
|
177
|
+
if (this.configSetAdapter[id]) {
|
|
178
|
+
this.selAdapter.push(arrApart[id]);
|
|
179
|
+
this.adapterSelected.push(await this.capitalize(id));
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
//Check if an Adapter is selected.
|
|
185
184
|
if (this.adapterSelected.length >= 1) {
|
|
186
185
|
// show list in debug log
|
|
187
|
-
this.log.debug(JSON.stringify(this.
|
|
186
|
+
this.log.debug(JSON.stringify(this.selAdapter));
|
|
188
187
|
|
|
189
188
|
this.log.info(`Number of selected adapters: ${this.adapterSelected.length}. Loading data from: ${this.adapterSelected.join(', ')} ...`);
|
|
190
189
|
} else {
|
|
@@ -203,7 +202,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
203
202
|
if (this.createOwnFolder) {
|
|
204
203
|
try {
|
|
205
204
|
for (const [id] of Object.entries(arrApart)) {
|
|
206
|
-
if (this.
|
|
205
|
+
if (this.configSetAdapter !== undefined && this.configSetAdapter[id]) {
|
|
207
206
|
await this.createDPsForEachAdapter(id);
|
|
208
207
|
if (this.createHtmlList) await this.createHtmlListDatapoints(id);
|
|
209
208
|
this.log.debug(`Created datapoints for ${this.capitalize(id)}`);
|
|
@@ -214,7 +213,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
|
|
217
|
-
// create HTML list
|
|
216
|
+
// create HTML list datapoints
|
|
218
217
|
if (this.createHtmlList) await this.createHtmlListDatapoints();
|
|
219
218
|
|
|
220
219
|
//read data first at start
|
|
@@ -255,94 +254,110 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
255
254
|
for (const device of this.listAllDevicesRaw) {
|
|
256
255
|
// On statechange update available datapoint
|
|
257
256
|
switch (id) {
|
|
257
|
+
case device.instanceAliveDP:
|
|
258
|
+
device.instanceAlive = state.val;
|
|
259
|
+
break;
|
|
260
|
+
|
|
258
261
|
case device.UpdateDP:
|
|
259
|
-
if (
|
|
262
|
+
if (device.instanceAlive) {
|
|
260
263
|
device.Upgradable = state.val;
|
|
261
|
-
if (
|
|
262
|
-
|
|
264
|
+
if (state.val) {
|
|
265
|
+
if (!this.blacklistNotify.includes(device.Path)) {
|
|
266
|
+
await this.sendDeviceUpdatesNotification(device.Device, device.Adapter);
|
|
267
|
+
}
|
|
263
268
|
}
|
|
264
269
|
}
|
|
265
270
|
break;
|
|
266
271
|
|
|
267
272
|
case device.SignalStrengthDP:
|
|
268
|
-
|
|
273
|
+
if (device.instanceAlive) {
|
|
274
|
+
device.SignalStrength = await this.calculateSignalStrength(state, device.adapterID);
|
|
275
|
+
}
|
|
269
276
|
break;
|
|
270
277
|
|
|
271
278
|
case device.batteryDP:
|
|
272
|
-
if (device.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
if (device.instanceAlive) {
|
|
280
|
+
if (device.isBatteryDevice) {
|
|
281
|
+
oldLowBatState = device.LowBat;
|
|
282
|
+
batteryData = await this.getBatteryData(state.val, oldLowBatState, device.adapterID);
|
|
283
|
+
|
|
284
|
+
device.Battery = batteryData[0];
|
|
285
|
+
device.BatteryRaw = batteryData[2];
|
|
286
|
+
if (device.LowBatDP !== 'none') {
|
|
287
|
+
isLowBatValue = await this.getInitValue(device.LowBatDP);
|
|
288
|
+
} else {
|
|
289
|
+
isLowBatValue = undefined;
|
|
290
|
+
}
|
|
291
|
+
device.LowBat = await this.setLowbatIndicator(state.val, isLowBatValue, device.faultReport, device.adapterID);
|
|
284
292
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
293
|
+
if (device.LowBat && oldLowBatState !== device.LowBat) {
|
|
294
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(device.Path)) {
|
|
295
|
+
await this.sendLowBatNoticiation(device.Device, device.Adapter, device.Battery);
|
|
296
|
+
}
|
|
288
297
|
}
|
|
289
298
|
}
|
|
290
299
|
}
|
|
291
300
|
break;
|
|
292
301
|
|
|
293
302
|
case device.LowBatDP:
|
|
294
|
-
if (device.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
303
|
+
if (device.instanceAlive) {
|
|
304
|
+
if (device.isBatteryDevice) {
|
|
305
|
+
oldLowBatState = device.LowBat;
|
|
306
|
+
batteryData = await this.getBatteryData(device.BatteryRaw, state.val, device.adapterID);
|
|
307
|
+
device.Battery = batteryData[0];
|
|
308
|
+
device.BatteryRaw = batteryData[2];
|
|
309
|
+
device.LowBat = await this.setLowbatIndicator(device.BatteryRaw, state.val, device.faultReport, device.adapterID);
|
|
310
|
+
|
|
311
|
+
if (device.LowBat && oldLowBatState !== device.LowBat) {
|
|
312
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(device.Path)) {
|
|
313
|
+
await this.sendLowBatNoticiation(device.Device, device.Adapter, device.Battery);
|
|
314
|
+
}
|
|
304
315
|
}
|
|
305
316
|
}
|
|
306
317
|
}
|
|
307
318
|
break;
|
|
308
319
|
|
|
309
320
|
case device.faultReportDP:
|
|
310
|
-
if (device.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
+
if (device.instanceAlive) {
|
|
322
|
+
if (device.isBatteryDevice) {
|
|
323
|
+
oldLowBatState = device.LowBat;
|
|
324
|
+
batteryData = await this.getBatteryData(device.BatteryRaw, oldLowBatState, device.adapterID);
|
|
325
|
+
|
|
326
|
+
device.Battery = batteryData[0];
|
|
327
|
+
device.BatteryRaw = batteryData[2];
|
|
328
|
+
device.LowBat = await this.setLowbatIndicator(device.BatteryRaw, undefined, state.val, device.adapterID);
|
|
329
|
+
|
|
330
|
+
if (device.LowBat && oldLowBatState !== device.LowBat) {
|
|
331
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(device.Path)) {
|
|
332
|
+
await this.sendLowBatNoticiation(device.Device, device.Adapter, device.Battery);
|
|
333
|
+
}
|
|
321
334
|
}
|
|
322
335
|
}
|
|
323
336
|
}
|
|
324
337
|
break;
|
|
325
338
|
|
|
326
339
|
case device.UnreachDP:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
340
|
+
if (device.instanceAlive) {
|
|
341
|
+
oldStatus = device.Status;
|
|
342
|
+
device.UnreachState = await this.getInitValue(device.UnreachDP);
|
|
343
|
+
contactData = await this.getOnlineState(
|
|
344
|
+
device.timeSelector,
|
|
345
|
+
device.adapterID,
|
|
346
|
+
device.UnreachDP,
|
|
347
|
+
device.SignalStrength,
|
|
348
|
+
device.UnreachState,
|
|
349
|
+
device.DeviceStateSelectorDP,
|
|
350
|
+
device.rssiPeerSelectorDP,
|
|
351
|
+
);
|
|
352
|
+
if (contactData !== undefined) {
|
|
353
|
+
device.LastContact = contactData[0];
|
|
354
|
+
device.Status = contactData[1];
|
|
355
|
+
device.SignalStrength = contactData[2];
|
|
356
|
+
}
|
|
343
357
|
|
|
344
|
-
|
|
345
|
-
|
|
358
|
+
if (this.config.checkSendOfflineMsg && oldStatus !== device.Status && !this.blacklistNotify.includes(device.Path)) {
|
|
359
|
+
await this.sendOfflineNotifications(device.Device, device.Adapter, device.Status, device.LastContact);
|
|
360
|
+
}
|
|
346
361
|
}
|
|
347
362
|
break;
|
|
348
363
|
}
|
|
@@ -390,6 +405,37 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
390
405
|
}
|
|
391
406
|
}
|
|
392
407
|
|
|
408
|
+
/**
|
|
409
|
+
* main function
|
|
410
|
+
*/
|
|
411
|
+
async main() {
|
|
412
|
+
this.log.debug(`Function started: ${this.main.name}`);
|
|
413
|
+
|
|
414
|
+
// fill counts and lists of all selected adapter
|
|
415
|
+
try {
|
|
416
|
+
await this.createDataOfAllAdapter();
|
|
417
|
+
this.log.debug(`Created and filled data for all adapters`);
|
|
418
|
+
} catch (error) {
|
|
419
|
+
this.errorReporting('[main - create data of all adapter]', error);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// fill datapoints for each adapter if selected
|
|
423
|
+
if (this.createOwnFolder) {
|
|
424
|
+
try {
|
|
425
|
+
for (const [id] of Object.entries(arrApart)) {
|
|
426
|
+
if (this.configSetAdapter !== undefined && this.configSetAdapter[id]) {
|
|
427
|
+
await this.createDataForEachAdapter(id);
|
|
428
|
+
this.log.debug(`Created and filled data for ${this.capitalize(id)}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
} catch (error) {
|
|
432
|
+
this.errorReporting('[main - create and fill datapoints for each adapter]', error);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
this.log.debug(`Function finished: ${this.main.name}`);
|
|
437
|
+
} //<--End of main function
|
|
438
|
+
|
|
393
439
|
/**
|
|
394
440
|
* refresh data with interval
|
|
395
441
|
* is neccessary to refresh lastContact data, especially of devices without state changes
|
|
@@ -403,7 +449,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
403
449
|
|
|
404
450
|
if (this.createOwnFolder) {
|
|
405
451
|
for (const [id] of Object.entries(arrApart)) {
|
|
406
|
-
if (this.
|
|
452
|
+
if (this.configSetAdapter !== undefined && this.configSetAdapter[id]) {
|
|
407
453
|
await this.createLists(id);
|
|
408
454
|
await this.writeDatapoints(id);
|
|
409
455
|
this.log.debug(`Created and filled data for ${this.capitalize(id)}`);
|
|
@@ -429,117 +475,284 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
429
475
|
} // <-- refreshData end
|
|
430
476
|
|
|
431
477
|
/**
|
|
432
|
-
*
|
|
478
|
+
* create blacklist
|
|
433
479
|
*/
|
|
434
|
-
async
|
|
435
|
-
this.log.debug(`Function started: ${this.
|
|
480
|
+
async createBlacklist() {
|
|
481
|
+
this.log.debug(`Function started: ${this.createBlacklist.name}`);
|
|
436
482
|
|
|
437
|
-
|
|
438
|
-
try {
|
|
439
|
-
await this.createDataOfAllAdapter();
|
|
440
|
-
this.log.debug(`Created and filled data for all adapters`);
|
|
441
|
-
} catch (error) {
|
|
442
|
-
this.errorReporting('[main - create data of all adapter]', error);
|
|
443
|
-
}
|
|
483
|
+
const myBlacklist = this.config.tableBlacklist;
|
|
444
484
|
|
|
445
|
-
|
|
446
|
-
if (this.createOwnFolder) {
|
|
485
|
+
for (const i in myBlacklist) {
|
|
447
486
|
try {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
487
|
+
const blacklistParse = await this.parseData(myBlacklist[i].devices);
|
|
488
|
+
// push devices in list to ignor device in lists
|
|
489
|
+
if (myBlacklist[i].checkIgnorLists) {
|
|
490
|
+
this.blacklistLists.push(blacklistParse.path);
|
|
491
|
+
}
|
|
492
|
+
if (myBlacklist[i].checkIgnorAdapterLists) {
|
|
493
|
+
this.blacklistAdapterLists.push(blacklistParse.path);
|
|
494
|
+
}
|
|
495
|
+
// push devices in list to ignor device in notifications
|
|
496
|
+
if (myBlacklist[i].checkIgnorNotify) {
|
|
497
|
+
this.blacklistNotify.push(blacklistParse.path);
|
|
453
498
|
}
|
|
454
499
|
} catch (error) {
|
|
455
|
-
this.errorReporting('[
|
|
500
|
+
this.errorReporting('[createBlacklist]', error);
|
|
456
501
|
}
|
|
457
502
|
}
|
|
458
503
|
|
|
459
|
-
this.log.
|
|
460
|
-
|
|
504
|
+
if (this.blacklistLists.length >= 1) this.log.info(`Found items on blacklist for lists: ${this.blacklistLists}`);
|
|
505
|
+
if (this.blacklistAdapterLists.length >= 1) this.log.info(`Found items on blacklist for lists: ${this.blacklistAdapterLists}`);
|
|
506
|
+
if (this.blacklistNotify.length >= 1) this.log.info(`Found items on blacklist for notificatioons: ${this.blacklistNotify}`);
|
|
461
507
|
|
|
462
|
-
|
|
463
|
-
* @param {string} id - id which should be capitalize
|
|
464
|
-
*/
|
|
465
|
-
capitalize(id) {
|
|
466
|
-
//make the first letter uppercase
|
|
467
|
-
return id && id[0].toUpperCase() + id.slice(1);
|
|
508
|
+
this.log.debug(`Function finished: ${this.createBlacklist.name}`);
|
|
468
509
|
}
|
|
469
510
|
|
|
470
511
|
/**
|
|
471
|
-
* @param {
|
|
512
|
+
* @param {object} i - Device Object
|
|
472
513
|
*/
|
|
473
|
-
async
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
}
|
|
514
|
+
async createData(i) {
|
|
515
|
+
const devices = await this.getForeignStatesAsync(this.selAdapter[i].Selektor);
|
|
516
|
+
const adapterID = this.selAdapter[i].adapterID;
|
|
477
517
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
518
|
+
/*---------- Start of loop ----------*/
|
|
519
|
+
for (const [id] of Object.entries(devices)) {
|
|
520
|
+
/*=============================================
|
|
521
|
+
= get Instanz =
|
|
522
|
+
=============================================*/
|
|
523
|
+
const instance = id.slice(0, id.indexOf('.') + 2);
|
|
524
|
+
const instanceAliveDP = `system.adapter.${instance}.alive`;
|
|
525
|
+
const instanceAlive = await this.getInitValue(instanceAliveDP);
|
|
526
|
+
this.subscribeForeignStates(instanceAliveDP);
|
|
486
527
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
//state can be null or undefinded for own states
|
|
492
|
-
const stateVal = await this.getStateAsync(obj);
|
|
493
|
-
if (stateVal) return stateVal.val;
|
|
494
|
-
}
|
|
528
|
+
/*=============================================
|
|
529
|
+
= Get device name =
|
|
530
|
+
=============================================*/
|
|
531
|
+
const deviceName = await this.getDeviceName(id, i);
|
|
495
532
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (!data) return {};
|
|
501
|
-
if (typeof data === 'object') return data;
|
|
502
|
-
if (typeof data === 'string') return JSON.parse(data);
|
|
503
|
-
return {};
|
|
504
|
-
}
|
|
533
|
+
/*=============================================
|
|
534
|
+
= Get adapter name =
|
|
535
|
+
=============================================*/
|
|
536
|
+
const adapter = this.selAdapter[i].adapter;
|
|
505
537
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
538
|
+
/*=============================================
|
|
539
|
+
= Get path to datapoints =
|
|
540
|
+
=============================================*/
|
|
541
|
+
const currDeviceString = id.slice(0, id.lastIndexOf('.') + 1 - 1);
|
|
542
|
+
const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
|
|
511
543
|
|
|
512
|
-
|
|
513
|
-
|
|
544
|
+
/*=============================================
|
|
545
|
+
= Get signal strength =
|
|
546
|
+
=============================================*/
|
|
547
|
+
let deviceQualityDP = currDeviceString + this.selAdapter[i].rssiState;
|
|
548
|
+
let deviceQualityState;
|
|
514
549
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (myBlacklist[i].checkIgnorNotify) {
|
|
527
|
-
this.blacklistNotify.push(blacklistParse.path);
|
|
550
|
+
switch (adapterID) {
|
|
551
|
+
case 'mihomeVacuum':
|
|
552
|
+
deviceQualityDP = shortCurrDeviceString + this.selAdapter[i].rssiState;
|
|
553
|
+
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
554
|
+
break;
|
|
555
|
+
|
|
556
|
+
case 'netatmo':
|
|
557
|
+
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
558
|
+
if (!deviceQualityState) {
|
|
559
|
+
deviceQualityDP = currDeviceString + this.selAdapter[i].rfState;
|
|
560
|
+
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
528
561
|
}
|
|
529
|
-
|
|
530
|
-
|
|
562
|
+
break;
|
|
563
|
+
|
|
564
|
+
default:
|
|
565
|
+
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
//subscribe to states
|
|
569
|
+
this.subscribeForeignStates(deviceQualityDP);
|
|
570
|
+
|
|
571
|
+
let linkQuality = await this.calculateSignalStrength(deviceQualityState, adapterID);
|
|
572
|
+
|
|
573
|
+
/*=============================================
|
|
574
|
+
= Get battery data =
|
|
575
|
+
=============================================*/
|
|
576
|
+
let deviceBatteryStateDP;
|
|
577
|
+
let deviceBatteryState;
|
|
578
|
+
let batteryHealth;
|
|
579
|
+
let batteryHealthRaw;
|
|
580
|
+
let lowBatIndicator;
|
|
581
|
+
let isBatteryDevice;
|
|
582
|
+
let isLowBatDP;
|
|
583
|
+
let faultReportingDP;
|
|
584
|
+
let faultReportingState;
|
|
585
|
+
|
|
586
|
+
const deviceChargerStateDP = currDeviceString + this.selAdapter[i].charger;
|
|
587
|
+
const deviceChargerState = await this.getInitValue(deviceChargerStateDP);
|
|
588
|
+
|
|
589
|
+
if (deviceChargerState === undefined || deviceChargerState === false) {
|
|
590
|
+
// Get battery states
|
|
591
|
+
switch (adapterID) {
|
|
592
|
+
case 'hueExt':
|
|
593
|
+
case 'mihomeVacuum':
|
|
594
|
+
case 'mqttNuki':
|
|
595
|
+
deviceBatteryStateDP = shortCurrDeviceString + this.selAdapter[i].battery;
|
|
596
|
+
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
597
|
+
if (deviceBatteryState === undefined) {
|
|
598
|
+
deviceBatteryStateDP = shortCurrDeviceString + this.selAdapter[i].battery2;
|
|
599
|
+
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
600
|
+
}
|
|
601
|
+
break;
|
|
602
|
+
default:
|
|
603
|
+
deviceBatteryStateDP = currDeviceString + this.selAdapter[i].battery;
|
|
604
|
+
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
605
|
+
if (deviceBatteryState === undefined) {
|
|
606
|
+
deviceBatteryStateDP = currDeviceString + this.selAdapter[i].battery2;
|
|
607
|
+
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
608
|
+
}
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Get low bat states
|
|
613
|
+
isLowBatDP = currDeviceString + this.selAdapter[i].isLowBat;
|
|
614
|
+
let deviceLowBatState = await this.getInitValue(isLowBatDP);
|
|
615
|
+
if (deviceLowBatState === undefined) {
|
|
616
|
+
isLowBatDP = currDeviceString + this.selAdapter[i].isLowBat2;
|
|
617
|
+
deviceLowBatState = await this.getInitValue(isLowBatDP);
|
|
618
|
+
}
|
|
619
|
+
if (deviceLowBatState === undefined) isLowBatDP = 'none';
|
|
620
|
+
|
|
621
|
+
faultReportingDP = shortCurrDeviceString + this.selAdapter[i].faultReporting;
|
|
622
|
+
faultReportingState = await this.getInitValue(faultReportingDP);
|
|
623
|
+
|
|
624
|
+
//subscribe to states
|
|
625
|
+
this.subscribeForeignStates(deviceBatteryStateDP);
|
|
626
|
+
this.subscribeForeignStates(isLowBatDP);
|
|
627
|
+
this.subscribeForeignStates(faultReportingDP);
|
|
628
|
+
|
|
629
|
+
const batteryData = await this.getBatteryData(deviceBatteryState, deviceLowBatState, adapterID);
|
|
630
|
+
batteryHealth = batteryData[0];
|
|
631
|
+
batteryHealthRaw = batteryData[2];
|
|
632
|
+
isBatteryDevice = batteryData[1];
|
|
633
|
+
|
|
634
|
+
if (isBatteryDevice) {
|
|
635
|
+
lowBatIndicator = await this.setLowbatIndicator(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
|
|
531
636
|
}
|
|
532
637
|
}
|
|
533
638
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
639
|
+
/*=============================================
|
|
640
|
+
= Get last contact of device =
|
|
641
|
+
=============================================*/
|
|
642
|
+
let unreachDP = currDeviceString + this.selAdapter[i].reach;
|
|
643
|
+
const deviceStateSelectorDP = shortCurrDeviceString + this.selAdapter[i].stateValue;
|
|
644
|
+
const rssiPeerSelectorDP = currDeviceString + this.selAdapter[i].rssiPeerState;
|
|
645
|
+
const timeSelector = currDeviceString + this.selAdapter[i].timeSelector;
|
|
646
|
+
|
|
647
|
+
let deviceUnreachState = await this.getInitValue(unreachDP);
|
|
648
|
+
if (deviceUnreachState === undefined) {
|
|
649
|
+
unreachDP = shortCurrDeviceString + this.selAdapter[i].reach;
|
|
650
|
+
deviceUnreachState = await this.getInitValue(shortCurrDeviceString + this.selAdapter[i].reach);
|
|
651
|
+
}
|
|
540
652
|
|
|
541
|
-
|
|
542
|
-
|
|
653
|
+
// subscribe to states
|
|
654
|
+
this.subscribeForeignStates(timeSelector);
|
|
655
|
+
this.subscribeForeignStates(unreachDP);
|
|
656
|
+
this.subscribeForeignStates(deviceStateSelectorDP);
|
|
657
|
+
this.subscribeForeignStates(rssiPeerSelectorDP);
|
|
658
|
+
|
|
659
|
+
const onlineState = await this.getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorDP, rssiPeerSelectorDP);
|
|
660
|
+
let deviceState;
|
|
661
|
+
let lastContactString;
|
|
662
|
+
|
|
663
|
+
if (onlineState) {
|
|
664
|
+
lastContactString = onlineState[0];
|
|
665
|
+
deviceState = onlineState[1];
|
|
666
|
+
linkQuality = onlineState[2];
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/*=============================================
|
|
670
|
+
= Get update data =
|
|
671
|
+
=============================================*/
|
|
672
|
+
const deviceUpdateDP = currDeviceString + this.selAdapter[i].upgrade;
|
|
673
|
+
let isUpgradable;
|
|
674
|
+
|
|
675
|
+
if (this.config.checkSendDeviceUpgrade) {
|
|
676
|
+
const deviceUpdateSelector = await this.getInitValue(deviceUpdateDP);
|
|
677
|
+
|
|
678
|
+
if (deviceUpdateSelector) {
|
|
679
|
+
isUpgradable = true;
|
|
680
|
+
} else if (!deviceUpdateSelector) {
|
|
681
|
+
isUpgradable = false;
|
|
682
|
+
}
|
|
683
|
+
// subscribe to states
|
|
684
|
+
this.subscribeForeignStates(deviceUpdateDP);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/*=============================================
|
|
688
|
+
= Fill Raw Lists =
|
|
689
|
+
=============================================*/
|
|
690
|
+
|
|
691
|
+
/* Add only devices with battery in the rawlist */
|
|
692
|
+
if (this.listOnlyBattery && isBatteryDevice) {
|
|
693
|
+
this.listAllDevicesRaw.push({
|
|
694
|
+
Path: id,
|
|
695
|
+
instanceAliveDP: instanceAliveDP,
|
|
696
|
+
instanceAlive: instanceAlive,
|
|
697
|
+
Device: deviceName,
|
|
698
|
+
adapterID: adapterID,
|
|
699
|
+
Adapter: adapter,
|
|
700
|
+
timeSelector: timeSelector,
|
|
701
|
+
isBatteryDevice: isBatteryDevice,
|
|
702
|
+
Battery: batteryHealth,
|
|
703
|
+
BatteryRaw: batteryHealthRaw,
|
|
704
|
+
batteryDP: deviceBatteryStateDP,
|
|
705
|
+
LowBat: lowBatIndicator,
|
|
706
|
+
LowBatDP: isLowBatDP,
|
|
707
|
+
faultReport: faultReportingState,
|
|
708
|
+
faultReportDP: faultReportingDP,
|
|
709
|
+
SignalStrengthDP: deviceQualityDP,
|
|
710
|
+
SignalStrength: linkQuality,
|
|
711
|
+
UnreachState: deviceUnreachState,
|
|
712
|
+
UnreachDP: unreachDP,
|
|
713
|
+
DeviceStateSelectorDP: deviceStateSelectorDP,
|
|
714
|
+
rssiPeerSelectorDP: rssiPeerSelectorDP,
|
|
715
|
+
LastContact: lastContactString,
|
|
716
|
+
Status: deviceState,
|
|
717
|
+
UpdateDP: deviceUpdateDP,
|
|
718
|
+
Upgradable: isUpgradable,
|
|
719
|
+
});
|
|
720
|
+
} else {
|
|
721
|
+
/* Add all devices */
|
|
722
|
+
this.listAllDevicesRaw.push({
|
|
723
|
+
Path: id,
|
|
724
|
+
instanceAliveDP: instanceAliveDP,
|
|
725
|
+
instanceAlive: instanceAlive,
|
|
726
|
+
Device: deviceName,
|
|
727
|
+
adapterID: adapterID,
|
|
728
|
+
Adapter: adapter,
|
|
729
|
+
timeSelector: timeSelector,
|
|
730
|
+
isBatteryDevice: isBatteryDevice,
|
|
731
|
+
Battery: batteryHealth,
|
|
732
|
+
BatteryRaw: batteryHealthRaw,
|
|
733
|
+
batteryDP: deviceBatteryStateDP,
|
|
734
|
+
LowBat: lowBatIndicator,
|
|
735
|
+
LowBatDP: isLowBatDP,
|
|
736
|
+
faultReport: faultReportingState,
|
|
737
|
+
faultReportDP: faultReportingDP,
|
|
738
|
+
SignalStrengthDP: deviceQualityDP,
|
|
739
|
+
SignalStrength: linkQuality,
|
|
740
|
+
UnreachState: deviceUnreachState,
|
|
741
|
+
UnreachDP: unreachDP,
|
|
742
|
+
DeviceStateSelectorDP: deviceStateSelectorDP,
|
|
743
|
+
rssiPeerSelectorDP: rssiPeerSelectorDP,
|
|
744
|
+
LastContact: lastContactString,
|
|
745
|
+
Status: deviceState,
|
|
746
|
+
UpdateDP: deviceUpdateDP,
|
|
747
|
+
Upgradable: isUpgradable,
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
} // <-- end of loop
|
|
751
|
+
} // <-- end of createData
|
|
752
|
+
|
|
753
|
+
/*=============================================
|
|
754
|
+
= functions to get data =
|
|
755
|
+
=============================================*/
|
|
543
756
|
|
|
544
757
|
/**
|
|
545
758
|
* @param {object} id - deviceID
|
|
@@ -559,25 +772,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
559
772
|
let folderName;
|
|
560
773
|
let deviceID;
|
|
561
774
|
|
|
562
|
-
switch (this.
|
|
563
|
-
// Get ID with currDeviceString from datapoint
|
|
564
|
-
case 'switchbotBle':
|
|
565
|
-
case 'esphome':
|
|
566
|
-
case 'apcups':
|
|
567
|
-
deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
|
|
568
|
-
break;
|
|
569
|
-
|
|
570
|
-
case 'eusec':
|
|
571
|
-
deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
|
|
572
|
-
if (deviceName === null || deviceName === undefined) {
|
|
573
|
-
if (deviceObject && typeof deviceObject === 'object') {
|
|
574
|
-
deviceName = deviceObject.common.name;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
break;
|
|
578
|
-
|
|
775
|
+
switch (this.selAdapter[i].adapterID) {
|
|
579
776
|
case 'fullybrowser':
|
|
580
|
-
deviceName = (await this.getInitValue(currDeviceString + this.
|
|
777
|
+
deviceName = (await this.getInitValue(currDeviceString + this.selAdapter[i].id)) + ' ' + (await this.getInitValue(currDeviceString + this.selAdapter[i].id2));
|
|
581
778
|
break;
|
|
582
779
|
|
|
583
780
|
// Get ID with short currDeviceString from objectjson
|
|
@@ -585,6 +782,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
585
782
|
case 'hmrpc':
|
|
586
783
|
case 'nukiExt':
|
|
587
784
|
case 'wled':
|
|
785
|
+
case 'mqttNuki':
|
|
588
786
|
if (shortDeviceObject && typeof shortDeviceObject === 'object') {
|
|
589
787
|
deviceName = shortDeviceObject.common.name;
|
|
590
788
|
}
|
|
@@ -601,7 +799,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
601
799
|
case 'mihomeVacuum':
|
|
602
800
|
case 'roomba':
|
|
603
801
|
folderName = shortCurrDeviceString.slice(shortCurrDeviceString.lastIndexOf('.') + 1);
|
|
604
|
-
deviceID = await this.getInitValue(shortCurrDeviceString + this.
|
|
802
|
+
deviceID = await this.getInitValue(shortCurrDeviceString + this.selAdapter[i].id);
|
|
605
803
|
deviceName = `I${folderName} ${deviceID}`;
|
|
606
804
|
break;
|
|
607
805
|
|
|
@@ -630,8 +828,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
630
828
|
|
|
631
829
|
// Get ID with main selektor from objectjson
|
|
632
830
|
default:
|
|
633
|
-
if (
|
|
634
|
-
|
|
831
|
+
if (this.selAdapter[i].id !== 'none' || this.selAdapter[i].id !== undefined) deviceName = await this.getInitValue(currDeviceString + this.selAdapter[i].id);
|
|
832
|
+
if (deviceName === null || deviceName === undefined) {
|
|
833
|
+
if (deviceObject && typeof deviceObject === 'object') {
|
|
834
|
+
deviceName = deviceObject.common.name;
|
|
835
|
+
}
|
|
635
836
|
}
|
|
636
837
|
break;
|
|
637
838
|
}
|
|
@@ -659,6 +860,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
659
860
|
switch (adapterID) {
|
|
660
861
|
case 'roomba':
|
|
661
862
|
case 'sonoff':
|
|
863
|
+
case 'smartgarden':
|
|
662
864
|
linkQuality = deviceQualityState.val + '%'; // If quality state is already an percent value
|
|
663
865
|
break;
|
|
664
866
|
case 'lupusec':
|
|
@@ -775,8 +977,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
775
977
|
async setLowbatIndicator(deviceBatteryState, deviceLowBatState, faultReportState, adapterID) {
|
|
776
978
|
let lowBatIndicator = false;
|
|
777
979
|
/*=============================================
|
|
778
|
-
|
|
779
|
-
|
|
980
|
+
= Set Lowbat indicator =
|
|
981
|
+
=============================================*/
|
|
780
982
|
if (deviceLowBatState !== undefined || faultReportState !== undefined) {
|
|
781
983
|
switch (adapterID) {
|
|
782
984
|
case 'hmrpc':
|
|
@@ -890,29 +1092,29 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
890
1092
|
}
|
|
891
1093
|
|
|
892
1094
|
/*=============================================
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
if (this.
|
|
1095
|
+
= Set Online Status =
|
|
1096
|
+
=============================================*/
|
|
1097
|
+
if (this.configMaxMinutes !== undefined) {
|
|
896
1098
|
switch (adapterID) {
|
|
897
1099
|
case 'hmrpc':
|
|
898
|
-
if (this.
|
|
1100
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
899
1101
|
if (deviceUnreachState === 1) {
|
|
900
1102
|
deviceState = 'Offline'; //set online state to offline
|
|
901
1103
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
902
1104
|
}
|
|
903
|
-
} else if (lastDeviceUnreachStateChange > this.
|
|
1105
|
+
} else if (lastDeviceUnreachStateChange > this.configMaxMinutes[adapterID] && deviceUnreachState === 1) {
|
|
904
1106
|
deviceState = 'Offline'; //set online state to offline
|
|
905
1107
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
906
1108
|
}
|
|
907
1109
|
break;
|
|
908
1110
|
case 'hmiP':
|
|
909
1111
|
case 'maxcube':
|
|
910
|
-
if (this.
|
|
1112
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
911
1113
|
if (deviceUnreachState) {
|
|
912
1114
|
deviceState = 'Offline'; //set online state to offline
|
|
913
1115
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
914
1116
|
}
|
|
915
|
-
} else if (lastDeviceUnreachStateChange > this.
|
|
1117
|
+
} else if (lastDeviceUnreachStateChange > this.configMaxMinutes[adapterID] && deviceUnreachState) {
|
|
916
1118
|
deviceState = 'Offline'; //set online state to offline
|
|
917
1119
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
918
1120
|
}
|
|
@@ -927,57 +1129,68 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
927
1129
|
case 'unifi':
|
|
928
1130
|
case 'zigbee':
|
|
929
1131
|
case 'zigbee2MQTT':
|
|
930
|
-
if (this.
|
|
1132
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
931
1133
|
if (!deviceUnreachState) {
|
|
932
1134
|
deviceState = 'Offline'; //set online state to offline
|
|
933
1135
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
934
1136
|
}
|
|
935
|
-
} else if (!deviceUnreachState && lastDeviceUnreachStateChange > this.
|
|
1137
|
+
} else if (!deviceUnreachState && lastDeviceUnreachStateChange > this.configMaxMinutes[adapterID]) {
|
|
936
1138
|
deviceState = 'Offline'; //set online state to offline
|
|
937
1139
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
938
1140
|
}
|
|
939
1141
|
break;
|
|
940
1142
|
case 'mqttClientZigbee2Mqtt':
|
|
941
|
-
if (this.
|
|
1143
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
942
1144
|
if (deviceUnreachState !== 'online') {
|
|
943
1145
|
deviceState = 'Offline'; //set online state to offline
|
|
944
1146
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
945
1147
|
}
|
|
946
|
-
} else if (deviceUnreachState !== 'online' && lastDeviceUnreachStateChange > this.
|
|
1148
|
+
} else if (deviceUnreachState !== 'online' && lastDeviceUnreachStateChange > this.configMaxMinutes[adapterID]) {
|
|
947
1149
|
deviceState = 'Offline'; //set online state to offline
|
|
948
1150
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
949
1151
|
}
|
|
950
1152
|
break;
|
|
951
1153
|
case 'mihome':
|
|
952
1154
|
if (deviceUnreachState !== undefined) {
|
|
953
|
-
if (this.
|
|
1155
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
954
1156
|
if (!deviceUnreachState) {
|
|
955
1157
|
deviceState = 'Offline'; //set online state to offline
|
|
956
1158
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
957
1159
|
}
|
|
958
|
-
} else if (lastContact > this.
|
|
1160
|
+
} else if (lastContact > this.configMaxMinutes[adapterID]) {
|
|
959
1161
|
deviceState = 'Offline'; //set online state to offline
|
|
960
1162
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
961
1163
|
}
|
|
962
1164
|
} else {
|
|
963
1165
|
if (this.config.mihomeMaxMinutes <= 0) {
|
|
964
|
-
if (this.
|
|
1166
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
965
1167
|
deviceState = 'Offline'; //set online state to offline
|
|
966
1168
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
967
1169
|
}
|
|
968
|
-
} else if (lastContact > this.
|
|
1170
|
+
} else if (lastContact > this.configMaxMinutes[adapterID]) {
|
|
969
1171
|
deviceState = 'Offline'; //set online state to offline
|
|
970
1172
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
971
1173
|
}
|
|
972
1174
|
}
|
|
973
1175
|
break;
|
|
1176
|
+
case 'smartgarden':
|
|
1177
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
1178
|
+
if (deviceUnreachState === 'OFFLINE') {
|
|
1179
|
+
deviceState = 'Offline'; //set online state to offline
|
|
1180
|
+
linkQuality = '0%'; // set linkQuality to nothing
|
|
1181
|
+
}
|
|
1182
|
+
} else if (deviceUnreachState === 'OFFLINE' && lastDeviceUnreachStateChange > this.configMaxMinutes[adapterID]) {
|
|
1183
|
+
deviceState = 'Offline'; //set online state to offline
|
|
1184
|
+
linkQuality = '0%'; // set linkQuality to nothing
|
|
1185
|
+
}
|
|
1186
|
+
break;
|
|
974
1187
|
default:
|
|
975
|
-
if (this.
|
|
1188
|
+
if (this.configMaxMinutes[adapterID] <= 0) {
|
|
976
1189
|
if (!deviceUnreachState) {
|
|
977
1190
|
deviceState = 'Offline'; //set online state to offline
|
|
978
1191
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
979
1192
|
}
|
|
980
|
-
} else if (lastContact > this.
|
|
1193
|
+
} else if (lastContact > this.configMaxMinutes[adapterID]) {
|
|
981
1194
|
deviceState = 'Offline'; //set online state to offline
|
|
982
1195
|
linkQuality = '0%'; // set linkQuality to nothing
|
|
983
1196
|
}
|
|
@@ -1018,241 +1231,6 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1018
1231
|
}
|
|
1019
1232
|
}
|
|
1020
1233
|
|
|
1021
|
-
/**
|
|
1022
|
-
* @param {object} i - Device Object
|
|
1023
|
-
*/
|
|
1024
|
-
async createData(i) {
|
|
1025
|
-
const devices = await this.getForeignStatesAsync(this.arrDev[i].Selektor);
|
|
1026
|
-
const adapterID = this.arrDev[i].adapterID;
|
|
1027
|
-
|
|
1028
|
-
/*---------- Start of loop ----------*/
|
|
1029
|
-
for (const [id] of Object.entries(devices)) {
|
|
1030
|
-
if (!isUnloaded) {
|
|
1031
|
-
/*=============================================
|
|
1032
|
-
= Get device name =
|
|
1033
|
-
=============================================*/
|
|
1034
|
-
const deviceName = await this.getDeviceName(id, i);
|
|
1035
|
-
|
|
1036
|
-
/*=============================================
|
|
1037
|
-
= Get adapter name =
|
|
1038
|
-
=============================================*/
|
|
1039
|
-
const adapter = this.arrDev[i].adapter;
|
|
1040
|
-
|
|
1041
|
-
/*=============================================
|
|
1042
|
-
= Get path to datapoints =
|
|
1043
|
-
=============================================*/
|
|
1044
|
-
const currDeviceString = id.slice(0, id.lastIndexOf('.') + 1 - 1);
|
|
1045
|
-
const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
|
|
1046
|
-
|
|
1047
|
-
/*=============================================
|
|
1048
|
-
= Get signal strength =
|
|
1049
|
-
=============================================*/
|
|
1050
|
-
let deviceQualityDP = currDeviceString + this.arrDev[i].rssiState;
|
|
1051
|
-
let deviceQualityState;
|
|
1052
|
-
|
|
1053
|
-
switch (adapterID) {
|
|
1054
|
-
case 'mihomeVacuum':
|
|
1055
|
-
deviceQualityDP = shortCurrDeviceString + this.arrDev[i].rssiState;
|
|
1056
|
-
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
1057
|
-
break;
|
|
1058
|
-
|
|
1059
|
-
case 'netatmo':
|
|
1060
|
-
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
1061
|
-
if (!deviceQualityState) {
|
|
1062
|
-
deviceQualityDP = currDeviceString + this.arrDev[i].rfState;
|
|
1063
|
-
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
1064
|
-
}
|
|
1065
|
-
break;
|
|
1066
|
-
|
|
1067
|
-
default:
|
|
1068
|
-
deviceQualityState = await this.getForeignStateAsync(deviceQualityDP);
|
|
1069
|
-
break;
|
|
1070
|
-
}
|
|
1071
|
-
//subscribe to states
|
|
1072
|
-
this.subscribeForeignStatesAsync(deviceQualityDP);
|
|
1073
|
-
|
|
1074
|
-
let linkQuality = await this.calculateSignalStrength(deviceQualityState, adapterID);
|
|
1075
|
-
|
|
1076
|
-
/*=============================================
|
|
1077
|
-
= Get battery data =
|
|
1078
|
-
=============================================*/
|
|
1079
|
-
let deviceBatteryStateDP;
|
|
1080
|
-
let deviceBatteryState;
|
|
1081
|
-
let batteryHealth;
|
|
1082
|
-
let batteryHealthRaw;
|
|
1083
|
-
let lowBatIndicator;
|
|
1084
|
-
let isBatteryDevice;
|
|
1085
|
-
let isLowBatDP;
|
|
1086
|
-
let faultReportingDP;
|
|
1087
|
-
let faultReportingState;
|
|
1088
|
-
|
|
1089
|
-
const deviceChargerStateDP = currDeviceString + this.arrDev[i].charger;
|
|
1090
|
-
const deviceChargerState = await this.getInitValue(deviceChargerStateDP);
|
|
1091
|
-
|
|
1092
|
-
if (deviceChargerState === undefined || deviceChargerState === false) {
|
|
1093
|
-
// Get battery states
|
|
1094
|
-
switch (adapterID) {
|
|
1095
|
-
case 'hueExt':
|
|
1096
|
-
case 'mihomeVacuum':
|
|
1097
|
-
case 'mqttNuki':
|
|
1098
|
-
deviceBatteryStateDP = shortCurrDeviceString + this.arrDev[i].battery;
|
|
1099
|
-
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
1100
|
-
if (deviceBatteryState === undefined) {
|
|
1101
|
-
deviceBatteryStateDP = shortCurrDeviceString + this.arrDev[i].battery2;
|
|
1102
|
-
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
1103
|
-
}
|
|
1104
|
-
break;
|
|
1105
|
-
default:
|
|
1106
|
-
deviceBatteryStateDP = currDeviceString + this.arrDev[i].battery;
|
|
1107
|
-
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
1108
|
-
if (deviceBatteryState === undefined) {
|
|
1109
|
-
deviceBatteryStateDP = currDeviceString + this.arrDev[i].battery2;
|
|
1110
|
-
deviceBatteryState = await this.getInitValue(deviceBatteryStateDP);
|
|
1111
|
-
}
|
|
1112
|
-
break;
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
// Get low bat states
|
|
1116
|
-
isLowBatDP = currDeviceString + this.arrDev[i].isLowBat;
|
|
1117
|
-
let deviceLowBatState = await this.getInitValue(isLowBatDP);
|
|
1118
|
-
if (deviceLowBatState === undefined) {
|
|
1119
|
-
isLowBatDP = currDeviceString + this.arrDev[i].isLowBat2;
|
|
1120
|
-
deviceLowBatState = await this.getInitValue(isLowBatDP);
|
|
1121
|
-
}
|
|
1122
|
-
if (deviceLowBatState === undefined) isLowBatDP = 'none';
|
|
1123
|
-
|
|
1124
|
-
faultReportingDP = shortCurrDeviceString + this.arrDev[i].faultReporting;
|
|
1125
|
-
faultReportingState = await this.getInitValue(faultReportingDP);
|
|
1126
|
-
|
|
1127
|
-
//subscribe to states
|
|
1128
|
-
this.subscribeForeignStatesAsync(deviceBatteryStateDP);
|
|
1129
|
-
this.subscribeForeignStatesAsync(isLowBatDP);
|
|
1130
|
-
this.subscribeForeignStatesAsync(faultReportingDP);
|
|
1131
|
-
|
|
1132
|
-
const batteryData = await this.getBatteryData(deviceBatteryState, deviceLowBatState, adapterID);
|
|
1133
|
-
batteryHealth = batteryData[0];
|
|
1134
|
-
batteryHealthRaw = batteryData[2];
|
|
1135
|
-
isBatteryDevice = batteryData[1];
|
|
1136
|
-
|
|
1137
|
-
if (isBatteryDevice) {
|
|
1138
|
-
lowBatIndicator = await this.setLowbatIndicator(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
/*=============================================
|
|
1143
|
-
= Get last contact of device =
|
|
1144
|
-
=============================================*/
|
|
1145
|
-
let unreachDP = currDeviceString + this.arrDev[i].reach;
|
|
1146
|
-
const deviceStateSelectorDP = shortCurrDeviceString + this.arrDev[i].stateValue;
|
|
1147
|
-
const rssiPeerSelectorDP = currDeviceString + this.arrDev[i].rssiPeerState;
|
|
1148
|
-
const timeSelector = currDeviceString + this.arrDev[i].timeSelector;
|
|
1149
|
-
|
|
1150
|
-
let deviceUnreachState = await this.getInitValue(unreachDP);
|
|
1151
|
-
if (deviceUnreachState === undefined) {
|
|
1152
|
-
unreachDP = shortCurrDeviceString + this.arrDev[i].reach;
|
|
1153
|
-
deviceUnreachState = await this.getInitValue(shortCurrDeviceString + this.arrDev[i].reach);
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
// subscribe to states
|
|
1157
|
-
this.subscribeForeignStatesAsync(timeSelector);
|
|
1158
|
-
this.subscribeForeignStatesAsync(unreachDP);
|
|
1159
|
-
this.subscribeForeignStatesAsync(deviceStateSelectorDP);
|
|
1160
|
-
this.subscribeForeignStatesAsync(rssiPeerSelectorDP);
|
|
1161
|
-
|
|
1162
|
-
const onlineState = await this.getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorDP, rssiPeerSelectorDP);
|
|
1163
|
-
let deviceState;
|
|
1164
|
-
let lastContactString;
|
|
1165
|
-
|
|
1166
|
-
if (onlineState) {
|
|
1167
|
-
lastContactString = onlineState[0];
|
|
1168
|
-
deviceState = onlineState[1];
|
|
1169
|
-
linkQuality = onlineState[2];
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
/*=============================================
|
|
1173
|
-
= Get update data =
|
|
1174
|
-
=============================================*/
|
|
1175
|
-
const deviceUpdateDP = currDeviceString + this.arrDev[i].upgrade;
|
|
1176
|
-
let isUpgradable;
|
|
1177
|
-
|
|
1178
|
-
if (this.config.checkSendDeviceUpgrade) {
|
|
1179
|
-
const deviceUpdateSelector = await this.getInitValue(deviceUpdateDP);
|
|
1180
|
-
|
|
1181
|
-
if (deviceUpdateSelector) {
|
|
1182
|
-
isUpgradable = true;
|
|
1183
|
-
} else if (!deviceUpdateSelector) {
|
|
1184
|
-
isUpgradable = false;
|
|
1185
|
-
}
|
|
1186
|
-
// subscribe to states
|
|
1187
|
-
this.subscribeForeignStatesAsync(deviceUpdateDP);
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
/*=============================================
|
|
1191
|
-
= Fill Raw Lists =
|
|
1192
|
-
=============================================*/
|
|
1193
|
-
|
|
1194
|
-
/* Add only devices with battery in the rawlist */
|
|
1195
|
-
if (this.listOnlyBattery && isBatteryDevice) {
|
|
1196
|
-
this.listAllDevicesRaw.push({
|
|
1197
|
-
Path: id,
|
|
1198
|
-
Device: deviceName,
|
|
1199
|
-
adapterID: adapterID,
|
|
1200
|
-
Adapter: adapter,
|
|
1201
|
-
timeSelector: timeSelector,
|
|
1202
|
-
isBatteryDevice: isBatteryDevice,
|
|
1203
|
-
Battery: batteryHealth,
|
|
1204
|
-
BatteryRaw: batteryHealthRaw,
|
|
1205
|
-
batteryDP: deviceBatteryStateDP,
|
|
1206
|
-
LowBat: lowBatIndicator,
|
|
1207
|
-
LowBatDP: isLowBatDP,
|
|
1208
|
-
faultReport: faultReportingState,
|
|
1209
|
-
faultReportDP: faultReportingDP,
|
|
1210
|
-
SignalStrengthDP: deviceQualityDP,
|
|
1211
|
-
SignalStrength: linkQuality,
|
|
1212
|
-
UnreachState: deviceUnreachState,
|
|
1213
|
-
UnreachDP: unreachDP,
|
|
1214
|
-
DeviceStateSelectorDP: deviceStateSelectorDP,
|
|
1215
|
-
rssiPeerSelectorDP: rssiPeerSelectorDP,
|
|
1216
|
-
LastContact: lastContactString,
|
|
1217
|
-
Status: deviceState,
|
|
1218
|
-
UpdateDP: deviceUpdateDP,
|
|
1219
|
-
Upgradable: isUpgradable,
|
|
1220
|
-
});
|
|
1221
|
-
} else {
|
|
1222
|
-
/* Add all devices */
|
|
1223
|
-
this.listAllDevicesRaw.push({
|
|
1224
|
-
Path: id,
|
|
1225
|
-
Device: deviceName,
|
|
1226
|
-
adapterID: adapterID,
|
|
1227
|
-
Adapter: adapter,
|
|
1228
|
-
timeSelector: timeSelector,
|
|
1229
|
-
isBatteryDevice: isBatteryDevice,
|
|
1230
|
-
Battery: batteryHealth,
|
|
1231
|
-
BatteryRaw: batteryHealthRaw,
|
|
1232
|
-
batteryDP: deviceBatteryStateDP,
|
|
1233
|
-
LowBat: lowBatIndicator,
|
|
1234
|
-
LowBatDP: isLowBatDP,
|
|
1235
|
-
faultReport: faultReportingState,
|
|
1236
|
-
faultReportDP: faultReportingDP,
|
|
1237
|
-
SignalStrengthDP: deviceQualityDP,
|
|
1238
|
-
SignalStrength: linkQuality,
|
|
1239
|
-
UnreachState: deviceUnreachState,
|
|
1240
|
-
UnreachDP: unreachDP,
|
|
1241
|
-
DeviceStateSelectorDP: deviceStateSelectorDP,
|
|
1242
|
-
rssiPeerSelectorDP: rssiPeerSelectorDP,
|
|
1243
|
-
LastContact: lastContactString,
|
|
1244
|
-
Status: deviceState,
|
|
1245
|
-
UpdateDP: deviceUpdateDP,
|
|
1246
|
-
Upgradable: isUpgradable,
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
} else {
|
|
1250
|
-
/* cancel run if unloaded was called. */
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
} // <-- end of loop
|
|
1254
|
-
} // <-- end of createData
|
|
1255
|
-
|
|
1256
1234
|
/**
|
|
1257
1235
|
* Create Lists
|
|
1258
1236
|
*/
|
|
@@ -1264,6 +1242,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1264
1242
|
this.offlineDevices = [];
|
|
1265
1243
|
this.batteryLowPoweredRaw = [];
|
|
1266
1244
|
this.offlineDevicesRaw = [];
|
|
1245
|
+
this.upgradableDevicesRaw = [];
|
|
1267
1246
|
this.upgradableList = [];
|
|
1268
1247
|
|
|
1269
1248
|
if (adptName === undefined) {
|
|
@@ -1291,6 +1270,15 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1291
1270
|
});
|
|
1292
1271
|
}
|
|
1293
1272
|
|
|
1273
|
+
// upgradable raw list
|
|
1274
|
+
if (device.Upgradable) {
|
|
1275
|
+
this.upgradableDevicesRaw.push({
|
|
1276
|
+
Path: device.Path,
|
|
1277
|
+
Device: device.Device,
|
|
1278
|
+
Adapter: device.Adapter,
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1294
1282
|
if (adptName === '' && !this.blacklistLists.includes(device.Path)) {
|
|
1295
1283
|
await this.theLists(device);
|
|
1296
1284
|
}
|
|
@@ -1405,32 +1393,188 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1405
1393
|
await this.createLists(adptName);
|
|
1406
1394
|
}
|
|
1407
1395
|
}
|
|
1408
|
-
await this.writeDatapoints(adptName); // fill the datapoints
|
|
1409
|
-
} catch (error) {
|
|
1410
|
-
this.errorReporting('[createDataForEachAdapter]', error);
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
this.log.debug(`Function finished: ${this.createDataForEachAdapter.name}`);
|
|
1414
|
-
} // <-- end of createDataForEachAdapter
|
|
1396
|
+
await this.writeDatapoints(adptName); // fill the datapoints
|
|
1397
|
+
} catch (error) {
|
|
1398
|
+
this.errorReporting('[createDataForEachAdapter]', error);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
this.log.debug(`Function finished: ${this.createDataForEachAdapter.name}`);
|
|
1402
|
+
} // <-- end of createDataForEachAdapter
|
|
1403
|
+
|
|
1404
|
+
/**
|
|
1405
|
+
* create Data of all selected adapter in one list
|
|
1406
|
+
*/
|
|
1407
|
+
async createDataOfAllAdapter() {
|
|
1408
|
+
this.log.debug(`Function started: ${this.createDataOfAllAdapter.name}`);
|
|
1409
|
+
|
|
1410
|
+
try {
|
|
1411
|
+
for (let i = 0; i < this.selAdapter.length; i++) {
|
|
1412
|
+
await this.createData(i);
|
|
1413
|
+
await this.createLists();
|
|
1414
|
+
}
|
|
1415
|
+
await this.writeDatapoints(); // fill the datapoints
|
|
1416
|
+
} catch (error) {
|
|
1417
|
+
this.errorReporting('[createDataOfAllAdapter]', error);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
this.log.debug(`Function finished: ${this.createDataOfAllAdapter.name}`);
|
|
1421
|
+
} // <-- end of createDataOfAllAdapter
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* @param {string} [adptName] - Adaptername
|
|
1425
|
+
*/
|
|
1426
|
+
async writeDatapoints(adptName) {
|
|
1427
|
+
// fill the datapoints
|
|
1428
|
+
|
|
1429
|
+
this.log.debug(`Start the function: ${this.writeDatapoints.name}`);
|
|
1430
|
+
|
|
1431
|
+
try {
|
|
1432
|
+
let dpSubFolder;
|
|
1433
|
+
//write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
|
|
1434
|
+
if (adptName) {
|
|
1435
|
+
dpSubFolder = adptName + '.';
|
|
1436
|
+
} else {
|
|
1437
|
+
dpSubFolder = '';
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// Write Datapoints for counts
|
|
1441
|
+
await this.setStateAsync(`${dpSubFolder}offlineCount`, { val: this.offlineDevicesCount, ack: true });
|
|
1442
|
+
await this.setStateAsync(`${dpSubFolder}countAll`, { val: this.deviceCounter, ack: true });
|
|
1443
|
+
await this.setStateAsync(`${dpSubFolder}batteryCount`, { val: this.batteryPoweredCount, ack: true });
|
|
1444
|
+
await this.setStateAsync(`${dpSubFolder}lowBatteryCount`, { val: this.lowBatteryPoweredCount, ack: true });
|
|
1445
|
+
await this.setStateAsync(`${dpSubFolder}upgradableCount`, { val: this.upgradableDevicesCount, ack: true });
|
|
1446
|
+
|
|
1447
|
+
// List all devices
|
|
1448
|
+
if (this.deviceCounter === 0) {
|
|
1449
|
+
// if no device is count, write the JSON List with default value
|
|
1450
|
+
this.listAllDevices = [{ Device: '--none--', Adapter: '', Battery: '', 'Last contact': '', 'Signal strength': '' }];
|
|
1451
|
+
}
|
|
1452
|
+
await this.setStateAsync(`${dpSubFolder}listAll`, { val: JSON.stringify(this.listAllDevices), ack: true });
|
|
1453
|
+
|
|
1454
|
+
// List link quality
|
|
1455
|
+
if (this.linkQualityCount === 0) {
|
|
1456
|
+
// if no device is count, write the JSON List with default value
|
|
1457
|
+
this.linkQualityDevices = [{ Device: '--none--', Adapter: '', 'Signal strength': '' }];
|
|
1458
|
+
}
|
|
1459
|
+
//write JSON list
|
|
1460
|
+
await this.setStateAsync(`${dpSubFolder}linkQualityList`, {
|
|
1461
|
+
val: JSON.stringify(this.linkQualityDevices),
|
|
1462
|
+
ack: true,
|
|
1463
|
+
});
|
|
1464
|
+
|
|
1465
|
+
// List offline devices
|
|
1466
|
+
if (this.offlineDevicesCount === 0) {
|
|
1467
|
+
// if no device is count, write the JSON List with default value
|
|
1468
|
+
this.offlineDevices = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
|
|
1469
|
+
}
|
|
1470
|
+
//write JSON list
|
|
1471
|
+
await this.setStateAsync(`${dpSubFolder}offlineList`, {
|
|
1472
|
+
val: JSON.stringify(this.offlineDevices),
|
|
1473
|
+
ack: true,
|
|
1474
|
+
});
|
|
1475
|
+
|
|
1476
|
+
// List updatable
|
|
1477
|
+
if (this.upgradableDevicesCount === 0) {
|
|
1478
|
+
// if no device is count, write the JSON List with default value
|
|
1479
|
+
this.upgradableList = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
|
|
1480
|
+
}
|
|
1481
|
+
//write JSON list
|
|
1482
|
+
await this.setStateAsync(`${dpSubFolder}upgradableList`, {
|
|
1483
|
+
val: JSON.stringify(this.upgradableList),
|
|
1484
|
+
ack: true,
|
|
1485
|
+
});
|
|
1486
|
+
|
|
1487
|
+
// List battery powered
|
|
1488
|
+
if (this.batteryPoweredCount === 0) {
|
|
1489
|
+
// if no device is count, write the JSON List with default value
|
|
1490
|
+
this.batteryPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
|
|
1491
|
+
}
|
|
1492
|
+
//write JSON list
|
|
1493
|
+
await this.setStateAsync(`${dpSubFolder}batteryList`, {
|
|
1494
|
+
val: JSON.stringify(this.batteryPowered),
|
|
1495
|
+
ack: true,
|
|
1496
|
+
});
|
|
1497
|
+
|
|
1498
|
+
// list battery low powered
|
|
1499
|
+
if (this.lowBatteryPoweredCount === 0) {
|
|
1500
|
+
// if no device is count, write the JSON List with default value
|
|
1501
|
+
this.batteryLowPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
|
|
1502
|
+
}
|
|
1503
|
+
//write JSON list
|
|
1504
|
+
await this.setStateAsync(`${dpSubFolder}lowBatteryList`, {
|
|
1505
|
+
val: JSON.stringify(this.batteryLowPowered),
|
|
1506
|
+
ack: true,
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
// set booleans datapoints
|
|
1510
|
+
if (this.offlineDevicesCount === 0) {
|
|
1511
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceOffline`, {
|
|
1512
|
+
val: false,
|
|
1513
|
+
ack: true,
|
|
1514
|
+
});
|
|
1515
|
+
} else {
|
|
1516
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceOffline`, {
|
|
1517
|
+
val: true,
|
|
1518
|
+
ack: true,
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
if (this.lowBatteryPoweredCount === 0) {
|
|
1523
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceLowBat`, {
|
|
1524
|
+
val: false,
|
|
1525
|
+
ack: true,
|
|
1526
|
+
});
|
|
1527
|
+
} else {
|
|
1528
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceLowBat`, {
|
|
1529
|
+
val: true,
|
|
1530
|
+
ack: true,
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1415
1533
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1534
|
+
if (this.upgradableDevicesCount === 0) {
|
|
1535
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceUpdatable`, {
|
|
1536
|
+
val: false,
|
|
1537
|
+
ack: true,
|
|
1538
|
+
});
|
|
1539
|
+
} else {
|
|
1540
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceUpdatable`, {
|
|
1541
|
+
val: true,
|
|
1542
|
+
ack: true,
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1421
1545
|
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
await this.
|
|
1425
|
-
|
|
1546
|
+
//write HTML list
|
|
1547
|
+
if (this.createHtmlList) {
|
|
1548
|
+
await this.setStateAsync(`${dpSubFolder}linkQualityListHTML`, {
|
|
1549
|
+
val: await this.creatLinkQualityListHTML(this.linkQualityDevices, this.linkQualityCount),
|
|
1550
|
+
ack: true,
|
|
1551
|
+
});
|
|
1552
|
+
await this.setStateAsync(`${dpSubFolder}offlineListHTML`, {
|
|
1553
|
+
val: await this.createOfflineListHTML(this.offlineDevices, this.offlineDevicesCount),
|
|
1554
|
+
ack: true,
|
|
1555
|
+
});
|
|
1556
|
+
await this.setStateAsync(`${dpSubFolder}batteryListHTML`, {
|
|
1557
|
+
val: await this.createBatteryListHTML(this.batteryPowered, this.batteryPoweredCount, false),
|
|
1558
|
+
ack: true,
|
|
1559
|
+
});
|
|
1560
|
+
await this.setStateAsync(`${dpSubFolder}lowBatteryListHTML`, {
|
|
1561
|
+
val: await this.createBatteryListHTML(this.batteryLowPowered, this.lowBatteryPoweredCount, true),
|
|
1562
|
+
ack: true,
|
|
1563
|
+
});
|
|
1426
1564
|
}
|
|
1427
|
-
|
|
1565
|
+
|
|
1566
|
+
// create timestamp of last run
|
|
1567
|
+
const lastCheck = this.formatDate(new Date(), 'DD.MM.YYYY') + ' - ' + this.formatDate(new Date(), 'hh:mm:ss');
|
|
1568
|
+
await this.setStateAsync('lastCheck', lastCheck, true);
|
|
1428
1569
|
} catch (error) {
|
|
1429
|
-
this.errorReporting('[
|
|
1570
|
+
this.errorReporting('[writeDatapoints]', error);
|
|
1430
1571
|
}
|
|
1572
|
+
this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
|
|
1573
|
+
} //<--End of writing Datapoints
|
|
1431
1574
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1575
|
+
/*=============================================
|
|
1576
|
+
= functions to send notifications =
|
|
1577
|
+
=============================================*/
|
|
1434
1578
|
|
|
1435
1579
|
/**
|
|
1436
1580
|
* Notification service
|
|
@@ -1812,7 +1956,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1812
1956
|
try {
|
|
1813
1957
|
let deviceList = '';
|
|
1814
1958
|
|
|
1815
|
-
for (const id of this.
|
|
1959
|
+
for (const id of this.upgradableDevicesRaw) {
|
|
1816
1960
|
if (!this.blacklistNotify.includes(id.Path)) {
|
|
1817
1961
|
if (!this.config.showAdapterNameinMsg) {
|
|
1818
1962
|
deviceList = `${deviceList}\n${id.Device}`;
|
|
@@ -1821,7 +1965,6 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1821
1965
|
}
|
|
1822
1966
|
}
|
|
1823
1967
|
}
|
|
1824
|
-
|
|
1825
1968
|
if (deviceList.length > 0) {
|
|
1826
1969
|
this.log.info(`Geräte Upgrade: ${deviceList}`);
|
|
1827
1970
|
this.setStateAsync('lastNotification', `Geräte Upgrade: ${deviceList}`, true);
|
|
@@ -1835,157 +1978,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1835
1978
|
}
|
|
1836
1979
|
} //<--End of daily offline notification
|
|
1837
1980
|
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
async writeDatapoints(adptName) {
|
|
1842
|
-
// fill the datapoints
|
|
1843
|
-
|
|
1844
|
-
this.log.debug(`Start the function: ${this.writeDatapoints.name}`);
|
|
1845
|
-
|
|
1846
|
-
try {
|
|
1847
|
-
let dpSubFolder;
|
|
1848
|
-
//write the datapoints in subfolders with the adaptername otherwise write the dP's in the root folder
|
|
1849
|
-
if (adptName) {
|
|
1850
|
-
dpSubFolder = adptName + '.';
|
|
1851
|
-
} else {
|
|
1852
|
-
dpSubFolder = '';
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
// Write Datapoints for counts
|
|
1856
|
-
await this.setStateAsync(`${dpSubFolder}offlineCount`, { val: this.offlineDevicesCount, ack: true });
|
|
1857
|
-
await this.setStateAsync(`${dpSubFolder}countAll`, { val: this.deviceCounter, ack: true });
|
|
1858
|
-
await this.setStateAsync(`${dpSubFolder}batteryCount`, { val: this.batteryPoweredCount, ack: true });
|
|
1859
|
-
await this.setStateAsync(`${dpSubFolder}lowBatteryCount`, { val: this.lowBatteryPoweredCount, ack: true });
|
|
1860
|
-
await this.setStateAsync(`${dpSubFolder}upgradableCount`, { val: this.upgradableDevicesCount, ack: true });
|
|
1861
|
-
|
|
1862
|
-
// List all devices
|
|
1863
|
-
if (this.deviceCounter === 0) {
|
|
1864
|
-
// if no device is count, write the JSON List with default value
|
|
1865
|
-
this.listAllDevices = [{ Device: '--none--', Adapter: '', Battery: '', 'Last contact': '', 'Signal strength': '' }];
|
|
1866
|
-
}
|
|
1867
|
-
await this.setStateAsync(`${dpSubFolder}listAll`, { val: JSON.stringify(this.listAllDevices), ack: true });
|
|
1868
|
-
|
|
1869
|
-
// List link quality
|
|
1870
|
-
if (this.linkQualityCount === 0) {
|
|
1871
|
-
// if no device is count, write the JSON List with default value
|
|
1872
|
-
this.linkQualityDevices = [{ Device: '--none--', Adapter: '', 'Signal strength': '' }];
|
|
1873
|
-
}
|
|
1874
|
-
//write JSON list
|
|
1875
|
-
await this.setStateAsync(`${dpSubFolder}linkQualityList`, {
|
|
1876
|
-
val: JSON.stringify(this.linkQualityDevices),
|
|
1877
|
-
ack: true,
|
|
1878
|
-
});
|
|
1879
|
-
|
|
1880
|
-
// List offline devices
|
|
1881
|
-
if (this.offlineDevicesCount === 0) {
|
|
1882
|
-
// if no device is count, write the JSON List with default value
|
|
1883
|
-
this.offlineDevices = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
|
|
1884
|
-
}
|
|
1885
|
-
//write JSON list
|
|
1886
|
-
await this.setStateAsync(`${dpSubFolder}offlineList`, {
|
|
1887
|
-
val: JSON.stringify(this.offlineDevices),
|
|
1888
|
-
ack: true,
|
|
1889
|
-
});
|
|
1890
|
-
|
|
1891
|
-
// List updatable
|
|
1892
|
-
if (this.upgradableDevicesCount === 0) {
|
|
1893
|
-
// if no device is count, write the JSON List with default value
|
|
1894
|
-
this.upgradableList = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
|
|
1895
|
-
}
|
|
1896
|
-
//write JSON list
|
|
1897
|
-
await this.setStateAsync(`${dpSubFolder}upgradableList`, {
|
|
1898
|
-
val: JSON.stringify(this.upgradableList),
|
|
1899
|
-
ack: true,
|
|
1900
|
-
});
|
|
1901
|
-
|
|
1902
|
-
// List battery powered
|
|
1903
|
-
if (this.batteryPoweredCount === 0) {
|
|
1904
|
-
// if no device is count, write the JSON List with default value
|
|
1905
|
-
this.batteryPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
|
|
1906
|
-
}
|
|
1907
|
-
//write JSON list
|
|
1908
|
-
await this.setStateAsync(`${dpSubFolder}batteryList`, {
|
|
1909
|
-
val: JSON.stringify(this.batteryPowered),
|
|
1910
|
-
ack: true,
|
|
1911
|
-
});
|
|
1912
|
-
|
|
1913
|
-
// list battery low powered
|
|
1914
|
-
if (this.lowBatteryPoweredCount === 0) {
|
|
1915
|
-
// if no device is count, write the JSON List with default value
|
|
1916
|
-
this.batteryLowPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
|
|
1917
|
-
}
|
|
1918
|
-
//write JSON list
|
|
1919
|
-
await this.setStateAsync(`${dpSubFolder}lowBatteryList`, {
|
|
1920
|
-
val: JSON.stringify(this.batteryLowPowered),
|
|
1921
|
-
ack: true,
|
|
1922
|
-
});
|
|
1923
|
-
|
|
1924
|
-
// set booleans datapoints
|
|
1925
|
-
if (this.offlineDevicesCount === 0) {
|
|
1926
|
-
await this.setStateAsync(`${dpSubFolder}oneDeviceOffline`, {
|
|
1927
|
-
val: false,
|
|
1928
|
-
ack: true,
|
|
1929
|
-
});
|
|
1930
|
-
} else {
|
|
1931
|
-
await this.setStateAsync(`${dpSubFolder}oneDeviceOffline`, {
|
|
1932
|
-
val: true,
|
|
1933
|
-
ack: true,
|
|
1934
|
-
});
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
if (this.lowBatteryPoweredCount === 0) {
|
|
1938
|
-
await this.setStateAsync(`${dpSubFolder}oneDeviceLowBat`, {
|
|
1939
|
-
val: false,
|
|
1940
|
-
ack: true,
|
|
1941
|
-
});
|
|
1942
|
-
} else {
|
|
1943
|
-
await this.setStateAsync(`${dpSubFolder}oneDeviceLowBat`, {
|
|
1944
|
-
val: true,
|
|
1945
|
-
ack: true,
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
if (this.upgradableDevicesCount === 0) {
|
|
1950
|
-
await this.setStateAsync(`${dpSubFolder}oneDeviceUpdatable`, {
|
|
1951
|
-
val: false,
|
|
1952
|
-
ack: true,
|
|
1953
|
-
});
|
|
1954
|
-
} else {
|
|
1955
|
-
await this.setStateAsync(`${dpSubFolder}oneDeviceUpdatable`, {
|
|
1956
|
-
val: true,
|
|
1957
|
-
ack: true,
|
|
1958
|
-
});
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
//write HTML list
|
|
1962
|
-
if (this.createHtmlList) {
|
|
1963
|
-
await this.setStateAsync(`${dpSubFolder}linkQualityListHTML`, {
|
|
1964
|
-
val: await this.creatLinkQualityListHTML(this.linkQualityDevices, this.linkQualityCount),
|
|
1965
|
-
ack: true,
|
|
1966
|
-
});
|
|
1967
|
-
await this.setStateAsync(`${dpSubFolder}offlineListHTML`, {
|
|
1968
|
-
val: await this.createOfflineListHTML(this.offlineDevices, this.offlineDevicesCount),
|
|
1969
|
-
ack: true,
|
|
1970
|
-
});
|
|
1971
|
-
await this.setStateAsync(`${dpSubFolder}batteryListHTML`, {
|
|
1972
|
-
val: await this.createBatteryListHTML(this.batteryPowered, this.batteryPoweredCount, false),
|
|
1973
|
-
ack: true,
|
|
1974
|
-
});
|
|
1975
|
-
await this.setStateAsync(`${dpSubFolder}lowBatteryListHTML`, {
|
|
1976
|
-
val: await this.createBatteryListHTML(this.batteryLowPowered, this.lowBatteryPoweredCount, true),
|
|
1977
|
-
ack: true,
|
|
1978
|
-
});
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
|
-
// create timestamp of last run
|
|
1982
|
-
const lastCheck = this.formatDate(new Date(), 'DD.MM.YYYY') + ' - ' + this.formatDate(new Date(), 'hh:mm:ss');
|
|
1983
|
-
await this.setStateAsync('lastCheck', lastCheck, true);
|
|
1984
|
-
} catch (error) {
|
|
1985
|
-
this.errorReporting('[writeDatapoints]', error);
|
|
1986
|
-
}
|
|
1987
|
-
this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
|
|
1988
|
-
} //<--End of writing Datapoints
|
|
1981
|
+
/*=============================================
|
|
1982
|
+
= functions to create html lists =
|
|
1983
|
+
=============================================*/
|
|
1989
1984
|
|
|
1990
1985
|
/**
|
|
1991
1986
|
* @param {object} devices - Device
|
|
@@ -2100,7 +2095,10 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2100
2095
|
return html;
|
|
2101
2096
|
}
|
|
2102
2097
|
|
|
2103
|
-
|
|
2098
|
+
/*=============================================
|
|
2099
|
+
= create datapoints for each adapter =
|
|
2100
|
+
=============================================*/
|
|
2101
|
+
|
|
2104
2102
|
/**
|
|
2105
2103
|
* @param {object} adptName - Adaptername of devices
|
|
2106
2104
|
*/
|
|
@@ -2549,6 +2547,54 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2549
2547
|
});
|
|
2550
2548
|
}
|
|
2551
2549
|
|
|
2550
|
+
/*=============================================
|
|
2551
|
+
= help functions =
|
|
2552
|
+
=============================================*/
|
|
2553
|
+
|
|
2554
|
+
/**
|
|
2555
|
+
* @param {string} id - id which should be capitalize
|
|
2556
|
+
*/
|
|
2557
|
+
capitalize(id) {
|
|
2558
|
+
//make the first letter uppercase
|
|
2559
|
+
return id && id[0].toUpperCase() + id.slice(1);
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
/**
|
|
2563
|
+
* @param {number} dpValue - get Time of this datapoint
|
|
2564
|
+
*/
|
|
2565
|
+
async getTimestamp(dpValue) {
|
|
2566
|
+
const time = new Date();
|
|
2567
|
+
return (dpValue = Math.round((time.getTime() - dpValue) / 1000 / 60));
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
/**
|
|
2571
|
+
* @param {object} obj - State of datapoint
|
|
2572
|
+
*/
|
|
2573
|
+
async getInitValue(obj) {
|
|
2574
|
+
//state can be null or undefinded
|
|
2575
|
+
const foreignState = await this.getForeignStateAsync(obj);
|
|
2576
|
+
if (foreignState) return foreignState.val;
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
/**
|
|
2580
|
+
* @param {object} obj - State of own datapoint
|
|
2581
|
+
*/
|
|
2582
|
+
async getOwnInitValue(obj) {
|
|
2583
|
+
//state can be null or undefinded for own states
|
|
2584
|
+
const stateVal = await this.getStateAsync(obj);
|
|
2585
|
+
if (stateVal) return stateVal.val;
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
/**
|
|
2589
|
+
* @param {object} data - object
|
|
2590
|
+
*/
|
|
2591
|
+
async parseData(data) {
|
|
2592
|
+
if (!data) return {};
|
|
2593
|
+
if (typeof data === 'object') return data;
|
|
2594
|
+
if (typeof data === 'string') return JSON.parse(data);
|
|
2595
|
+
return {};
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2552
2598
|
/**
|
|
2553
2599
|
* @param {string} codePart - Message Prefix
|
|
2554
2600
|
* @param {object} error - Sentry message
|