iobroker.device-watcher 2.2.1 → 2.3.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/LICENSE +1 -1
- package/README.md +129 -31
- package/admin/i18n/de/translations.json +7 -1
- package/admin/i18n/en/translations.json +100 -94
- package/admin/i18n/es/translations.json +7 -1
- package/admin/i18n/fr/translations.json +7 -1
- package/admin/i18n/it/translations.json +7 -1
- package/admin/i18n/nl/translations.json +7 -1
- package/admin/i18n/pl/translations.json +7 -1
- package/admin/i18n/pt/translations.json +7 -1
- package/admin/i18n/ru/translations.json +7 -1
- package/admin/i18n/uk/translations.json +7 -1
- package/admin/i18n/zh-cn/translations.json +7 -1
- package/admin/jsonConfig.json +27 -1
- package/io-package.json +105 -28
- package/lib/arrApart.js +10 -0
- package/main.js +258 -129
- package/package.json +7 -7
package/main.js
CHANGED
|
@@ -30,6 +30,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
30
30
|
this.batteryLowPowered = [];
|
|
31
31
|
this.listAllDevices = [];
|
|
32
32
|
this.blacklistLists = [];
|
|
33
|
+
this.blacklistAdapterLists = [];
|
|
33
34
|
this.blacklistNotify = [];
|
|
34
35
|
this.arrDev = [];
|
|
35
36
|
this.adapterSelected = [];
|
|
@@ -68,6 +69,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
68
69
|
|
|
69
70
|
try {
|
|
70
71
|
this.listOnlyBattery = this.config.listOnlyBattery;
|
|
72
|
+
this.createOwnFolder = this.config.createOwnFolder;
|
|
73
|
+
this.createHtmlList = this.config.createHtmlList;
|
|
71
74
|
|
|
72
75
|
this.supAdapter = {
|
|
73
76
|
alexa2: this.config.alexa2Devices,
|
|
@@ -76,6 +79,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
76
79
|
deconz: this.config.deconzDevices,
|
|
77
80
|
enocean: this.config.enoceanDevices,
|
|
78
81
|
esphome: this.config.esphomeDevices,
|
|
82
|
+
eusec: this.config.eusecDevices,
|
|
79
83
|
fritzdect: this.config.fritzdectDevices,
|
|
80
84
|
fullybrowser: this.config.fullybrowserDevices,
|
|
81
85
|
ham: this.config.hamDevices,
|
|
@@ -124,6 +128,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
124
128
|
deconz: this.config.deconzMaxMinutes,
|
|
125
129
|
enocean: this.config.enoceanMaxMinutes,
|
|
126
130
|
esphome: this.config.esphomeMaxMinutes,
|
|
131
|
+
eusec: this.config.eusecMaxMinutes,
|
|
127
132
|
fritzdect: this.config.fritzdectMaxMinutes,
|
|
128
133
|
fullybrowser: this.config.fullybrowserMaxMinutes,
|
|
129
134
|
ham: this.config.hamMaxMinutes,
|
|
@@ -195,17 +200,13 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
195
200
|
}
|
|
196
201
|
|
|
197
202
|
//create and fill datapoints for each adapter if selected
|
|
198
|
-
if (this.
|
|
203
|
+
if (this.createOwnFolder) {
|
|
199
204
|
try {
|
|
200
205
|
for (const [id] of Object.entries(arrApart)) {
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.log.debug(`Created datapoints for ${this.capitalize(id)}`);
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
return; // cancel run if unloaded was called.
|
|
206
|
+
if (this.supAdapter !== undefined && this.supAdapter[id]) {
|
|
207
|
+
await this.createDPsForEachAdapter(id);
|
|
208
|
+
if (this.createHtmlList) await this.createHtmlListDatapoints(id);
|
|
209
|
+
this.log.debug(`Created datapoints for ${this.capitalize(id)}`);
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
} catch (error) {
|
|
@@ -214,7 +215,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
// create HTML list
|
|
217
|
-
if (this.
|
|
218
|
+
if (this.createHtmlList) await this.createHtmlListDatapoints();
|
|
218
219
|
|
|
219
220
|
//read data first at start
|
|
220
221
|
await this.main();
|
|
@@ -249,7 +250,6 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
249
250
|
let oldLowBatState;
|
|
250
251
|
let contactData;
|
|
251
252
|
let oldStatus;
|
|
252
|
-
let oldSignalStrength;
|
|
253
253
|
|
|
254
254
|
for (const device of this.listAllDevicesRaw) {
|
|
255
255
|
// On statechange update available datapoint
|
|
@@ -257,10 +257,6 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
257
257
|
case device.UpdateDP:
|
|
258
258
|
if (state.val) {
|
|
259
259
|
device.Upgradable = state.val;
|
|
260
|
-
|
|
261
|
-
await this.createLists();
|
|
262
|
-
await this.writeDatapoints();
|
|
263
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
264
260
|
if (!this.blacklistNotify.includes(device.Path)) {
|
|
265
261
|
await this.sendDeviceUpdatesNotification(device.Device, device.Adapter);
|
|
266
262
|
}
|
|
@@ -268,13 +264,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
268
264
|
break;
|
|
269
265
|
|
|
270
266
|
case device.SignalStrengthDP:
|
|
271
|
-
oldSignalStrength = device.SignalStrength;
|
|
272
267
|
device.SignalStrength = await this.calculateSignalStrength(state, device.adapterID);
|
|
273
|
-
if (oldSignalStrength !== device.SignalStrength) {
|
|
274
|
-
await this.createLists();
|
|
275
|
-
await this.writeDatapoints();
|
|
276
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
277
|
-
}
|
|
278
268
|
break;
|
|
279
269
|
|
|
280
270
|
case device.batteryDP:
|
|
@@ -287,16 +277,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
287
277
|
device.LowBat = await this.setLowbatIndicator(state.val, undefined, device.LowBatDP);
|
|
288
278
|
|
|
289
279
|
if (device.LowBat && oldLowBatState !== device.LowBat) {
|
|
290
|
-
await this.createLists();
|
|
291
|
-
await this.writeDatapoints();
|
|
292
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
293
280
|
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(device.Path)) {
|
|
294
281
|
await this.sendLowBatNoticiation(device.Device, device.Adapter, device.Battery);
|
|
295
282
|
}
|
|
296
|
-
} else if (!device.LowBat && oldLowBatState !== device.LowBat) {
|
|
297
|
-
await this.createLists();
|
|
298
|
-
await this.writeDatapoints();
|
|
299
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
300
283
|
}
|
|
301
284
|
}
|
|
302
285
|
break;
|
|
@@ -310,16 +293,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
310
293
|
device.LowBat = await this.setLowbatIndicator(device.BatteryRaw, state.val, device.LowBatDP);
|
|
311
294
|
|
|
312
295
|
if (device.LowBat && oldLowBatState !== device.LowBat) {
|
|
313
|
-
await this.createLists();
|
|
314
|
-
await this.writeDatapoints();
|
|
315
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
316
296
|
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(device.Path)) {
|
|
317
297
|
await this.sendLowBatNoticiation(device.Device, device.Adapter, device.Battery);
|
|
318
298
|
}
|
|
319
|
-
} else if (!device.LowBat && oldLowBatState !== device.LowBat) {
|
|
320
|
-
await this.createLists();
|
|
321
|
-
await this.writeDatapoints();
|
|
322
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
323
299
|
}
|
|
324
300
|
}
|
|
325
301
|
|
|
@@ -344,13 +320,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
344
320
|
device.Status = contactData[1];
|
|
345
321
|
device.SignalStrength = contactData[2];
|
|
346
322
|
}
|
|
347
|
-
if (device.Status !== oldStatus) {
|
|
348
|
-
await this.createLists();
|
|
349
|
-
await this.writeDatapoints();
|
|
350
|
-
if (this.config.createOwnFolder) await this.createDataForEachAdapter(device.adapterID);
|
|
351
|
-
}
|
|
352
323
|
|
|
353
|
-
if (
|
|
324
|
+
if (this.config.checkSendOfflineMsg && oldStatus !== device.Status && !this.blacklistNotify.includes(device.Path)) {
|
|
354
325
|
await this.sendOfflineNotifications(device.Device, device.Adapter, device.Status, device.LastContact);
|
|
355
326
|
}
|
|
356
327
|
break;
|
|
@@ -373,7 +344,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
373
344
|
try {
|
|
374
345
|
result = this.listAllDevicesRaw;
|
|
375
346
|
for (const element in result) {
|
|
376
|
-
const label =
|
|
347
|
+
const label = `${result[element].Adapter}: ${result[element].Device}`;
|
|
377
348
|
const myValueObject = {
|
|
378
349
|
deviceName: result[element].Device,
|
|
379
350
|
adapter: result[element].Adapter,
|
|
@@ -382,7 +353,13 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
382
353
|
devices[myCount] = { label: label, value: JSON.stringify(myValueObject) };
|
|
383
354
|
myCount++;
|
|
384
355
|
}
|
|
385
|
-
|
|
356
|
+
const sortDevices = devices.slice(0);
|
|
357
|
+
sortDevices.sort(function (a, b) {
|
|
358
|
+
const x = a.label;
|
|
359
|
+
const y = b.label;
|
|
360
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
361
|
+
});
|
|
362
|
+
this.sendTo(obj.from, obj.command, sortDevices, obj.callback);
|
|
386
363
|
} catch (error) {
|
|
387
364
|
this.sendTo(obj.from, obj.command, obj.callback);
|
|
388
365
|
}
|
|
@@ -401,6 +378,18 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
401
378
|
const nextTimeout = this.config.updateinterval * 1000;
|
|
402
379
|
|
|
403
380
|
await this.checkLastContact();
|
|
381
|
+
await this.createLists();
|
|
382
|
+
await this.writeDatapoints();
|
|
383
|
+
|
|
384
|
+
if (this.createOwnFolder) {
|
|
385
|
+
for (const [id] of Object.entries(arrApart)) {
|
|
386
|
+
if (this.supAdapter !== undefined && this.supAdapter[id]) {
|
|
387
|
+
await this.createLists(id);
|
|
388
|
+
await this.writeDatapoints(id);
|
|
389
|
+
this.log.debug(`Created and filled data for ${this.capitalize(id)}`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
404
393
|
|
|
405
394
|
// Clear existing timeout
|
|
406
395
|
if (this.refreshDataTimeout) {
|
|
@@ -434,7 +423,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
434
423
|
}
|
|
435
424
|
|
|
436
425
|
// fill datapoints for each adapter if selected
|
|
437
|
-
if (this.
|
|
426
|
+
if (this.createOwnFolder) {
|
|
438
427
|
try {
|
|
439
428
|
for (const [id] of Object.entries(arrApart)) {
|
|
440
429
|
if (this.supAdapter !== undefined && this.supAdapter[id]) {
|
|
@@ -510,6 +499,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
510
499
|
if (myBlacklist[i].checkIgnorLists) {
|
|
511
500
|
this.blacklistLists.push(blacklistParse.path);
|
|
512
501
|
}
|
|
502
|
+
if (myBlacklist[i].checkIgnorAdapterLists) {
|
|
503
|
+
this.blacklistAdapterLists.push(blacklistParse.path);
|
|
504
|
+
}
|
|
513
505
|
// push devices in list to ignor device in notifications
|
|
514
506
|
if (myBlacklist[i].checkIgnorNotify) {
|
|
515
507
|
this.blacklistNotify.push(blacklistParse.path);
|
|
@@ -520,6 +512,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
520
512
|
}
|
|
521
513
|
|
|
522
514
|
if (this.blacklistLists.length >= 1) this.log.info(`Found items on blacklist for lists: ${this.blacklistLists}`);
|
|
515
|
+
if (this.blacklistAdapterLists.length >= 1) this.log.info(`Found items on blacklist for lists: ${this.blacklistAdapterLists}`);
|
|
523
516
|
if (this.blacklistNotify.length >= 1) this.log.info(`Found items on blacklist for notificatioons: ${this.blacklistNotify}`);
|
|
524
517
|
} else {
|
|
525
518
|
return; // cancel run if unloaded was called.
|
|
@@ -546,15 +539,23 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
546
539
|
let folderName;
|
|
547
540
|
let deviceID;
|
|
548
541
|
|
|
549
|
-
// Get ID with currDeviceString from datapoint
|
|
550
542
|
switch (this.arrDev[i].adapterID) {
|
|
551
|
-
// Get ID
|
|
543
|
+
// Get ID with currDeviceString from datapoint
|
|
552
544
|
case 'switchbotBle':
|
|
553
545
|
case 'esphome':
|
|
554
546
|
case 'apcups':
|
|
555
547
|
deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
|
|
556
548
|
break;
|
|
557
549
|
|
|
550
|
+
case 'eusec':
|
|
551
|
+
deviceName = await this.getInitValue(currDeviceString + this.arrDev[i].id);
|
|
552
|
+
if (deviceName === null || deviceName === undefined) {
|
|
553
|
+
if (deviceObject && typeof deviceObject === 'object') {
|
|
554
|
+
deviceName = deviceObject.common.name;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
break;
|
|
558
|
+
|
|
558
559
|
case 'fullybrowser':
|
|
559
560
|
deviceName = (await this.getInitValue(currDeviceString + this.arrDev[i].id)) + ' ' + (await this.getInitValue(currDeviceString + this.arrDev[i].id2));
|
|
560
561
|
break;
|
|
@@ -737,7 +738,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
737
738
|
}
|
|
738
739
|
|
|
739
740
|
/**
|
|
740
|
-
*set low bat indicator
|
|
741
|
+
* set low bat indicator
|
|
741
742
|
* @param {object} deviceBatteryState
|
|
742
743
|
* @param {object} deviceLowBatState
|
|
743
744
|
* @param {object} isLowBatDP
|
|
@@ -969,8 +970,6 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
969
970
|
await this.sendOfflineNotifications(device.Device, device.Adapter, device.Status, device.LastContact);
|
|
970
971
|
}
|
|
971
972
|
}
|
|
972
|
-
await this.createLists();
|
|
973
|
-
await this.writeDatapoints();
|
|
974
973
|
}
|
|
975
974
|
|
|
976
975
|
/**
|
|
@@ -1203,78 +1202,35 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1203
1202
|
}
|
|
1204
1203
|
|
|
1205
1204
|
for (const device of this.listAllDevicesRaw) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
/*---------- fill user lists ----------*/
|
|
1228
|
-
if (!this.blacklistLists.includes(device.Path)) {
|
|
1229
|
-
this.listAllDevices.push({
|
|
1230
|
-
Device: device.Device,
|
|
1231
|
-
Adapter: device.Adapter,
|
|
1232
|
-
Battery: device.Battery,
|
|
1233
|
-
'Signal strength': device.SignalStrength,
|
|
1234
|
-
'Last contact': device.LastContact,
|
|
1235
|
-
Status: device.Status,
|
|
1236
|
-
});
|
|
1237
|
-
// LinkQuality lists
|
|
1238
|
-
if (device.SignalStrength != ' - ') {
|
|
1239
|
-
this.linkQualityDevices.push({
|
|
1240
|
-
Device: device.Device,
|
|
1241
|
-
Adapter: device.Adapter,
|
|
1242
|
-
'Signal strength': device.SignalStrength,
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
// Battery lists
|
|
1246
|
-
if (device['isBatteryDevice']) {
|
|
1247
|
-
this.batteryPowered.push({
|
|
1248
|
-
Device: device.Device,
|
|
1249
|
-
Adapter: device.Adapter,
|
|
1250
|
-
Battery: device.Battery,
|
|
1251
|
-
Status: device.Status,
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
// Low Bat lists
|
|
1255
|
-
if (device.LowBat && device.Status !== 'Offline') {
|
|
1256
|
-
this.batteryLowPowered.push({
|
|
1257
|
-
Device: device.Device,
|
|
1258
|
-
Adapter: device.Adapter,
|
|
1259
|
-
Battery: device.Battery,
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1205
|
+
/*---------- fill raw lists ----------*/
|
|
1206
|
+
// low bat list
|
|
1207
|
+
if (device.LowBat && device.Status !== 'Offline') {
|
|
1208
|
+
this.batteryLowPoweredRaw.push({
|
|
1209
|
+
Path: device.Path,
|
|
1210
|
+
Device: device.Device,
|
|
1211
|
+
Adapter: device.Adapter,
|
|
1212
|
+
Battery: device.Battery,
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
// offline raw list
|
|
1216
|
+
if (device.Status === 'Offline') {
|
|
1217
|
+
this.offlineDevicesRaw.push({
|
|
1218
|
+
Path: device.Path,
|
|
1219
|
+
Device: device.Device,
|
|
1220
|
+
Adapter: device.Adapter,
|
|
1221
|
+
LastContact: device.LastContact,
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1262
1224
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
Device: device.Device,
|
|
1267
|
-
Adapter: device.Adapter,
|
|
1268
|
-
'Last contact': device.LastContact,
|
|
1269
|
-
});
|
|
1270
|
-
}
|
|
1225
|
+
if (adptName === '' && !this.blacklistLists.includes(device.Path)) {
|
|
1226
|
+
await this.theLists(device);
|
|
1227
|
+
}
|
|
1271
1228
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
});
|
|
1229
|
+
if (this.config.createOwnFolder && adptName !== '') {
|
|
1230
|
+
if (device.adapterID.includes(adptName)) {
|
|
1231
|
+
/*---------- fill user lists for each adapter ----------*/
|
|
1232
|
+
if (!this.blacklistAdapterLists.includes(device.Path)) {
|
|
1233
|
+
await this.theLists(device);
|
|
1278
1234
|
}
|
|
1279
1235
|
}
|
|
1280
1236
|
}
|
|
@@ -1282,6 +1238,67 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1282
1238
|
await this.countDevices();
|
|
1283
1239
|
}
|
|
1284
1240
|
|
|
1241
|
+
/**
|
|
1242
|
+
* fill the lists for user
|
|
1243
|
+
* @param {object} device
|
|
1244
|
+
*/
|
|
1245
|
+
async theLists(device) {
|
|
1246
|
+
// List with all devices
|
|
1247
|
+
this.listAllDevices.push({
|
|
1248
|
+
Device: device.Device,
|
|
1249
|
+
Adapter: device.Adapter,
|
|
1250
|
+
Battery: device.Battery,
|
|
1251
|
+
'Signal strength': device.SignalStrength,
|
|
1252
|
+
'Last contact': device.LastContact,
|
|
1253
|
+
Status: device.Status,
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
// LinkQuality lists
|
|
1257
|
+
if (device.SignalStrength != ' - ') {
|
|
1258
|
+
this.linkQualityDevices.push({
|
|
1259
|
+
Device: device.Device,
|
|
1260
|
+
Adapter: device.Adapter,
|
|
1261
|
+
'Signal strength': device.SignalStrength,
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// Battery lists
|
|
1266
|
+
if (device['isBatteryDevice']) {
|
|
1267
|
+
this.batteryPowered.push({
|
|
1268
|
+
Device: device.Device,
|
|
1269
|
+
Adapter: device.Adapter,
|
|
1270
|
+
Battery: device.Battery,
|
|
1271
|
+
Status: device.Status,
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// Low Bat lists
|
|
1276
|
+
if (device.LowBat && device.Status !== 'Offline') {
|
|
1277
|
+
this.batteryLowPowered.push({
|
|
1278
|
+
Device: device.Device,
|
|
1279
|
+
Adapter: device.Adapter,
|
|
1280
|
+
Battery: device.Battery,
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// Offline List
|
|
1285
|
+
if (device.Status === 'Offline') {
|
|
1286
|
+
this.offlineDevices.push({
|
|
1287
|
+
Device: device.Device,
|
|
1288
|
+
Adapter: device.Adapter,
|
|
1289
|
+
'Last contact': device.LastContact,
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// Device update List
|
|
1294
|
+
if (device.Upgradable) {
|
|
1295
|
+
this.upgradableList.push({
|
|
1296
|
+
Device: device.Device,
|
|
1297
|
+
Adapter: device.Adapter,
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1285
1302
|
/**
|
|
1286
1303
|
* Count devices for each type
|
|
1287
1304
|
*/
|
|
@@ -1303,11 +1320,6 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1303
1320
|
|
|
1304
1321
|
// Count how many devices has update available
|
|
1305
1322
|
this.upgradableDevicesCount = this.upgradableList.length;
|
|
1306
|
-
|
|
1307
|
-
// raws
|
|
1308
|
-
|
|
1309
|
-
// Count how many devcies are offline
|
|
1310
|
-
this.offlineDevicesCountRaw = this.offlineDevicesRaw.length;
|
|
1311
1323
|
}
|
|
1312
1324
|
|
|
1313
1325
|
/**
|
|
@@ -1322,10 +1334,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1322
1334
|
if (device.adapterID.includes(adptName)) {
|
|
1323
1335
|
// list device only if selected adapter matched with device
|
|
1324
1336
|
await this.createLists(adptName);
|
|
1325
|
-
await this.writeDatapoints(adptName);
|
|
1326
1337
|
}
|
|
1327
1338
|
}
|
|
1328
|
-
|
|
1329
1339
|
await this.writeDatapoints(adptName); // fill the datapoints
|
|
1330
1340
|
} catch (error) {
|
|
1331
1341
|
this.errorReporting('[createDataForEachAdapter]', error);
|
|
@@ -1773,18 +1783,21 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1773
1783
|
dpSubFolder = '';
|
|
1774
1784
|
}
|
|
1775
1785
|
|
|
1786
|
+
// Write Datapoints for counts
|
|
1776
1787
|
await this.setStateAsync(`${dpSubFolder}offlineCount`, { val: this.offlineDevicesCount, ack: true });
|
|
1777
1788
|
await this.setStateAsync(`${dpSubFolder}countAll`, { val: this.deviceCounter, ack: true });
|
|
1778
1789
|
await this.setStateAsync(`${dpSubFolder}batteryCount`, { val: this.batteryPoweredCount, ack: true });
|
|
1779
1790
|
await this.setStateAsync(`${dpSubFolder}lowBatteryCount`, { val: this.lowBatteryPoweredCount, ack: true });
|
|
1780
1791
|
await this.setStateAsync(`${dpSubFolder}upgradableCount`, { val: this.upgradableDevicesCount, ack: true });
|
|
1781
1792
|
|
|
1793
|
+
// List all devices
|
|
1782
1794
|
if (this.deviceCounter === 0) {
|
|
1783
1795
|
// if no device is count, write the JSON List with default value
|
|
1784
1796
|
this.listAllDevices = [{ Device: '--none--', Adapter: '', Battery: '', 'Last contact': '', 'Signal strength': '' }];
|
|
1785
1797
|
}
|
|
1786
1798
|
await this.setStateAsync(`${dpSubFolder}listAll`, { val: JSON.stringify(this.listAllDevices), ack: true });
|
|
1787
1799
|
|
|
1800
|
+
// List link quality
|
|
1788
1801
|
if (this.linkQualityCount === 0) {
|
|
1789
1802
|
// if no device is count, write the JSON List with default value
|
|
1790
1803
|
this.linkQualityDevices = [{ Device: '--none--', Adapter: '', 'Signal strength': '' }];
|
|
@@ -1795,6 +1808,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1795
1808
|
ack: true,
|
|
1796
1809
|
});
|
|
1797
1810
|
|
|
1811
|
+
// List offline devices
|
|
1798
1812
|
if (this.offlineDevicesCount === 0) {
|
|
1799
1813
|
// if no device is count, write the JSON List with default value
|
|
1800
1814
|
this.offlineDevices = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
|
|
@@ -1805,6 +1819,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1805
1819
|
ack: true,
|
|
1806
1820
|
});
|
|
1807
1821
|
|
|
1822
|
+
// List updatable
|
|
1808
1823
|
if (this.upgradableDevicesCount === 0) {
|
|
1809
1824
|
// if no device is count, write the JSON List with default value
|
|
1810
1825
|
this.upgradableList = [{ Device: '--none--', Adapter: '', 'Last contact': '' }];
|
|
@@ -1815,6 +1830,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1815
1830
|
ack: true,
|
|
1816
1831
|
});
|
|
1817
1832
|
|
|
1833
|
+
// List battery powered
|
|
1818
1834
|
if (this.batteryPoweredCount === 0) {
|
|
1819
1835
|
// if no device is count, write the JSON List with default value
|
|
1820
1836
|
this.batteryPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
|
|
@@ -1825,6 +1841,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1825
1841
|
ack: true,
|
|
1826
1842
|
});
|
|
1827
1843
|
|
|
1844
|
+
// list battery low powered
|
|
1828
1845
|
if (this.lowBatteryPoweredCount === 0) {
|
|
1829
1846
|
// if no device is count, write the JSON List with default value
|
|
1830
1847
|
this.batteryLowPowered = [{ Device: '--none--', Adapter: '', Battery: '' }];
|
|
@@ -1835,8 +1852,45 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1835
1852
|
ack: true,
|
|
1836
1853
|
});
|
|
1837
1854
|
|
|
1855
|
+
// set booleans datapoints
|
|
1856
|
+
if (this.offlineDevicesCount === 0) {
|
|
1857
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceOffline`, {
|
|
1858
|
+
val: false,
|
|
1859
|
+
ack: true,
|
|
1860
|
+
});
|
|
1861
|
+
} else {
|
|
1862
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceOffline`, {
|
|
1863
|
+
val: true,
|
|
1864
|
+
ack: true,
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
if (this.lowBatteryPoweredCount === 0) {
|
|
1869
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceLowBat`, {
|
|
1870
|
+
val: false,
|
|
1871
|
+
ack: true,
|
|
1872
|
+
});
|
|
1873
|
+
} else {
|
|
1874
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceLowBat`, {
|
|
1875
|
+
val: true,
|
|
1876
|
+
ack: true,
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
if (this.upgradableDevicesCount === 0) {
|
|
1881
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceUpdatable`, {
|
|
1882
|
+
val: false,
|
|
1883
|
+
ack: true,
|
|
1884
|
+
});
|
|
1885
|
+
} else {
|
|
1886
|
+
await this.setStateAsync(`${dpSubFolder}oneDeviceUpdatable`, {
|
|
1887
|
+
val: true,
|
|
1888
|
+
ack: true,
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1838
1892
|
//write HTML list
|
|
1839
|
-
if (this.
|
|
1893
|
+
if (this.createHtmlList) {
|
|
1840
1894
|
await this.setStateAsync(`${dpSubFolder}linkQualityListHTML`, {
|
|
1841
1895
|
val: await this.creatLinkQualityListHTML(this.linkQualityDevices, this.linkQualityCount),
|
|
1842
1896
|
ack: true,
|
|
@@ -1892,7 +1946,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1892
1946
|
html += `<tr>
|
|
1893
1947
|
<td><font>${device.Device}</font></td>
|
|
1894
1948
|
<td align=center><font>${device.Adapter}</font></td>
|
|
1895
|
-
<td align=right><font>${device
|
|
1949
|
+
<td align=right><font>${device['Signal strength']}</font></td>
|
|
1896
1950
|
</tr>`;
|
|
1897
1951
|
}
|
|
1898
1952
|
|
|
@@ -1928,7 +1982,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1928
1982
|
html += `<tr>
|
|
1929
1983
|
<td><font>${device.Device}</font></td>
|
|
1930
1984
|
<td align=center><font>${device.Adapter}</font></td>
|
|
1931
|
-
<td align=center><font color=orange>${device
|
|
1985
|
+
<td align=center><font color=orange>${device['Last contact']}</font></td>
|
|
1932
1986
|
</tr>`;
|
|
1933
1987
|
}
|
|
1934
1988
|
|
|
@@ -2036,6 +2090,31 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2036
2090
|
native: {},
|
|
2037
2091
|
});
|
|
2038
2092
|
|
|
2093
|
+
await this.setObjectNotExistsAsync(`${adptName}.oneDeviceOffline`, {
|
|
2094
|
+
type: 'state',
|
|
2095
|
+
common: {
|
|
2096
|
+
name: {
|
|
2097
|
+
en: 'Is one device with offline',
|
|
2098
|
+
de: 'Ist ein Gerät mit Offline',
|
|
2099
|
+
ru: 'Это одно устройство с offline',
|
|
2100
|
+
pt: 'É um dispositivo com offline',
|
|
2101
|
+
nl: 'Is een apparaat met offline',
|
|
2102
|
+
fr: 'Est un appareil avec hors ligne',
|
|
2103
|
+
it: 'È un dispositivo con offline',
|
|
2104
|
+
es: 'Es un dispositivo sin conexión',
|
|
2105
|
+
pl: 'Jest to jeden urządzenie z offlinem',
|
|
2106
|
+
uk: 'Є один пристрій з автономним',
|
|
2107
|
+
'zh-cn': '一处有线装置',
|
|
2108
|
+
},
|
|
2109
|
+
type: 'boolean',
|
|
2110
|
+
role: 'state',
|
|
2111
|
+
read: true,
|
|
2112
|
+
write: false,
|
|
2113
|
+
def: false,
|
|
2114
|
+
},
|
|
2115
|
+
native: {},
|
|
2116
|
+
});
|
|
2117
|
+
|
|
2039
2118
|
await this.setObjectNotExistsAsync(`${adptName}.listAll`, {
|
|
2040
2119
|
type: 'state',
|
|
2041
2120
|
common: {
|
|
@@ -2174,6 +2253,31 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2174
2253
|
native: {},
|
|
2175
2254
|
});
|
|
2176
2255
|
|
|
2256
|
+
await this.setObjectNotExistsAsync(`${adptName}.oneDeviceLowBat`, {
|
|
2257
|
+
type: 'state',
|
|
2258
|
+
common: {
|
|
2259
|
+
name: {
|
|
2260
|
+
en: 'Is one device with low battery',
|
|
2261
|
+
de: 'Ist ein Gerät mit niedrigem Akku',
|
|
2262
|
+
ru: 'Один прибор с низкой батареей',
|
|
2263
|
+
pt: 'É um dispositivo com bateria baixa',
|
|
2264
|
+
nl: 'Is een apparaat met lage batterijen',
|
|
2265
|
+
fr: 'Est un appareil avec batterie basse',
|
|
2266
|
+
it: 'È un dispositivo con batteria bassa',
|
|
2267
|
+
es: 'Es un dispositivo con batería baja',
|
|
2268
|
+
pl: 'Jest to jeden urządzenie z niską baterią',
|
|
2269
|
+
uk: 'Є одним пристроєм з низьких акумуляторів',
|
|
2270
|
+
'zh-cn': '低电池的装置',
|
|
2271
|
+
},
|
|
2272
|
+
type: 'boolean',
|
|
2273
|
+
role: 'state',
|
|
2274
|
+
read: true,
|
|
2275
|
+
write: false,
|
|
2276
|
+
def: false,
|
|
2277
|
+
},
|
|
2278
|
+
native: {},
|
|
2279
|
+
});
|
|
2280
|
+
|
|
2177
2281
|
await this.setObjectNotExistsAsync(`${adptName}.batteryCount`, {
|
|
2178
2282
|
type: 'state',
|
|
2179
2283
|
common: {
|
|
@@ -2244,6 +2348,31 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2244
2348
|
},
|
|
2245
2349
|
native: {},
|
|
2246
2350
|
});
|
|
2351
|
+
|
|
2352
|
+
await this.setObjectNotExistsAsync(`${adptName}.oneDeviceUpdatable`, {
|
|
2353
|
+
type: 'state',
|
|
2354
|
+
common: {
|
|
2355
|
+
name: {
|
|
2356
|
+
en: 'Is one device updatable',
|
|
2357
|
+
de: 'Ist ein Gerät aufnehmbar',
|
|
2358
|
+
ru: 'Одно устройство обновляется',
|
|
2359
|
+
pt: 'É um dispositivo updatable',
|
|
2360
|
+
nl: 'Is een apparaat updat',
|
|
2361
|
+
fr: "Est-ce qu'un appareil est indéfectible",
|
|
2362
|
+
it: 'È un dispositivo updatable',
|
|
2363
|
+
es: 'Es un dispositivo actualizado',
|
|
2364
|
+
pl: 'Jest to jedno urządzenie updatable',
|
|
2365
|
+
uk: 'Є одним пристроєм',
|
|
2366
|
+
'zh-cn': '一台装置',
|
|
2367
|
+
},
|
|
2368
|
+
type: 'boolean',
|
|
2369
|
+
role: 'state',
|
|
2370
|
+
read: true,
|
|
2371
|
+
write: false,
|
|
2372
|
+
def: false,
|
|
2373
|
+
},
|
|
2374
|
+
native: {},
|
|
2375
|
+
});
|
|
2247
2376
|
}
|
|
2248
2377
|
|
|
2249
2378
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.device-watcher",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Watchdog for devices",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Christian Behrends",
|
|
@@ -33,23 +33,23 @@
|
|
|
33
33
|
"@types/chai": "^4.3.4",
|
|
34
34
|
"@types/chai-as-promised": "^7.1.5",
|
|
35
35
|
"@types/mocha": "^10.0.1",
|
|
36
|
-
"@types/node": "^18.11.
|
|
36
|
+
"@types/node": "^18.11.18",
|
|
37
37
|
"@types/node-schedule": "^2.1.0",
|
|
38
38
|
"@types/proxyquire": "^1.3.28",
|
|
39
39
|
"@types/sinon": "^10.0.13",
|
|
40
40
|
"@types/sinon-chai": "^3.2.9",
|
|
41
41
|
"chai": "^4.3.7",
|
|
42
42
|
"chai-as-promised": "^7.1.1",
|
|
43
|
-
"eslint": "^8.
|
|
43
|
+
"eslint": "^8.31.0",
|
|
44
44
|
"eslint-config-prettier": "^8.5.0",
|
|
45
45
|
"eslint-plugin-prettier": "^4.2.1",
|
|
46
|
-
"mocha": "^10.
|
|
46
|
+
"mocha": "^10.2.0",
|
|
47
47
|
"node-schedule": "^2.1.0",
|
|
48
|
-
"prettier": "^2.8.
|
|
48
|
+
"prettier": "^2.8.1",
|
|
49
49
|
"proxyquire": "^2.1.3",
|
|
50
|
-
"sinon": "^15.0.
|
|
50
|
+
"sinon": "^15.0.1",
|
|
51
51
|
"sinon-chai": "^3.7.0",
|
|
52
|
-
"typescript": "~4.9.
|
|
52
|
+
"typescript": "~4.9.4"
|
|
53
53
|
},
|
|
54
54
|
"main": "main.js",
|
|
55
55
|
"files": [
|