iobroker.device-watcher 2.8.2 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/admin/i18n/de/translations.json +164 -161
- package/admin/i18n/en/translations.json +5 -1
- package/admin/i18n/es/translations.json +5 -1
- package/admin/i18n/fr/translations.json +5 -1
- package/admin/i18n/it/translations.json +5 -1
- package/admin/i18n/nl/translations.json +5 -1
- package/admin/i18n/pl/translations.json +5 -1
- package/admin/i18n/pt/translations.json +5 -1
- package/admin/i18n/ru/translations.json +5 -1
- package/admin/i18n/uk/translations.json +5 -1
- package/admin/i18n/zh-cn/translations.json +5 -1
- package/admin/jsonConfig.json +35 -3
- package/io-package.json +27 -27
- package/main.js +211 -227
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -342,7 +342,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
342
342
|
} else {
|
|
343
343
|
try {
|
|
344
344
|
// The object was deleted
|
|
345
|
-
this.log.
|
|
345
|
+
this.log.debug(`object ${id} deleted`);
|
|
346
346
|
|
|
347
347
|
// delete instance data in map
|
|
348
348
|
if (this.listInstanceRaw.has(id)) {
|
|
@@ -379,9 +379,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
379
379
|
let oldStatus;
|
|
380
380
|
let isLowBatValue;
|
|
381
381
|
let instanceStatusRaw;
|
|
382
|
-
let oldInstanceHostState;
|
|
383
|
-
let oldInstanceDeviceState;
|
|
384
382
|
let oldAdapterUpdatesCounts;
|
|
383
|
+
let oldIsHealthyValue;
|
|
385
384
|
|
|
386
385
|
try {
|
|
387
386
|
// adapter updates
|
|
@@ -404,74 +403,33 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
// instances
|
|
407
|
-
for (const [
|
|
406
|
+
for (const [instanceID, instanceData] of this.listInstanceRaw) {
|
|
408
407
|
switch (id) {
|
|
409
|
-
|
|
410
|
-
case
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
instanceData.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
await this.sendStateNotifications('deactivatedInstance', instance);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
break;
|
|
429
|
-
// instance connected host
|
|
430
|
-
case instanceData.connectedHostPath:
|
|
431
|
-
oldInstanceHostState = instanceData.isConnectedHost;
|
|
432
|
-
instanceData.isConnectedHost = state.val;
|
|
433
|
-
if (oldInstanceHostState !== instanceData.isConnectedHost) {
|
|
434
|
-
instanceStatusRaw = await this.setInstanceStatus(
|
|
435
|
-
instanceData.instanceMode,
|
|
436
|
-
instanceData.schedule,
|
|
437
|
-
instanceData.instanceAlivePath,
|
|
438
|
-
instanceData.connectedHostPath,
|
|
439
|
-
instanceData.connectedDevicePath,
|
|
440
|
-
);
|
|
441
|
-
instanceData.isAlive = instanceStatusRaw[1];
|
|
442
|
-
instanceData.status = instanceStatusRaw[0];
|
|
443
|
-
instanceData.isHealthy = instanceStatusRaw[2];
|
|
444
|
-
|
|
445
|
-
if (!instanceData.isAlive) continue;
|
|
446
|
-
if (this.config.checkSendInstanceFailedMsg && !this.blacklistInstancesNotify.includes(instanceData.instanceAlivePath)) {
|
|
447
|
-
if (!instanceData.isHealthy) {
|
|
448
|
-
await this.sendStateNotifications('errorInstance', instance);
|
|
408
|
+
case `system.adapter.${instanceID}.alive`:
|
|
409
|
+
case `system.adapter.${instanceID}.connected`:
|
|
410
|
+
case `${instanceID}.info.connection`:
|
|
411
|
+
if (!instanceData.checkIsRunning) {
|
|
412
|
+
instanceData.checkIsRunning = true;
|
|
413
|
+
oldIsHealthyValue = instanceData.isHealthy;
|
|
414
|
+
instanceStatusRaw = await this.setInstanceStatus(instanceData.instanceMode, instanceData.schedule, instanceID);
|
|
415
|
+
instanceData.isAlive = instanceStatusRaw[0];
|
|
416
|
+
instanceData.isHealthy = instanceStatusRaw[1];
|
|
417
|
+
instanceData.status = instanceStatusRaw[2];
|
|
418
|
+
|
|
419
|
+
if (oldIsHealthyValue !== instanceData.isHealthy) {
|
|
420
|
+
if (this.config.checkSendInstanceDeactivatedMsg && !instanceData.isAlive) {
|
|
421
|
+
if (!this.blacklistInstancesNotify.includes(instanceID)) {
|
|
422
|
+
await this.sendStateNotifications('deactivatedInstance', instanceID);
|
|
423
|
+
}
|
|
449
424
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
oldInstanceDeviceState = instanceData.isConnectedDevice;
|
|
456
|
-
instanceData.isConnectedDevice = state.val;
|
|
457
|
-
if (oldInstanceDeviceState !== instanceData.isConnectedDevice) {
|
|
458
|
-
instanceStatusRaw = await this.setInstanceStatus(
|
|
459
|
-
instanceData.instanceMode,
|
|
460
|
-
instanceData.schedule,
|
|
461
|
-
instanceData.instanceAlivePath,
|
|
462
|
-
instanceData.connectedHostPath,
|
|
463
|
-
instanceData.connectedDevicePath,
|
|
464
|
-
);
|
|
465
|
-
instanceData.isAlive = instanceStatusRaw[1];
|
|
466
|
-
instanceData.status = instanceStatusRaw[0];
|
|
467
|
-
instanceData.isHealthy = instanceStatusRaw[2];
|
|
468
|
-
|
|
469
|
-
if (!instanceData.isAlive) continue;
|
|
470
|
-
if (this.config.checkSendInstanceFailedMsg && !this.blacklistInstancesNotify.includes(instanceData.instanceAlivePath)) {
|
|
471
|
-
if (!instanceData.isHealthy) {
|
|
472
|
-
await this.sendStateNotifications('errorInstance', instance);
|
|
425
|
+
|
|
426
|
+
if (this.config.checkSendInstanceFailedMsg && instanceData.isAlive && !instanceData.isHealthy) {
|
|
427
|
+
if (!this.blacklistInstancesNotify.includes(instanceID)) {
|
|
428
|
+
await this.sendStateNotifications('errorInstance', instanceID);
|
|
429
|
+
}
|
|
473
430
|
}
|
|
474
431
|
}
|
|
432
|
+
instanceData.checkIsRunning = false;
|
|
475
433
|
}
|
|
476
434
|
break;
|
|
477
435
|
}
|
|
@@ -648,12 +606,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
648
606
|
case 'instancesList':
|
|
649
607
|
if (obj.message) {
|
|
650
608
|
try {
|
|
651
|
-
for (const instanceData of this.listInstanceRaw
|
|
652
|
-
const label = `${instanceData.Adapter}: ${
|
|
609
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
610
|
+
const label = `${instanceData.Adapter}: ${instance}`;
|
|
653
611
|
const valueObjectInstances = {
|
|
654
612
|
adapter: instanceData.Adapter,
|
|
655
|
-
|
|
656
|
-
path: instanceData.instanceAlivePath,
|
|
613
|
+
instanceID: instance,
|
|
657
614
|
};
|
|
658
615
|
instances[countInstances] = { label: label, value: JSON.stringify(valueObjectInstances) };
|
|
659
616
|
countInstances++;
|
|
@@ -673,12 +630,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
673
630
|
case 'instancesListTime':
|
|
674
631
|
if (obj.message) {
|
|
675
632
|
try {
|
|
676
|
-
for (const instanceData of this.listInstanceRaw
|
|
677
|
-
const label = `${instanceData.Adapter}: ${
|
|
633
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
634
|
+
const label = `${instanceData.Adapter}: ${instance}`;
|
|
678
635
|
const valueObjectInstances = {
|
|
679
636
|
adapter: instanceData.Adapter,
|
|
680
|
-
instanceName:
|
|
681
|
-
path: instanceData.instanceAlivePath,
|
|
637
|
+
instanceName: instance,
|
|
682
638
|
};
|
|
683
639
|
instancesTime[countInstances] = { label: label, value: JSON.stringify(valueObjectInstances) };
|
|
684
640
|
countInstances++;
|
|
@@ -820,11 +776,11 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
820
776
|
const blacklistParse = this.parseData(myBlacklistInstances[i].instances);
|
|
821
777
|
// push devices in list to ignor device in lists
|
|
822
778
|
if (myBlacklistInstances[i].checkIgnorLists) {
|
|
823
|
-
this.blacklistInstancesLists.push(blacklistParse.
|
|
779
|
+
this.blacklistInstancesLists.push(blacklistParse.instanceID);
|
|
824
780
|
}
|
|
825
781
|
// push devices in list to ignor device in notifications
|
|
826
782
|
if (myBlacklistInstances[i].checkIgnorNotify) {
|
|
827
|
-
this.blacklistInstancesNotify.push(blacklistParse.
|
|
783
|
+
this.blacklistInstancesNotify.push(blacklistParse.instanceID);
|
|
828
784
|
}
|
|
829
785
|
} catch (error) {
|
|
830
786
|
this.errorReporting('[createBlacklist]', error);
|
|
@@ -847,18 +803,15 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
847
803
|
try {
|
|
848
804
|
const userTimeListparse = this.parseData(userTimeListInstances[i].instancesTime);
|
|
849
805
|
// push devices in list to ignor device in lists
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
errorTime: userTimeListInstances[i].errorTime,
|
|
855
|
-
});
|
|
856
|
-
}
|
|
806
|
+
this.userTimeInstancesList.set(userTimeListparse.instanceName, {
|
|
807
|
+
deactivationTime: userTimeListInstances[i].deactivationTime,
|
|
808
|
+
errorTime: userTimeListInstances[i].errorTime,
|
|
809
|
+
});
|
|
857
810
|
} catch (error) {
|
|
858
811
|
this.errorReporting('[createTimeListInstances]', error);
|
|
859
812
|
}
|
|
860
813
|
}
|
|
861
|
-
if (this.userTimeInstancesList.size >= 1) this.log.info(`Found instances items on lists for timesettings: ${this.
|
|
814
|
+
if (this.userTimeInstancesList.size >= 1) this.log.info(`Found instances items on lists for timesettings: ${Array.from(this.userTimeInstancesList.keys())}`);
|
|
862
815
|
}
|
|
863
816
|
}
|
|
864
817
|
|
|
@@ -2038,14 +1991,14 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2038
1991
|
if (!(typeof id === 'string' && id.startsWith(`system.adapter.`))) continue;
|
|
2039
1992
|
|
|
2040
1993
|
// get instance name
|
|
2041
|
-
const
|
|
1994
|
+
const instanceID = await this.getInstanceName(id);
|
|
2042
1995
|
|
|
2043
1996
|
// get instance connected to host data
|
|
2044
|
-
const instanceConnectedHostDP = `system.adapter.${
|
|
1997
|
+
const instanceConnectedHostDP = `system.adapter.${instanceID}.connected`;
|
|
2045
1998
|
const instanceConnectedHostVal = await this.getInitValue(instanceConnectedHostDP);
|
|
2046
1999
|
|
|
2047
2000
|
// get instance connected to device data
|
|
2048
|
-
const instanceConnectedDeviceDP = `${
|
|
2001
|
+
const instanceConnectedDeviceDP = `${instanceID}.info.connection`;
|
|
2049
2002
|
let instanceConnectedDeviceVal;
|
|
2050
2003
|
if (instanceConnectedDeviceDP !== undefined && typeof instanceConnectedDeviceDP === 'boolean') {
|
|
2051
2004
|
instanceConnectedDeviceVal = await this.getInitValue(instanceConnectedDeviceDP);
|
|
@@ -2054,7 +2007,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2054
2007
|
}
|
|
2055
2008
|
|
|
2056
2009
|
// get adapter version
|
|
2057
|
-
const instanceObjectPath = `system.adapter.${
|
|
2010
|
+
const instanceObjectPath = `system.adapter.${instanceID}`;
|
|
2058
2011
|
let adapterName;
|
|
2059
2012
|
let adapterVersion;
|
|
2060
2013
|
let adapterAvailableUpdate = '';
|
|
@@ -2082,11 +2035,20 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2082
2035
|
adapterAvailableUpdate = ' - ';
|
|
2083
2036
|
}
|
|
2084
2037
|
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2038
|
+
let isAlive;
|
|
2039
|
+
let isHealthy;
|
|
2040
|
+
let instanceStatus;
|
|
2041
|
+
if (instanceMode === 'schedule') {
|
|
2042
|
+
const instanceStatusRaw = await this.checkScheduleisHealty(instanceID, scheduleTime);
|
|
2043
|
+
isAlive = instanceStatusRaw[0];
|
|
2044
|
+
isHealthy = instanceStatusRaw[1];
|
|
2045
|
+
instanceStatus = instanceStatusRaw[2];
|
|
2046
|
+
} else if (instanceMode === 'daemon') {
|
|
2047
|
+
const instanceStatusRaw = await this.checkDaemonIsHealthy(instanceID);
|
|
2048
|
+
isAlive = instanceStatusRaw[0];
|
|
2049
|
+
isHealthy = instanceStatusRaw[1];
|
|
2050
|
+
instanceStatus = instanceStatusRaw[2];
|
|
2051
|
+
}
|
|
2090
2052
|
|
|
2091
2053
|
//subscribe to statechanges
|
|
2092
2054
|
this.subscribeForeignStates(id);
|
|
@@ -2095,22 +2057,19 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2095
2057
|
this.subscribeForeignObjects(`system.adapter.*`);
|
|
2096
2058
|
|
|
2097
2059
|
// create raw list
|
|
2098
|
-
this.listInstanceRaw.set(
|
|
2060
|
+
this.listInstanceRaw.set(instanceID, {
|
|
2099
2061
|
Adapter: adapterName,
|
|
2100
|
-
InstanceName: instanceName,
|
|
2101
2062
|
instanceObjectPath: instanceObjectPath,
|
|
2102
|
-
instanceAlivePath: id,
|
|
2103
2063
|
instanceMode: instanceMode,
|
|
2104
2064
|
schedule: scheduleTime,
|
|
2105
2065
|
adapterVersion: adapterVersion,
|
|
2106
2066
|
updateAvailable: adapterAvailableUpdate,
|
|
2107
2067
|
isAlive: isAlive,
|
|
2108
2068
|
isHealthy: isHealthy,
|
|
2109
|
-
connectedHostPath: instanceConnectedHostDP,
|
|
2110
2069
|
isConnectedHost: instanceConnectedHostVal,
|
|
2111
|
-
connectedDevicePath: instanceConnectedDeviceDP,
|
|
2112
2070
|
isConnectedDevice: instanceConnectedDeviceVal,
|
|
2113
2071
|
status: instanceStatus,
|
|
2072
|
+
checkIsRunning: false,
|
|
2114
2073
|
});
|
|
2115
2074
|
}
|
|
2116
2075
|
await this.createInstanceList();
|
|
@@ -2132,133 +2091,158 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2132
2091
|
}
|
|
2133
2092
|
|
|
2134
2093
|
/**
|
|
2135
|
-
* Check if instance is alive
|
|
2136
|
-
* @param {string
|
|
2137
|
-
* @param {any} instanceAlivePath
|
|
2138
|
-
* @param {number} instanceDeactivationTime
|
|
2094
|
+
* Check if instance is alive and ok
|
|
2095
|
+
* @param {string} instanceID
|
|
2139
2096
|
*/
|
|
2140
|
-
async
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2097
|
+
async checkDaemonIsHealthy(instanceID) {
|
|
2098
|
+
const aliveState = await this.getInitValue(`system.adapter.${instanceID}.alive`);
|
|
2099
|
+
const connectedHostState = await this.getInitValue(`system.adapter.${instanceID}.connected`);
|
|
2100
|
+
let connectedDeviceState = await this.getInitValue(`${instanceID}.info.connection`);
|
|
2101
|
+
if (connectedDeviceState === undefined) connectedDeviceState = true;
|
|
2102
|
+
|
|
2103
|
+
let isAlive = false;
|
|
2104
|
+
let isHealthy = false;
|
|
2105
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2106
|
+
|
|
2107
|
+
if (!aliveState) {
|
|
2108
|
+
isAlive = false;
|
|
2109
|
+
isHealthy = false;
|
|
2110
|
+
instanceStatusString = 'Instanz deaktiviert';
|
|
2154
2111
|
} else {
|
|
2155
|
-
|
|
2112
|
+
if (connectedHostState && connectedDeviceState) {
|
|
2113
|
+
isAlive = true;
|
|
2114
|
+
isHealthy = true;
|
|
2115
|
+
instanceStatusString = 'Instanz okay';
|
|
2116
|
+
} else if (!connectedHostState) {
|
|
2117
|
+
isAlive = true;
|
|
2118
|
+
isHealthy = false;
|
|
2119
|
+
instanceStatusString = 'Nicht verbunden mit Host';
|
|
2120
|
+
} else if (!connectedDeviceState) {
|
|
2121
|
+
isAlive = true;
|
|
2122
|
+
isHealthy = false;
|
|
2123
|
+
instanceStatusString = 'Nicht verbunden mit Gerät oder Dienst';
|
|
2124
|
+
}
|
|
2156
2125
|
}
|
|
2126
|
+
|
|
2127
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
async checkScheduleisHealty(instanceID, scheduleTime) {
|
|
2131
|
+
let lastUpdate;
|
|
2132
|
+
let previousCronRun = null;
|
|
2133
|
+
let lastCronRun;
|
|
2134
|
+
let diff;
|
|
2135
|
+
let isAlive = false;
|
|
2136
|
+
let isHealthy = false;
|
|
2137
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2138
|
+
|
|
2139
|
+
const isAliveSchedule = await this.getForeignStateAsync(`system.adapter.${instanceID}.alive`);
|
|
2140
|
+
|
|
2141
|
+
if (isAliveSchedule) {
|
|
2142
|
+
lastUpdate = Math.round((Date.now() - isAliveSchedule.lc) / 1000); // Last state change in seconds
|
|
2143
|
+
previousCronRun = this.getPreviousCronRun(scheduleTime); // When was the last cron run
|
|
2144
|
+
if (previousCronRun) {
|
|
2145
|
+
lastCronRun = Math.round(previousCronRun / 1000); // change distance to last run in seconds
|
|
2146
|
+
diff = lastCronRun - lastUpdate;
|
|
2147
|
+
if (diff > -300) {
|
|
2148
|
+
// if 5 minutes difference exceeded, instance is not alive
|
|
2149
|
+
isAlive = true;
|
|
2150
|
+
isHealthy = true;
|
|
2151
|
+
instanceStatusString = 'Instanz okay';
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2157
2157
|
}
|
|
2158
2158
|
|
|
2159
2159
|
/**
|
|
2160
2160
|
* set status for instance
|
|
2161
2161
|
* @param {string} instanceMode
|
|
2162
2162
|
* @param {string} scheduleTime
|
|
2163
|
-
* @param {
|
|
2164
|
-
* @param {string} hostConnectedPath
|
|
2165
|
-
* @param {string} isDeviceConnctedPath
|
|
2163
|
+
* @param {any} instanceID
|
|
2166
2164
|
*/
|
|
2167
|
-
async setInstanceStatus(instanceMode, scheduleTime,
|
|
2168
|
-
|
|
2169
|
-
let
|
|
2170
|
-
let isDeviceConnected = await this.getInitValue(isDeviceConnctedPath);
|
|
2171
|
-
let instanceStatusString = 'Instance deactivated';
|
|
2172
|
-
let lastUpdate;
|
|
2173
|
-
let lastCronRun;
|
|
2174
|
-
let diff;
|
|
2175
|
-
let isAlive;
|
|
2176
|
-
let previousCronRun = null;
|
|
2165
|
+
async setInstanceStatus(instanceMode, scheduleTime, instanceID) {
|
|
2166
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2167
|
+
let isAlive = false;
|
|
2177
2168
|
let isHealthy = false;
|
|
2169
|
+
let scheduleIsAlive;
|
|
2170
|
+
let daemonIsAlive;
|
|
2171
|
+
let daemonIsNotAlive;
|
|
2178
2172
|
let instanceDeactivationTime = (this.config.offlineTimeInstances * 1000) / 2;
|
|
2179
2173
|
let instanceErrorTime = (this.config.errorTimeInstances * 1000) / 2;
|
|
2180
2174
|
|
|
2181
2175
|
switch (instanceMode) {
|
|
2182
2176
|
case 'schedule':
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
lastCronRun = Math.round(previousCronRun / 1000); // change distance to last run in seconds
|
|
2188
|
-
diff = lastCronRun - lastUpdate;
|
|
2189
|
-
if (diff > -300) {
|
|
2190
|
-
// if 5 minutes difference exceeded, instance is not alive
|
|
2191
|
-
isAlive = true;
|
|
2192
|
-
isHealthy = true;
|
|
2193
|
-
instanceStatusString = 'Instanz okay';
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2177
|
+
scheduleIsAlive = await this.checkScheduleisHealty(instanceID, scheduleTime);
|
|
2178
|
+
isAlive = Boolean(scheduleIsAlive[0]);
|
|
2179
|
+
isHealthy = Boolean(scheduleIsAlive[1]);
|
|
2180
|
+
instanceStatusString = String(scheduleIsAlive[2]);
|
|
2197
2181
|
break;
|
|
2198
2182
|
case 'daemon':
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
if (this.userTimeInstancesList.has(instanceAlivePath)) {
|
|
2183
|
+
// check with time the user did define for error and deactivation
|
|
2184
|
+
if (this.userTimeInstancesList.has(instanceID)) {
|
|
2202
2185
|
// User set own setting for deactivation time
|
|
2203
|
-
instanceDeactivationTime = this.userTimeInstancesList.get(
|
|
2186
|
+
instanceDeactivationTime = this.userTimeInstancesList.get(instanceID).deactivationTime;
|
|
2204
2187
|
instanceDeactivationTime = (instanceDeactivationTime * 1000) / 2; // calculate sec to ms and divide into two
|
|
2205
2188
|
|
|
2206
2189
|
// User set own setting for error time
|
|
2207
|
-
instanceErrorTime = this.userTimeInstancesList.get(
|
|
2190
|
+
instanceErrorTime = this.userTimeInstancesList.get(instanceID).errorTime;
|
|
2208
2191
|
instanceErrorTime = (instanceErrorTime * 1000) / 2; // calculate sec to ms and divide into two
|
|
2209
2192
|
}
|
|
2193
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2194
|
+
|
|
2195
|
+
daemonIsNotAlive = async () => {
|
|
2196
|
+
// wait first time
|
|
2197
|
+
await this.delay(instanceDeactivationTime);
|
|
2198
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2199
|
+
if (!daemonIsAlive[0]) {
|
|
2200
|
+
// wait second time
|
|
2201
|
+
await this.delay(instanceDeactivationTime);
|
|
2202
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2203
|
+
if (!daemonIsAlive[0]) {
|
|
2204
|
+
// finally
|
|
2205
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2206
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2207
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2210
2211
|
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
// Attempt 1/3 - immediately
|
|
2219
|
-
isHealthy = true;
|
|
2220
|
-
instanceStatusString = 'Instanz okay';
|
|
2221
|
-
} else {
|
|
2222
|
-
// 2/3 - after 15 seconds
|
|
2223
|
-
await this.delay(instanceErrorTime);
|
|
2224
|
-
|
|
2225
|
-
isAlive = await this.checkIsAlive(isAlive, instanceAlivePath, instanceDeactivationTime);
|
|
2226
|
-
if (!isAlive) return ['Instanz deaktiviert', false, null]; // if instance is turned off
|
|
2227
|
-
|
|
2228
|
-
isDeviceConnected = await this.getInitValue(isDeviceConnctedPath);
|
|
2229
|
-
isHostConnected = await this.getInitValue(hostConnectedPath);
|
|
2230
|
-
|
|
2231
|
-
if (isHostConnected && isDeviceConnected) {
|
|
2232
|
-
isHealthy = true;
|
|
2233
|
-
instanceStatusString = 'Instanz okay';
|
|
2234
|
-
} else {
|
|
2235
|
-
// 3/3 - after 30 seconds in total or user time setting
|
|
2212
|
+
if (daemonIsAlive[0]) {
|
|
2213
|
+
if (daemonIsAlive[1]) {
|
|
2214
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2215
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2216
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2217
|
+
} else if (daemonIsAlive[0] && !daemonIsAlive[1]) {
|
|
2218
|
+
// wait first time
|
|
2236
2219
|
await this.delay(instanceErrorTime);
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
instanceStatusString = 'Nicht verbunden mit Gerät oder Dienst';
|
|
2250
|
-
isHealthy = false;
|
|
2251
|
-
} else if (!isHostConnected) {
|
|
2252
|
-
instanceStatusString = 'Nicht verbunden mit Host';
|
|
2253
|
-
isHealthy = false;
|
|
2220
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2221
|
+
if (daemonIsAlive[0] && !daemonIsAlive[1]) {
|
|
2222
|
+
// wait second time
|
|
2223
|
+
await this.delay(instanceErrorTime);
|
|
2224
|
+
daemonIsAlive = await this.checkDaemonIsHealthy(instanceID);
|
|
2225
|
+
if (daemonIsAlive[0] && !daemonIsAlive[1]) {
|
|
2226
|
+
// finally
|
|
2227
|
+
isAlive = Boolean(daemonIsAlive[0]);
|
|
2228
|
+
isHealthy = Boolean(daemonIsAlive[1]);
|
|
2229
|
+
instanceStatusString = String(daemonIsAlive[2]);
|
|
2230
|
+
} else if (!daemonIsAlive[0]) {
|
|
2231
|
+
await daemonIsNotAlive();
|
|
2254
2232
|
}
|
|
2233
|
+
} else if (!daemonIsAlive[0]) {
|
|
2234
|
+
await daemonIsNotAlive();
|
|
2255
2235
|
}
|
|
2236
|
+
} else if (!daemonIsAlive[0]) {
|
|
2237
|
+
await daemonIsNotAlive();
|
|
2256
2238
|
}
|
|
2239
|
+
} else if (!daemonIsAlive[0]) {
|
|
2240
|
+
await daemonIsNotAlive();
|
|
2257
2241
|
}
|
|
2258
2242
|
break;
|
|
2259
2243
|
}
|
|
2260
2244
|
|
|
2261
|
-
return [
|
|
2245
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2262
2246
|
}
|
|
2263
2247
|
|
|
2264
2248
|
/**
|
|
@@ -2343,54 +2327,54 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2343
2327
|
this.listErrorInstanceRaw = [];
|
|
2344
2328
|
this.listErrorInstance = [];
|
|
2345
2329
|
|
|
2346
|
-
for (const instance of this.listInstanceRaw
|
|
2330
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
2347
2331
|
// fill raw list
|
|
2348
|
-
if (
|
|
2332
|
+
if (instanceData.isAlive && !instanceData.isHealthy) {
|
|
2349
2333
|
this.listErrorInstanceRaw.push({
|
|
2350
|
-
Adapter:
|
|
2351
|
-
Instance: instance
|
|
2352
|
-
Mode:
|
|
2353
|
-
Status:
|
|
2334
|
+
Adapter: instanceData.Adapter,
|
|
2335
|
+
Instance: instance,
|
|
2336
|
+
Mode: instanceData.instanceMode,
|
|
2337
|
+
Status: instanceData.status,
|
|
2354
2338
|
});
|
|
2355
2339
|
}
|
|
2356
2340
|
|
|
2357
|
-
if (this.blacklistInstancesLists.includes(instance
|
|
2341
|
+
if (this.blacklistInstancesLists.includes(instance)) continue;
|
|
2358
2342
|
// all instances
|
|
2359
2343
|
this.listAllInstances.push({
|
|
2360
|
-
Adapter:
|
|
2361
|
-
Instance: instance
|
|
2362
|
-
Mode:
|
|
2363
|
-
Schedule:
|
|
2364
|
-
Version:
|
|
2365
|
-
Updateable:
|
|
2366
|
-
Status:
|
|
2344
|
+
Adapter: instanceData.Adapter,
|
|
2345
|
+
Instance: instance,
|
|
2346
|
+
Mode: instanceData.instanceMode,
|
|
2347
|
+
Schedule: instanceData.schedule,
|
|
2348
|
+
Version: instanceData.adapterVersion,
|
|
2349
|
+
Updateable: instanceData.updateAvailable,
|
|
2350
|
+
Status: instanceData.status,
|
|
2367
2351
|
});
|
|
2368
2352
|
|
|
2369
|
-
if (!
|
|
2353
|
+
if (!instanceData.isAlive) {
|
|
2370
2354
|
// list with deactivated instances
|
|
2371
2355
|
this.listDeactivatedInstances.push({
|
|
2372
|
-
Adapter:
|
|
2373
|
-
Instance: instance
|
|
2374
|
-
Status:
|
|
2356
|
+
Adapter: instanceData.Adapter,
|
|
2357
|
+
Instance: instance,
|
|
2358
|
+
Status: instanceData.status,
|
|
2375
2359
|
});
|
|
2376
2360
|
} else {
|
|
2377
2361
|
// list with active instances
|
|
2378
2362
|
this.listAllActiveInstances.push({
|
|
2379
|
-
Adapter:
|
|
2380
|
-
Instance: instance
|
|
2381
|
-
Mode:
|
|
2382
|
-
Schedule:
|
|
2383
|
-
Status:
|
|
2363
|
+
Adapter: instanceData.Adapter,
|
|
2364
|
+
Instance: instance,
|
|
2365
|
+
Mode: instanceData.instanceMode,
|
|
2366
|
+
Schedule: instanceData.schedule,
|
|
2367
|
+
Status: instanceData.status,
|
|
2384
2368
|
});
|
|
2385
2369
|
}
|
|
2386
2370
|
|
|
2387
2371
|
// list with error instances
|
|
2388
|
-
if (
|
|
2372
|
+
if (instanceData.isAlive && !instanceData.isHealthy) {
|
|
2389
2373
|
this.listErrorInstance.push({
|
|
2390
|
-
Adapter:
|
|
2391
|
-
Instance: instance
|
|
2392
|
-
Mode:
|
|
2393
|
-
Status:
|
|
2374
|
+
Adapter: instanceData.Adapter,
|
|
2375
|
+
Instance: instance,
|
|
2376
|
+
Mode: instanceData.instanceMode,
|
|
2377
|
+
Status: instanceData.status,
|
|
2394
2378
|
});
|
|
2395
2379
|
}
|
|
2396
2380
|
}
|
|
@@ -2973,12 +2957,12 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2973
2957
|
break;
|
|
2974
2958
|
case 'errorInstance':
|
|
2975
2959
|
objectData = this.listInstanceRaw.get(id);
|
|
2976
|
-
message = `Instanz Watchdog:\n${
|
|
2960
|
+
message = `Instanz Watchdog:\n${id}: ${objectData.status}`;
|
|
2977
2961
|
setMessage(message);
|
|
2978
2962
|
break;
|
|
2979
2963
|
case 'deactivatedInstance':
|
|
2980
2964
|
objectData = this.listInstanceRaw.get(id);
|
|
2981
|
-
message = `Instanz Watchdog:\n${
|
|
2965
|
+
message = `Instanz Watchdog:\n${id}: ${objectData.status}`;
|
|
2982
2966
|
setMessage(message);
|
|
2983
2967
|
break;
|
|
2984
2968
|
}
|
|
@@ -3162,8 +3146,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
3162
3146
|
list = '';
|
|
3163
3147
|
|
|
3164
3148
|
for (const id of this.listErrorInstanceRaw) {
|
|
3165
|
-
if (this.blacklistInstancesNotify.includes(id
|
|
3166
|
-
list = `${list}\n${id
|
|
3149
|
+
if (this.blacklistInstancesNotify.includes(id)) continue;
|
|
3150
|
+
list = `${list}\n${id}: ${id.Status}`;
|
|
3167
3151
|
}
|
|
3168
3152
|
if (list.length === 0) return;
|
|
3169
3153
|
message = `Tägliche Meldung über fehlerhafte Instanzen: ${list}`;
|
|
@@ -3192,8 +3176,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
3192
3176
|
list = '';
|
|
3193
3177
|
|
|
3194
3178
|
for (const id of this.listDeactivatedInstances) {
|
|
3195
|
-
if (this.blacklistInstancesNotify.includes(id
|
|
3196
|
-
list = `${list}\n${id
|
|
3179
|
+
if (this.blacklistInstancesNotify.includes(id)) continue;
|
|
3180
|
+
list = `${list}\n${id}`;
|
|
3197
3181
|
}
|
|
3198
3182
|
if (list.length === 0) return;
|
|
3199
3183
|
message = `Tägliche Meldung über deaktivierte Instanzen: ${list}`;
|