iobroker.device-watcher 2.8.3 → 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 +5 -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 +827 -847
- package/main.js +209 -228
- 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,136 +2091,158 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2132
2091
|
}
|
|
2133
2092
|
|
|
2134
2093
|
/**
|
|
2135
|
-
* Check if instance is alive
|
|
2136
|
-
* @param {
|
|
2137
|
-
* @param {number} instanceDeactivationTime
|
|
2094
|
+
* Check if instance is alive and ok
|
|
2095
|
+
* @param {string} instanceID
|
|
2138
2096
|
*/
|
|
2139
|
-
async
|
|
2140
|
-
|
|
2141
|
-
|
|
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';
|
|
2142
2106
|
|
|
2143
|
-
await this.delay(instanceDeactivationTime);
|
|
2144
|
-
aliveState = await this.getInitValue(instanceAlivePath);
|
|
2145
2107
|
if (!aliveState) {
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
return false; // if instance is turned off
|
|
2150
|
-
} else {
|
|
2151
|
-
return true;
|
|
2152
|
-
}
|
|
2108
|
+
isAlive = false;
|
|
2109
|
+
isHealthy = false;
|
|
2110
|
+
instanceStatusString = 'Instanz deaktiviert';
|
|
2153
2111
|
} else {
|
|
2154
|
-
|
|
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
|
+
}
|
|
2155
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];
|
|
2156
2157
|
}
|
|
2157
2158
|
|
|
2158
2159
|
/**
|
|
2159
2160
|
* set status for instance
|
|
2160
2161
|
* @param {string} instanceMode
|
|
2161
2162
|
* @param {string} scheduleTime
|
|
2162
|
-
* @param {
|
|
2163
|
-
* @param {string} hostConnectedPath
|
|
2164
|
-
* @param {string} isDeviceConnctedPath
|
|
2163
|
+
* @param {any} instanceID
|
|
2165
2164
|
*/
|
|
2166
|
-
async setInstanceStatus(instanceMode, scheduleTime,
|
|
2167
|
-
|
|
2168
|
-
let
|
|
2169
|
-
let isDeviceConnected = await this.getInitValue(isDeviceConnctedPath);
|
|
2170
|
-
let instanceStatusString = 'Instance deactivated';
|
|
2171
|
-
let lastUpdate;
|
|
2172
|
-
let lastCronRun;
|
|
2173
|
-
let diff;
|
|
2174
|
-
let isAlive;
|
|
2175
|
-
let previousCronRun = null;
|
|
2165
|
+
async setInstanceStatus(instanceMode, scheduleTime, instanceID) {
|
|
2166
|
+
let instanceStatusString = 'Instanz deaktiviert';
|
|
2167
|
+
let isAlive = false;
|
|
2176
2168
|
let isHealthy = false;
|
|
2169
|
+
let scheduleIsAlive;
|
|
2170
|
+
let daemonIsAlive;
|
|
2171
|
+
let daemonIsNotAlive;
|
|
2177
2172
|
let instanceDeactivationTime = (this.config.offlineTimeInstances * 1000) / 2;
|
|
2178
2173
|
let instanceErrorTime = (this.config.errorTimeInstances * 1000) / 2;
|
|
2179
2174
|
|
|
2180
2175
|
switch (instanceMode) {
|
|
2181
2176
|
case 'schedule':
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
lastCronRun = Math.round(previousCronRun / 1000); // change distance to last run in seconds
|
|
2187
|
-
diff = lastCronRun - lastUpdate;
|
|
2188
|
-
if (diff > -300) {
|
|
2189
|
-
// if 5 minutes difference exceeded, instance is not alive
|
|
2190
|
-
isAlive = true;
|
|
2191
|
-
isHealthy = true;
|
|
2192
|
-
instanceStatusString = 'Instanz okay';
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2177
|
+
scheduleIsAlive = await this.checkScheduleisHealty(instanceID, scheduleTime);
|
|
2178
|
+
isAlive = Boolean(scheduleIsAlive[0]);
|
|
2179
|
+
isHealthy = Boolean(scheduleIsAlive[1]);
|
|
2180
|
+
instanceStatusString = String(scheduleIsAlive[2]);
|
|
2196
2181
|
break;
|
|
2197
2182
|
case 'daemon':
|
|
2198
|
-
|
|
2183
|
+
// check with time the user did define for error and deactivation
|
|
2184
|
+
if (this.userTimeInstancesList.has(instanceID)) {
|
|
2199
2185
|
// User set own setting for deactivation time
|
|
2200
|
-
instanceDeactivationTime = this.userTimeInstancesList.get(
|
|
2186
|
+
instanceDeactivationTime = this.userTimeInstancesList.get(instanceID).deactivationTime;
|
|
2201
2187
|
instanceDeactivationTime = (instanceDeactivationTime * 1000) / 2; // calculate sec to ms and divide into two
|
|
2202
2188
|
|
|
2203
2189
|
// User set own setting for error time
|
|
2204
|
-
instanceErrorTime = this.userTimeInstancesList.get(
|
|
2190
|
+
instanceErrorTime = this.userTimeInstancesList.get(instanceID).errorTime;
|
|
2205
2191
|
instanceErrorTime = (instanceErrorTime * 1000) / 2; // calculate sec to ms and divide into two
|
|
2206
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
|
+
};
|
|
2207
2211
|
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
if (isHostConnected && isDeviceConnected) {
|
|
2216
|
-
// In case of (re)start, connection may take some time. We take 3 attempts.
|
|
2217
|
-
// Attempt 1/3 - immediately
|
|
2218
|
-
isHealthy = true;
|
|
2219
|
-
instanceStatusString = 'Instanz okay';
|
|
2220
|
-
} else {
|
|
2221
|
-
// 2/3 - after x seconds
|
|
2222
|
-
await this.delay(instanceErrorTime);
|
|
2223
|
-
|
|
2224
|
-
isAlive = await this.checkIsAlive(instanceAlivePath, instanceDeactivationTime);
|
|
2225
|
-
if (!isAlive) return ['Instanz deaktiviert', false, null]; // if instance is turned off
|
|
2226
|
-
|
|
2227
|
-
isDeviceConnected = await this.getInitValue(isDeviceConnctedPath);
|
|
2228
|
-
if (isDeviceConnected === undefined) isDeviceConnected = true;
|
|
2229
|
-
|
|
2230
|
-
isHostConnected = await this.getInitValue(hostConnectedPath);
|
|
2231
|
-
|
|
2232
|
-
if (isHostConnected && isDeviceConnected) {
|
|
2233
|
-
isHealthy = true;
|
|
2234
|
-
instanceStatusString = 'Instanz okay';
|
|
2235
|
-
} else {
|
|
2236
|
-
// 3/3 - after x 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
|
|
2237
2219
|
await this.delay(instanceErrorTime);
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
} else {
|
|
2251
|
-
if (!isDeviceConnected) {
|
|
2252
|
-
instanceStatusString = 'Nicht verbunden mit Gerät oder Dienst';
|
|
2253
|
-
isHealthy = false;
|
|
2254
|
-
} else if (!isHostConnected) {
|
|
2255
|
-
instanceStatusString = 'Nicht verbunden mit Host';
|
|
2256
|
-
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();
|
|
2257
2232
|
}
|
|
2233
|
+
} else if (!daemonIsAlive[0]) {
|
|
2234
|
+
await daemonIsNotAlive();
|
|
2258
2235
|
}
|
|
2236
|
+
} else if (!daemonIsAlive[0]) {
|
|
2237
|
+
await daemonIsNotAlive();
|
|
2259
2238
|
}
|
|
2239
|
+
} else if (!daemonIsAlive[0]) {
|
|
2240
|
+
await daemonIsNotAlive();
|
|
2260
2241
|
}
|
|
2261
2242
|
break;
|
|
2262
2243
|
}
|
|
2263
2244
|
|
|
2264
|
-
return [
|
|
2245
|
+
return [isAlive, isHealthy, instanceStatusString];
|
|
2265
2246
|
}
|
|
2266
2247
|
|
|
2267
2248
|
/**
|
|
@@ -2346,54 +2327,54 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2346
2327
|
this.listErrorInstanceRaw = [];
|
|
2347
2328
|
this.listErrorInstance = [];
|
|
2348
2329
|
|
|
2349
|
-
for (const instance of this.listInstanceRaw
|
|
2330
|
+
for (const [instance, instanceData] of this.listInstanceRaw) {
|
|
2350
2331
|
// fill raw list
|
|
2351
|
-
if (
|
|
2332
|
+
if (instanceData.isAlive && !instanceData.isHealthy) {
|
|
2352
2333
|
this.listErrorInstanceRaw.push({
|
|
2353
|
-
Adapter:
|
|
2354
|
-
Instance: instance
|
|
2355
|
-
Mode:
|
|
2356
|
-
Status:
|
|
2334
|
+
Adapter: instanceData.Adapter,
|
|
2335
|
+
Instance: instance,
|
|
2336
|
+
Mode: instanceData.instanceMode,
|
|
2337
|
+
Status: instanceData.status,
|
|
2357
2338
|
});
|
|
2358
2339
|
}
|
|
2359
2340
|
|
|
2360
|
-
if (this.blacklistInstancesLists.includes(instance
|
|
2341
|
+
if (this.blacklistInstancesLists.includes(instance)) continue;
|
|
2361
2342
|
// all instances
|
|
2362
2343
|
this.listAllInstances.push({
|
|
2363
|
-
Adapter:
|
|
2364
|
-
Instance: instance
|
|
2365
|
-
Mode:
|
|
2366
|
-
Schedule:
|
|
2367
|
-
Version:
|
|
2368
|
-
Updateable:
|
|
2369
|
-
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,
|
|
2370
2351
|
});
|
|
2371
2352
|
|
|
2372
|
-
if (!
|
|
2353
|
+
if (!instanceData.isAlive) {
|
|
2373
2354
|
// list with deactivated instances
|
|
2374
2355
|
this.listDeactivatedInstances.push({
|
|
2375
|
-
Adapter:
|
|
2376
|
-
Instance: instance
|
|
2377
|
-
Status:
|
|
2356
|
+
Adapter: instanceData.Adapter,
|
|
2357
|
+
Instance: instance,
|
|
2358
|
+
Status: instanceData.status,
|
|
2378
2359
|
});
|
|
2379
2360
|
} else {
|
|
2380
2361
|
// list with active instances
|
|
2381
2362
|
this.listAllActiveInstances.push({
|
|
2382
|
-
Adapter:
|
|
2383
|
-
Instance: instance
|
|
2384
|
-
Mode:
|
|
2385
|
-
Schedule:
|
|
2386
|
-
Status:
|
|
2363
|
+
Adapter: instanceData.Adapter,
|
|
2364
|
+
Instance: instance,
|
|
2365
|
+
Mode: instanceData.instanceMode,
|
|
2366
|
+
Schedule: instanceData.schedule,
|
|
2367
|
+
Status: instanceData.status,
|
|
2387
2368
|
});
|
|
2388
2369
|
}
|
|
2389
2370
|
|
|
2390
2371
|
// list with error instances
|
|
2391
|
-
if (
|
|
2372
|
+
if (instanceData.isAlive && !instanceData.isHealthy) {
|
|
2392
2373
|
this.listErrorInstance.push({
|
|
2393
|
-
Adapter:
|
|
2394
|
-
Instance: instance
|
|
2395
|
-
Mode:
|
|
2396
|
-
Status:
|
|
2374
|
+
Adapter: instanceData.Adapter,
|
|
2375
|
+
Instance: instance,
|
|
2376
|
+
Mode: instanceData.instanceMode,
|
|
2377
|
+
Status: instanceData.status,
|
|
2397
2378
|
});
|
|
2398
2379
|
}
|
|
2399
2380
|
}
|
|
@@ -2976,12 +2957,12 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2976
2957
|
break;
|
|
2977
2958
|
case 'errorInstance':
|
|
2978
2959
|
objectData = this.listInstanceRaw.get(id);
|
|
2979
|
-
message = `Instanz Watchdog:\n${
|
|
2960
|
+
message = `Instanz Watchdog:\n${id}: ${objectData.status}`;
|
|
2980
2961
|
setMessage(message);
|
|
2981
2962
|
break;
|
|
2982
2963
|
case 'deactivatedInstance':
|
|
2983
2964
|
objectData = this.listInstanceRaw.get(id);
|
|
2984
|
-
message = `Instanz Watchdog:\n${
|
|
2965
|
+
message = `Instanz Watchdog:\n${id}: ${objectData.status}`;
|
|
2985
2966
|
setMessage(message);
|
|
2986
2967
|
break;
|
|
2987
2968
|
}
|
|
@@ -3165,8 +3146,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
3165
3146
|
list = '';
|
|
3166
3147
|
|
|
3167
3148
|
for (const id of this.listErrorInstanceRaw) {
|
|
3168
|
-
if (this.blacklistInstancesNotify.includes(id
|
|
3169
|
-
list = `${list}\n${id
|
|
3149
|
+
if (this.blacklistInstancesNotify.includes(id)) continue;
|
|
3150
|
+
list = `${list}\n${id}: ${id.Status}`;
|
|
3170
3151
|
}
|
|
3171
3152
|
if (list.length === 0) return;
|
|
3172
3153
|
message = `Tägliche Meldung über fehlerhafte Instanzen: ${list}`;
|
|
@@ -3195,8 +3176,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
3195
3176
|
list = '';
|
|
3196
3177
|
|
|
3197
3178
|
for (const id of this.listDeactivatedInstances) {
|
|
3198
|
-
if (this.blacklistInstancesNotify.includes(id
|
|
3199
|
-
list = `${list}\n${id
|
|
3179
|
+
if (this.blacklistInstancesNotify.includes(id)) continue;
|
|
3180
|
+
list = `${list}\n${id}`;
|
|
3200
3181
|
}
|
|
3201
3182
|
if (list.length === 0) return;
|
|
3202
3183
|
message = `Tägliche Meldung über deaktivierte Instanzen: ${list}`;
|