iobroker.device-watcher 2.13.1 → 2.14.5
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 +26 -2
- package/admin/jsonConfig.json5 +1537 -2869
- package/io-package.json +525 -213
- package/lib/{arrApart.js → adapterArray.js} +195 -67
- package/lib/crud.js +1985 -1932
- package/lib/tools.js +158 -155
- package/lib/translations.js +26 -0
- package/main.js +384 -438
- package/package.json +13 -13
package/lib/tools.js
CHANGED
|
@@ -1,155 +1,158 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* when was last contact of device
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
1
|
+
const adapterArray = require('./adapterArray');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param adaptr
|
|
6
|
+
* @param unreachDP
|
|
7
|
+
* @param treeDP
|
|
8
|
+
*/
|
|
9
|
+
async function isDisabledDevice(adaptr, treeDP) {
|
|
10
|
+
let isDisabled = false;
|
|
11
|
+
|
|
12
|
+
const device = await adaptr.getForeignObject(treeDP);
|
|
13
|
+
|
|
14
|
+
if (device.native.deviceRemoved == true || device.common.desc.includes('disabled') || device.common.desc.includes('Deaktiviert') || device.common.desc.includes('disabled')) {
|
|
15
|
+
isDisabled = true;
|
|
16
|
+
}
|
|
17
|
+
return isDisabled;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {object} data - object
|
|
22
|
+
*/
|
|
23
|
+
function parseData(data) {
|
|
24
|
+
if (!data) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
if (typeof data === 'object') {
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
if (typeof data === 'string') {
|
|
31
|
+
return JSON.parse(data);
|
|
32
|
+
}
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param adaptr
|
|
38
|
+
* @param {object} obj - State of datapoint
|
|
39
|
+
*/
|
|
40
|
+
async function getInitValue(adaptr, obj) {
|
|
41
|
+
//state can be null or undefinded
|
|
42
|
+
const foreignState = await adaptr.getForeignStateAsync(obj);
|
|
43
|
+
if (foreignState) {
|
|
44
|
+
return foreignState.val;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} id - id which should be capitalize
|
|
50
|
+
*/
|
|
51
|
+
function capitalize(id) {
|
|
52
|
+
//make the first letter uppercase
|
|
53
|
+
return id && id[0].toUpperCase() + id.slice(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {number} dpValue - get Time of this datapoint
|
|
58
|
+
*/
|
|
59
|
+
function getTimestamp(dpValue) {
|
|
60
|
+
const time = new Date();
|
|
61
|
+
return (dpValue = Math.round((time.getTime() - dpValue) / 1000));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param adaptr
|
|
66
|
+
* @param {string} dp - get Time of this datapoint
|
|
67
|
+
* @param {number} ms - milliseconds
|
|
68
|
+
*/
|
|
69
|
+
async function getTimestampConnectionDP(adaptr, dp, ms) {
|
|
70
|
+
const time = new Date();
|
|
71
|
+
const dpValue = await adaptr.getForeignStateAsync(dp);
|
|
72
|
+
if (dpValue) {
|
|
73
|
+
if (!dpValue.val) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const dpLastStateChange = Math.round(time.getTime() - dpValue.lc); // calculate in ms
|
|
78
|
+
if (dpLastStateChange >= ms) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Count devices for each type
|
|
87
|
+
*
|
|
88
|
+
* @param adaptr
|
|
89
|
+
*/
|
|
90
|
+
async function countDevices(adaptr) {
|
|
91
|
+
// Count how many devices with link Quality
|
|
92
|
+
adaptr.linkQualityCount = adaptr.linkQualityDevices.length;
|
|
93
|
+
|
|
94
|
+
// Count how many devcies are offline
|
|
95
|
+
adaptr.offlineDevicesCount = adaptr.offlineDevices.length;
|
|
96
|
+
|
|
97
|
+
// Count how many devices are with battery
|
|
98
|
+
adaptr.batteryPoweredCount = adaptr.batteryPowered.length;
|
|
99
|
+
|
|
100
|
+
// 3d. Count how many devices are with low battery
|
|
101
|
+
adaptr.lowBatteryPoweredCount = adaptr.batteryLowPowered.length;
|
|
102
|
+
|
|
103
|
+
// Count how many devices are exists
|
|
104
|
+
adaptr.deviceCounter = adaptr.listAllDevices.length;
|
|
105
|
+
|
|
106
|
+
// Count how many devices has update available
|
|
107
|
+
adaptr.upgradableDevicesCount = adaptr.upgradableList.length;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* when was last contact of device
|
|
112
|
+
*
|
|
113
|
+
* @param adaptr
|
|
114
|
+
*/
|
|
115
|
+
async function checkLastContact(adaptr) {
|
|
116
|
+
for (const [deviceID, deviceData] of adaptr.listAllDevicesRaw.entries()) {
|
|
117
|
+
if (deviceData.instanceDeviceConnected !== false && deviceData.instanceDeviceConnected != undefined) {
|
|
118
|
+
deviceData.UnreachState = await this.getInitValue(adaptr, deviceData.UnreachDP);
|
|
119
|
+
|
|
120
|
+
const gefundenerAdapter = Object.values(adapterArray).find((adapter) => adapter.adapterID === deviceData.adapterID);
|
|
121
|
+
const silentEnabled = Object.values(adaptr.config.tableDevices).find((adapter) => adapter.adapterKey === gefundenerAdapter.adapterKey);
|
|
122
|
+
|
|
123
|
+
const oldContactState = deviceData.Status;
|
|
124
|
+
|
|
125
|
+
const contactData = await adaptr.getOnlineState(
|
|
126
|
+
deviceData.timeSelector,
|
|
127
|
+
deviceData.adapterID,
|
|
128
|
+
deviceData.UnreachDP,
|
|
129
|
+
deviceData.SignalStrength,
|
|
130
|
+
deviceData.UnreachState,
|
|
131
|
+
deviceData.deviceStateSelectorHMRPC,
|
|
132
|
+
deviceData.rssiPeerSelectorHMRPC,
|
|
133
|
+
);
|
|
134
|
+
if (contactData !== undefined || contactData !== null) {
|
|
135
|
+
deviceData.LastContact = contactData[0];
|
|
136
|
+
deviceData.Status = contactData[1];
|
|
137
|
+
deviceData.linkQuality = contactData[2];
|
|
138
|
+
}
|
|
139
|
+
if (adaptr.config.checkSendOfflineMsg && oldContactState !== deviceData.Status && !adaptr.blacklistNotify.includes(deviceData.Path)) {
|
|
140
|
+
// check if the generally deviceData connected state is for a while true
|
|
141
|
+
if (await this.getTimestampConnectionDP(adaptr, deviceData.instanceDeviceConnectionDP, 50000)) {
|
|
142
|
+
await adaptr.sendStateNotifications('Devices', 'onlineStateDevice', deviceID, silentEnabled.telegramSilent);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
isDisabledDevice,
|
|
151
|
+
parseData,
|
|
152
|
+
getInitValue,
|
|
153
|
+
capitalize,
|
|
154
|
+
getTimestamp,
|
|
155
|
+
getTimestampConnectionDP,
|
|
156
|
+
countDevices,
|
|
157
|
+
checkLastContact,
|
|
158
|
+
};
|
package/lib/translations.js
CHANGED
|
@@ -542,6 +542,32 @@ const translations = {
|
|
|
542
542
|
uk: 'годин',
|
|
543
543
|
'zh-cn': '小时',
|
|
544
544
|
},
|
|
545
|
+
minits: {
|
|
546
|
+
en: 'minutes',
|
|
547
|
+
de: 'Minuten',
|
|
548
|
+
ru: 'протокол',
|
|
549
|
+
pt: 'ata',
|
|
550
|
+
nl: 'minuten',
|
|
551
|
+
fr: 'minutes',
|
|
552
|
+
it: 'minuti',
|
|
553
|
+
es: 'minutos',
|
|
554
|
+
pl: 'minuty',
|
|
555
|
+
uk: 'хвилини',
|
|
556
|
+
'zh-cn': '分钟',
|
|
557
|
+
},
|
|
558
|
+
secs: {
|
|
559
|
+
en: 'seconds',
|
|
560
|
+
de: 'Sekunden',
|
|
561
|
+
ru: 'секунды',
|
|
562
|
+
pt: 'segundos',
|
|
563
|
+
nl: 'seconden',
|
|
564
|
+
fr: 'secondes',
|
|
565
|
+
it: 'secondi',
|
|
566
|
+
es: 'segundos',
|
|
567
|
+
pl: 'sekundy',
|
|
568
|
+
uk: 'секунд',
|
|
569
|
+
'zh-cn': '秒',
|
|
570
|
+
},
|
|
545
571
|
Link_quality_devices: {
|
|
546
572
|
en: 'Link quality devices',
|
|
547
573
|
de: 'Signalstärke Geräte',
|