iobroker.device-watcher 2.9.10 → 2.9.12
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 +9 -1
- package/io-package.json +837 -859
- package/main.js +250 -216
- package/package.json +8 -8
package/main.js
CHANGED
|
@@ -374,215 +374,27 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
374
374
|
async onStateChange(id, state) {
|
|
375
375
|
if (state) {
|
|
376
376
|
// this.log.debug(`State changed: ${id} changed ${state.val}`);
|
|
377
|
-
let batteryData;
|
|
378
|
-
let signalData;
|
|
379
|
-
let oldLowBatState;
|
|
380
|
-
let contactData;
|
|
381
|
-
let oldStatus;
|
|
382
|
-
let isLowBatValue;
|
|
383
|
-
let instanceStatusRaw;
|
|
384
|
-
let oldAdapterUpdatesCounts;
|
|
385
377
|
|
|
386
378
|
try {
|
|
387
379
|
/*=============================================
|
|
388
|
-
=
|
|
380
|
+
= Instances / Adapter =
|
|
389
381
|
=============================================*/
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (this.config.checkSendAdapterUpdateMsg && this.countAdapterUpdates > oldAdapterUpdatesCounts) {
|
|
395
|
-
await this.sendStateNotifications('updateAdapter', null);
|
|
382
|
+
if (this.config.checkAdapterInstances) {
|
|
383
|
+
// Adapter Update data
|
|
384
|
+
if (id.endsWith('updatesJson')) {
|
|
385
|
+
await this.renewAdapterUpdateData(id);
|
|
396
386
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
instance.updateAvailable = adapter.newVersion;
|
|
401
|
-
}
|
|
402
|
-
} else {
|
|
403
|
-
instance.updateAvailable = ' - ';
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/*=============================================
|
|
409
|
-
= Instances =
|
|
410
|
-
=============================================*/
|
|
411
|
-
for (const [instanceID, instanceData] of this.listInstanceRaw) {
|
|
412
|
-
const checkInstance = async (instanceID, instanceData) => {
|
|
413
|
-
if (!instanceData.checkIsRunning) {
|
|
414
|
-
instanceData.checkIsRunning = true;
|
|
415
|
-
instanceStatusRaw = await this.setInstanceStatus(instanceData.instanceMode, instanceData.schedule, instanceID);
|
|
416
|
-
instanceData.isAlive = instanceStatusRaw[0];
|
|
417
|
-
instanceData.isHealthy = instanceStatusRaw[1];
|
|
418
|
-
instanceData.status = instanceStatusRaw[2];
|
|
419
|
-
instanceData.checkIsRunning = false;
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
switch (id) {
|
|
425
|
-
case `system.adapter.${instanceID}.alive`:
|
|
426
|
-
if (state.val !== instanceData.isAlive) {
|
|
427
|
-
await checkInstance(instanceID, instanceData);
|
|
428
|
-
// send message when instance was deactivated
|
|
429
|
-
if (this.config.checkSendInstanceDeactivatedMsg && !instanceData.isAlive) {
|
|
430
|
-
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
431
|
-
await this.sendStateNotifications('deactivatedInstance', instanceID);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
break;
|
|
436
|
-
case `system.adapter.${instanceID}.connected`:
|
|
437
|
-
if (state.val !== instanceData.isConnectedHost && instanceData.isAlive) {
|
|
438
|
-
await checkInstance(instanceID, instanceData);
|
|
439
|
-
// send message when instance has an error
|
|
440
|
-
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
441
|
-
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
442
|
-
await this.sendStateNotifications('errorInstance', instanceID);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
break;
|
|
446
|
-
case `${instanceID}.info.connection`:
|
|
447
|
-
if (state.val !== instanceData.isConnectedDevice && instanceData.isAlive) {
|
|
448
|
-
await checkInstance(instanceID, instanceData);
|
|
449
|
-
// send message when instance has an error
|
|
450
|
-
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
451
|
-
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
452
|
-
await this.sendStateNotifications('errorInstance', instanceID);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
break;
|
|
387
|
+
// Instanz data
|
|
388
|
+
if (Array.from(this.listInstanceRaw.values()).some((obj) => Object.values(obj).includes(id))) {
|
|
389
|
+
await this.renewInstanceData(id, state);
|
|
457
390
|
}
|
|
458
391
|
}
|
|
459
392
|
|
|
460
393
|
/*=============================================
|
|
461
394
|
= Devices =
|
|
462
395
|
=============================================*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
switch (id) {
|
|
466
|
-
// device connection
|
|
467
|
-
case deviceData.instanceDeviceConnectionDP:
|
|
468
|
-
if (state.val !== deviceData.instancedeviceConnected) {
|
|
469
|
-
deviceData.instancedeviceConnected = state.val;
|
|
470
|
-
}
|
|
471
|
-
break;
|
|
472
|
-
|
|
473
|
-
// device updates
|
|
474
|
-
case deviceData.UpdateDP:
|
|
475
|
-
if (state.val !== deviceData.Upgradable) {
|
|
476
|
-
deviceData.Upgradable = await this.checkDeviceUpdate(deviceData.adapterID, state.val);
|
|
477
|
-
if (deviceData.Upgradable === true) {
|
|
478
|
-
if (this.config.checkSendDeviceUpgrade && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
479
|
-
await this.sendStateNotifications('updateDevice', device);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
break;
|
|
484
|
-
|
|
485
|
-
// device signal
|
|
486
|
-
case deviceData.SignalStrengthDP:
|
|
487
|
-
signalData = await this.calculateSignalStrength(state, deviceData.adapterID);
|
|
488
|
-
deviceData.SignalStrength = signalData[0];
|
|
489
|
-
|
|
490
|
-
break;
|
|
491
|
-
|
|
492
|
-
// device battery
|
|
493
|
-
case deviceData.batteryDP:
|
|
494
|
-
if (deviceData.isBatteryDevice) {
|
|
495
|
-
oldLowBatState = deviceData.LowBat;
|
|
496
|
-
if (state.val === 0 && deviceData.BatteryRaw >= 5) continue;
|
|
497
|
-
batteryData = await this.getBatteryData(state.val, oldLowBatState, deviceData.faultReport, deviceData.adapterID);
|
|
498
|
-
|
|
499
|
-
deviceData.Battery = batteryData[0];
|
|
500
|
-
deviceData.BatteryRaw = batteryData[2];
|
|
501
|
-
deviceData.BatteryUnitRaw = batteryData[3];
|
|
502
|
-
if (deviceData.LowBatDP !== 'none') {
|
|
503
|
-
isLowBatValue = await this.getInitValue(deviceData.LowBatDP);
|
|
504
|
-
} else {
|
|
505
|
-
isLowBatValue = undefined;
|
|
506
|
-
}
|
|
507
|
-
deviceData.LowBat = await this.setLowbatIndicator(state.val, isLowBatValue, deviceData.faultReport, deviceData.adapterID);
|
|
508
|
-
|
|
509
|
-
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
510
|
-
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
511
|
-
await this.sendStateNotifications('lowBatDevice', device);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
break;
|
|
516
|
-
|
|
517
|
-
// device low bat
|
|
518
|
-
case deviceData.LowBatDP:
|
|
519
|
-
if (deviceData.isBatteryDevice) {
|
|
520
|
-
oldLowBatState = deviceData.LowBat;
|
|
521
|
-
batteryData = await this.getBatteryData(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
522
|
-
deviceData.Battery = batteryData[0];
|
|
523
|
-
deviceData.BatteryRaw = batteryData[2];
|
|
524
|
-
deviceData.BatteryUnitRaw = batteryData[3];
|
|
525
|
-
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
526
|
-
|
|
527
|
-
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
528
|
-
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
529
|
-
await this.sendStateNotifications('lowBatDevice', device);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
break;
|
|
534
|
-
|
|
535
|
-
//device error / fault reports
|
|
536
|
-
case deviceData.faultReportDP:
|
|
537
|
-
if (deviceData.isBatteryDevice) {
|
|
538
|
-
oldLowBatState = deviceData.LowBat;
|
|
539
|
-
batteryData = await this.getBatteryData(deviceData.BatteryRaw, oldLowBatState, state.val, deviceData.adapterID);
|
|
540
|
-
|
|
541
|
-
deviceData.Battery = batteryData[0];
|
|
542
|
-
deviceData.BatteryRaw = batteryData[2];
|
|
543
|
-
deviceData.BatteryUnitRaw = batteryData[3];
|
|
544
|
-
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, undefined, state.val, deviceData.adapterID);
|
|
545
|
-
|
|
546
|
-
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
547
|
-
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
548
|
-
await this.sendStateNotifications('lowBatDevice', device);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
break;
|
|
553
|
-
|
|
554
|
-
// device unreach
|
|
555
|
-
case deviceData.UnreachDP:
|
|
556
|
-
if (deviceData.UnreachState !== state.val) {
|
|
557
|
-
oldStatus = deviceData.Status;
|
|
558
|
-
deviceData.UnreachState = state.val;
|
|
559
|
-
contactData = await this.getOnlineState(
|
|
560
|
-
deviceData.timeSelector,
|
|
561
|
-
deviceData.adapterID,
|
|
562
|
-
deviceData.UnreachDP,
|
|
563
|
-
deviceData.SignalStrength,
|
|
564
|
-
deviceData.UnreachState,
|
|
565
|
-
deviceData.DeviceStateSelectorDP,
|
|
566
|
-
deviceData.rssiPeerSelectorDP,
|
|
567
|
-
);
|
|
568
|
-
if (contactData !== undefined) {
|
|
569
|
-
deviceData.LastContact = contactData[0];
|
|
570
|
-
deviceData.Status = contactData[1];
|
|
571
|
-
deviceData.SignalStrength = contactData[2];
|
|
572
|
-
}
|
|
573
|
-
if (this.config.checkSendOfflineMsg && oldStatus !== deviceData.Status && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
574
|
-
if (deviceData.instanceDeviceConnectionDP.val !== undefined) {
|
|
575
|
-
// check if the generally deviceData connected state is for a while true
|
|
576
|
-
if (await this.getTimestampConnectionDP(deviceData.instanceDeviceConnectionDP, 20000)) {
|
|
577
|
-
await this.sendStateNotifications('onlineStateDevice', device);
|
|
578
|
-
}
|
|
579
|
-
} else {
|
|
580
|
-
await this.sendStateNotifications('onlineStateDevice', device);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
396
|
+
if (Array.from(this.listAllDevicesRaw.values()).some((obj) => Object.values(obj).includes(id))) {
|
|
397
|
+
await this.renewDeviceData(id, state);
|
|
586
398
|
}
|
|
587
399
|
} catch (error) {
|
|
588
400
|
this.log.error(`Issue at state change: ${error}`);
|
|
@@ -864,9 +676,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
864
676
|
|
|
865
677
|
const instanceDeviceConnectionDP = `${instance}.info.connection`;
|
|
866
678
|
const instancedeviceConnected = await this.getInitValue(instanceDeviceConnectionDP);
|
|
867
|
-
this.subscribeForeignStates(instanceDeviceConnectionDP);
|
|
868
|
-
this.subscribeForeignObjects(`${this.selAdapter[i].Selektor}`);
|
|
869
|
-
|
|
679
|
+
// this.subscribeForeignStates(instanceDeviceConnectionDP);
|
|
680
|
+
//this.subscribeForeignObjects(`${this.selAdapter[i].Selektor}`);
|
|
681
|
+
this.subscribeForeignObjects('*');
|
|
870
682
|
/*=============================================
|
|
871
683
|
= Get device name =
|
|
872
684
|
=============================================*/
|
|
@@ -884,7 +696,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
884
696
|
const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
|
|
885
697
|
|
|
886
698
|
// subscribe to object device path
|
|
887
|
-
this.
|
|
699
|
+
// this.subscribeForeignStates(currDeviceString);
|
|
888
700
|
|
|
889
701
|
/*=============================================
|
|
890
702
|
= Get signal strength =
|
|
@@ -911,7 +723,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
911
723
|
break;
|
|
912
724
|
}
|
|
913
725
|
//subscribe to states
|
|
914
|
-
this.subscribeForeignStates(deviceQualityDP);
|
|
726
|
+
// this.subscribeForeignStates(deviceQualityDP);
|
|
915
727
|
|
|
916
728
|
const signalData = await this.calculateSignalStrength(deviceQualityState, adapterID);
|
|
917
729
|
let linkQuality = signalData[0];
|
|
@@ -983,9 +795,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
983
795
|
faultReportingState = await this.getInitValue(faultReportingDP);
|
|
984
796
|
|
|
985
797
|
//subscribe to states
|
|
986
|
-
this.subscribeForeignStates(deviceBatteryStateDP);
|
|
987
|
-
this.subscribeForeignStates(isLowBatDP);
|
|
988
|
-
this.subscribeForeignStates(faultReportingDP);
|
|
798
|
+
// this.subscribeForeignStates(deviceBatteryStateDP);
|
|
799
|
+
// this.subscribeForeignStates(isLowBatDP);
|
|
800
|
+
// this.subscribeForeignStates(faultReportingDP);
|
|
989
801
|
|
|
990
802
|
const batteryData = await this.getBatteryData(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
|
|
991
803
|
batteryHealth = batteryData[0];
|
|
@@ -1018,10 +830,10 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1018
830
|
}
|
|
1019
831
|
|
|
1020
832
|
// subscribe to states
|
|
1021
|
-
this.subscribeForeignStates(timeSelector);
|
|
1022
|
-
this.subscribeForeignStates(unreachDP);
|
|
1023
|
-
this.subscribeForeignStates(deviceStateSelectorDP);
|
|
1024
|
-
this.subscribeForeignStates(rssiPeerSelectorDP);
|
|
833
|
+
// this.subscribeForeignStates(timeSelector);
|
|
834
|
+
// this.subscribeForeignStates(unreachDP);
|
|
835
|
+
// this.subscribeForeignStates(deviceStateSelectorDP);
|
|
836
|
+
// this.subscribeForeignStates(rssiPeerSelectorDP);
|
|
1025
837
|
|
|
1026
838
|
const onlineState = await this.getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorDP, rssiPeerSelectorDP);
|
|
1027
839
|
let deviceState;
|
|
@@ -1059,7 +871,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1059
871
|
}
|
|
1060
872
|
|
|
1061
873
|
// subscribe to states
|
|
1062
|
-
this.subscribeForeignStates(deviceUpdateDP);
|
|
874
|
+
// this.subscribeForeignStates(deviceUpdateDP);
|
|
875
|
+
this.subscribeForeignStates('*');
|
|
1063
876
|
}
|
|
1064
877
|
|
|
1065
878
|
/*=============================================
|
|
@@ -1173,6 +986,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1173
986
|
//Get ID of foldername
|
|
1174
987
|
case 'tado':
|
|
1175
988
|
case 'wifilight':
|
|
989
|
+
case 'fullybrowserV3':
|
|
1176
990
|
deviceName = currDeviceString.slice(currDeviceString.lastIndexOf('.') + 1);
|
|
1177
991
|
break;
|
|
1178
992
|
|
|
@@ -2042,6 +1856,146 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2042
1856
|
this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
|
|
2043
1857
|
} //<--End of writing Datapoints
|
|
2044
1858
|
|
|
1859
|
+
/**
|
|
1860
|
+
* @param {string | string[]} id
|
|
1861
|
+
* @param {ioBroker.State} state
|
|
1862
|
+
*/
|
|
1863
|
+
async renewDeviceData(id, state) {
|
|
1864
|
+
let batteryData;
|
|
1865
|
+
let signalData;
|
|
1866
|
+
let oldLowBatState;
|
|
1867
|
+
let contactData;
|
|
1868
|
+
let oldStatus;
|
|
1869
|
+
let isLowBatValue;
|
|
1870
|
+
|
|
1871
|
+
const deviceID = id.slice(0, id.lastIndexOf('.') + 1 - 1);
|
|
1872
|
+
const deviceData = this.listAllDevicesRaw.get(deviceID);
|
|
1873
|
+
|
|
1874
|
+
if (deviceData) {
|
|
1875
|
+
// On statechange update available datapoint
|
|
1876
|
+
switch (id) {
|
|
1877
|
+
// device connection
|
|
1878
|
+
case deviceData.instanceDeviceConnectionDP:
|
|
1879
|
+
if (state.val !== deviceData.instancedeviceConnected) {
|
|
1880
|
+
deviceData.instancedeviceConnected = state.val;
|
|
1881
|
+
}
|
|
1882
|
+
break;
|
|
1883
|
+
|
|
1884
|
+
// device updates
|
|
1885
|
+
case deviceData.UpdateDP:
|
|
1886
|
+
if (state.val !== deviceData.Upgradable) {
|
|
1887
|
+
deviceData.Upgradable = await this.checkDeviceUpdate(deviceData.adapterID, state.val);
|
|
1888
|
+
if (deviceData.Upgradable === true) {
|
|
1889
|
+
if (this.config.checkSendDeviceUpgrade && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1890
|
+
await this.sendStateNotifications('updateDevice', deviceID);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
break;
|
|
1895
|
+
|
|
1896
|
+
// device signal
|
|
1897
|
+
case deviceData.SignalStrengthDP:
|
|
1898
|
+
signalData = await this.calculateSignalStrength(state, deviceData.adapterID);
|
|
1899
|
+
deviceData.SignalStrength = signalData[0];
|
|
1900
|
+
|
|
1901
|
+
break;
|
|
1902
|
+
|
|
1903
|
+
// device battery
|
|
1904
|
+
case deviceData.batteryDP:
|
|
1905
|
+
if (deviceData.isBatteryDevice) {
|
|
1906
|
+
oldLowBatState = deviceData.LowBat;
|
|
1907
|
+
if (state.val === 0 && deviceData.BatteryRaw >= 5) return;
|
|
1908
|
+
batteryData = await this.getBatteryData(state.val, oldLowBatState, deviceData.faultReport, deviceData.adapterID);
|
|
1909
|
+
|
|
1910
|
+
deviceData.Battery = batteryData[0];
|
|
1911
|
+
deviceData.BatteryRaw = batteryData[2];
|
|
1912
|
+
deviceData.BatteryUnitRaw = batteryData[3];
|
|
1913
|
+
if (deviceData.LowBatDP !== 'none') {
|
|
1914
|
+
isLowBatValue = await this.getInitValue(deviceData.LowBatDP);
|
|
1915
|
+
} else {
|
|
1916
|
+
isLowBatValue = undefined;
|
|
1917
|
+
}
|
|
1918
|
+
deviceData.LowBat = await this.setLowbatIndicator(state.val, isLowBatValue, deviceData.faultReport, deviceData.adapterID);
|
|
1919
|
+
|
|
1920
|
+
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
1921
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1922
|
+
await this.sendStateNotifications('lowBatDevice', deviceID);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
break;
|
|
1927
|
+
|
|
1928
|
+
// device low bat
|
|
1929
|
+
case deviceData.LowBatDP:
|
|
1930
|
+
if (deviceData.isBatteryDevice) {
|
|
1931
|
+
oldLowBatState = deviceData.LowBat;
|
|
1932
|
+
batteryData = await this.getBatteryData(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
1933
|
+
deviceData.Battery = batteryData[0];
|
|
1934
|
+
deviceData.BatteryRaw = batteryData[2];
|
|
1935
|
+
deviceData.BatteryUnitRaw = batteryData[3];
|
|
1936
|
+
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
1937
|
+
|
|
1938
|
+
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
1939
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1940
|
+
await this.sendStateNotifications('lowBatDevice', deviceID);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
break;
|
|
1945
|
+
|
|
1946
|
+
//device error / fault reports
|
|
1947
|
+
case deviceData.faultReportDP:
|
|
1948
|
+
if (deviceData.isBatteryDevice) {
|
|
1949
|
+
oldLowBatState = deviceData.LowBat;
|
|
1950
|
+
batteryData = await this.getBatteryData(deviceData.BatteryRaw, oldLowBatState, state.val, deviceData.adapterID);
|
|
1951
|
+
|
|
1952
|
+
deviceData.Battery = batteryData[0];
|
|
1953
|
+
deviceData.BatteryRaw = batteryData[2];
|
|
1954
|
+
deviceData.BatteryUnitRaw = batteryData[3];
|
|
1955
|
+
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, undefined, state.val, deviceData.adapterID);
|
|
1956
|
+
|
|
1957
|
+
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
1958
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1959
|
+
await this.sendStateNotifications('lowBatDevice', deviceID);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
break;
|
|
1964
|
+
|
|
1965
|
+
// device unreach
|
|
1966
|
+
case deviceData.UnreachDP:
|
|
1967
|
+
if (deviceData.UnreachState !== state.val) {
|
|
1968
|
+
oldStatus = deviceData.Status;
|
|
1969
|
+
deviceData.UnreachState = state.val;
|
|
1970
|
+
contactData = await this.getOnlineState(
|
|
1971
|
+
deviceData.timeSelector,
|
|
1972
|
+
deviceData.adapterID,
|
|
1973
|
+
deviceData.UnreachDP,
|
|
1974
|
+
deviceData.SignalStrength,
|
|
1975
|
+
deviceData.UnreachState,
|
|
1976
|
+
deviceData.DeviceStateSelectorDP,
|
|
1977
|
+
deviceData.rssiPeerSelectorDP,
|
|
1978
|
+
);
|
|
1979
|
+
if (contactData !== undefined) {
|
|
1980
|
+
deviceData.LastContact = contactData[0];
|
|
1981
|
+
deviceData.Status = contactData[1];
|
|
1982
|
+
deviceData.SignalStrength = contactData[2];
|
|
1983
|
+
}
|
|
1984
|
+
if (this.config.checkSendOfflineMsg && oldStatus !== deviceData.Status && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1985
|
+
if (deviceData.instanceDeviceConnectionDP.val !== undefined) {
|
|
1986
|
+
// check if the generally deviceData connected state is for a while true
|
|
1987
|
+
if (await this.getTimestampConnectionDP(deviceData.instanceDeviceConnectionDP, 20000)) {
|
|
1988
|
+
await this.sendStateNotifications('onlineStateDevice', deviceID);
|
|
1989
|
+
}
|
|
1990
|
+
} else {
|
|
1991
|
+
await this.sendStateNotifications('onlineStateDevice', deviceID);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
break;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
2045
1999
|
/**
|
|
2046
2000
|
* get all Instances at start
|
|
2047
2001
|
*/
|
|
@@ -2126,10 +2080,12 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2126
2080
|
}
|
|
2127
2081
|
|
|
2128
2082
|
//subscribe to statechanges
|
|
2129
|
-
this.subscribeForeignStates(id);
|
|
2130
|
-
this.subscribeForeignStates(instanceConnectedHostDP);
|
|
2131
|
-
this.subscribeForeignStates(instanceConnectedDeviceDP);
|
|
2132
|
-
this.
|
|
2083
|
+
// this.subscribeForeignStates(id);
|
|
2084
|
+
// this.subscribeForeignStates(instanceConnectedHostDP);
|
|
2085
|
+
// this.subscribeForeignStates(instanceConnectedDeviceDP);
|
|
2086
|
+
this.subscribeForeignStates('*');
|
|
2087
|
+
//this.subscribeForeignObjects(`system.adapter.*`);
|
|
2088
|
+
this.subscribeForeignObjects('*');
|
|
2133
2089
|
|
|
2134
2090
|
// create raw list
|
|
2135
2091
|
this.listInstanceRaw.set(instanceID, {
|
|
@@ -2145,6 +2101,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2145
2101
|
isConnectedDevice: instanceConnectedDeviceVal,
|
|
2146
2102
|
status: instanceStatus,
|
|
2147
2103
|
checkIsRunning: false,
|
|
2104
|
+
aliveDP: `system.adapter.${instanceID}.alive`,
|
|
2105
|
+
hostConnectionDP: instanceConnectedHostDP,
|
|
2106
|
+
deviceConnectionDP: instanceConnectedDeviceDP,
|
|
2148
2107
|
});
|
|
2149
2108
|
}
|
|
2150
2109
|
await this.createInstanceList();
|
|
@@ -2363,7 +2322,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2363
2322
|
const adapterUpdateListDP = `admin.*.info.updatesJson`;
|
|
2364
2323
|
|
|
2365
2324
|
// subscribe to datapoint
|
|
2366
|
-
this.subscribeForeignStates(adapterUpdateListDP);
|
|
2325
|
+
// this.subscribeForeignStates(adapterUpdateListDP);
|
|
2367
2326
|
|
|
2368
2327
|
await this.getAdapterUpdateData(adapterUpdateListDP);
|
|
2369
2328
|
|
|
@@ -2534,6 +2493,81 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2534
2493
|
await this.setStateChangedAsync(`adapterAndInstances.countInstancesError`, { val: this.countErrorInstance, ack: true });
|
|
2535
2494
|
}
|
|
2536
2495
|
|
|
2496
|
+
/**
|
|
2497
|
+
* @param {string} id
|
|
2498
|
+
*/
|
|
2499
|
+
async renewAdapterUpdateData(id) {
|
|
2500
|
+
const oldAdapterUpdatesCounts = this.countAdapterUpdates;
|
|
2501
|
+
await this.getAdapterUpdateData(id);
|
|
2502
|
+
await this.createAdapterUpdateList();
|
|
2503
|
+
if (this.config.checkSendAdapterUpdateMsg && this.countAdapterUpdates > oldAdapterUpdatesCounts) {
|
|
2504
|
+
await this.sendStateNotifications('updateAdapter', null);
|
|
2505
|
+
}
|
|
2506
|
+
this.listInstanceRaw.forEach((instance) => {
|
|
2507
|
+
const adapterUpdate = this.adapterUpdatesJsonRaw.get(instance.Adapter);
|
|
2508
|
+
instance.updateAvailable = adapterUpdate ? adapterUpdate.newVersion : ' - ';
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* call function on state change, renew data and send messages
|
|
2513
|
+
* @param {string} id
|
|
2514
|
+
* @param {ioBroker.State} state
|
|
2515
|
+
*/
|
|
2516
|
+
async renewInstanceData(id, state) {
|
|
2517
|
+
const instanceID = await this.getInstanceName(id);
|
|
2518
|
+
const instanceData = this.listInstanceRaw.get(instanceID);
|
|
2519
|
+
if (instanceData) {
|
|
2520
|
+
let instanceStatusRaw;
|
|
2521
|
+
|
|
2522
|
+
const checkInstance = async (instanceID, instanceData) => {
|
|
2523
|
+
if (!instanceData.checkIsRunning) {
|
|
2524
|
+
instanceData.checkIsRunning = true;
|
|
2525
|
+
instanceStatusRaw = await this.setInstanceStatus(instanceData.instanceMode, instanceData.schedule, instanceID);
|
|
2526
|
+
instanceData.isAlive = instanceStatusRaw[0];
|
|
2527
|
+
instanceData.isHealthy = instanceStatusRaw[1];
|
|
2528
|
+
instanceData.status = instanceStatusRaw[2];
|
|
2529
|
+
instanceData.checkIsRunning = false;
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
|
|
2534
|
+
switch (id) {
|
|
2535
|
+
case `system.adapter.${instanceID}.alive`:
|
|
2536
|
+
if (state.val !== instanceData.isAlive) {
|
|
2537
|
+
await checkInstance(instanceID, instanceData);
|
|
2538
|
+
// send message when instance was deactivated
|
|
2539
|
+
if (this.config.checkSendInstanceDeactivatedMsg && !instanceData.isAlive) {
|
|
2540
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) return;
|
|
2541
|
+
await this.sendStateNotifications('deactivatedInstance', instanceID);
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
break;
|
|
2545
|
+
|
|
2546
|
+
case `system.adapter.${instanceID}.connected`:
|
|
2547
|
+
if (state.val !== instanceData.isConnectedHost && instanceData.isAlive) {
|
|
2548
|
+
await checkInstance(instanceID, instanceData);
|
|
2549
|
+
// send message when instance has an error
|
|
2550
|
+
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
2551
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) return;
|
|
2552
|
+
await this.sendStateNotifications('errorInstance', instanceID);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
break;
|
|
2556
|
+
|
|
2557
|
+
case `${instanceID}.info.connection`:
|
|
2558
|
+
if (state.val !== instanceData.isConnectedDevice && instanceData.isAlive) {
|
|
2559
|
+
await checkInstance(instanceID, instanceData);
|
|
2560
|
+
// send message when instance has an error
|
|
2561
|
+
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
2562
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) return;
|
|
2563
|
+
await this.sendStateNotifications('errorInstance', instanceID);
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
break;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2537
2571
|
/**
|
|
2538
2572
|
* create Datapoints for Instances
|
|
2539
2573
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.device-watcher",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.12",
|
|
4
4
|
"description": "Watchdog for devices",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Christian Behrends",
|
|
@@ -37,24 +37,24 @@
|
|
|
37
37
|
"@types/chai": "^4.3.11",
|
|
38
38
|
"@types/chai-as-promised": "^7.1.8",
|
|
39
39
|
"@types/mocha": "^10.0.6",
|
|
40
|
-
"@types/node": "^20.10.
|
|
41
|
-
"@types/node-schedule": "^2.1.
|
|
40
|
+
"@types/node": "^20.10.6",
|
|
41
|
+
"@types/node-schedule": "^2.1.5",
|
|
42
42
|
"@types/proxyquire": "^1.3.31",
|
|
43
43
|
"@types/sinon": "^17.0.2",
|
|
44
44
|
"@types/sinon-chai": "^3.2.12",
|
|
45
45
|
"chai": "^4.3.10",
|
|
46
46
|
"chai-as-promised": "^7.1.1",
|
|
47
47
|
"cron-parser": "^4.9.0",
|
|
48
|
-
"eslint": "^8.
|
|
49
|
-
"eslint-config-prettier": "^9.
|
|
50
|
-
"eslint-plugin-prettier": "^5.
|
|
48
|
+
"eslint": "^8.56.0",
|
|
49
|
+
"eslint-config-prettier": "^9.1.0",
|
|
50
|
+
"eslint-plugin-prettier": "^5.1.2",
|
|
51
51
|
"mocha": "^10.2.0",
|
|
52
52
|
"node-schedule": "^2.1.1",
|
|
53
|
-
"prettier": "^3.1.
|
|
53
|
+
"prettier": "^3.1.1",
|
|
54
54
|
"proxyquire": "^2.1.3",
|
|
55
55
|
"sinon": "^17.0.1",
|
|
56
56
|
"sinon-chai": "^3.7.0",
|
|
57
|
-
"typescript": "~5.3.
|
|
57
|
+
"typescript": "~5.3.3"
|
|
58
58
|
},
|
|
59
59
|
"main": "main.js",
|
|
60
60
|
"files": [
|