iobroker.ebus 3.2.3 → 3.2.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/.eslintrc.json +34 -34
- package/.releaseconfig.json +3 -0
- package/LICENSE +20 -20
- package/README.md +213 -197
- package/admin/index_m.html +419 -419
- package/admin/style.css +18 -18
- package/admin/words.js +27 -27
- package/io-package.json +205 -179
- package/lib/support_tools.js +370 -370
- package/lib/tools.js +99 -99
- package/main.js +1232 -1232
- package/package.json +13 -11
- package/widgets/ebus/lib/js/flot/jquery.canvaswrapper.js +549 -549
- package/widgets/ebus/lib/js/flot/jquery.colorhelpers.js +199 -199
- package/widgets/ebus/lib/js/flot/jquery.flot.axislabels.js +212 -212
- package/widgets/ebus/lib/js/flot/jquery.flot.browser.js +98 -98
- package/widgets/ebus/lib/js/flot/jquery.flot.categories.js +202 -202
- package/widgets/ebus/lib/js/flot/jquery.flot.composeImages.js +330 -330
- package/widgets/ebus/lib/js/flot/jquery.flot.crosshair.js +202 -202
- package/widgets/ebus/lib/js/flot/jquery.flot.drawSeries.js +662 -662
- package/widgets/ebus/lib/js/flot/jquery.flot.errorbars.js +375 -375
- package/widgets/ebus/lib/js/flot/jquery.flot.fillbetween.js +254 -254
- package/widgets/ebus/lib/js/flot/jquery.flot.flatdata.js +47 -47
- package/widgets/ebus/lib/js/flot/jquery.flot.hover.js +361 -361
- package/widgets/ebus/lib/js/flot/jquery.flot.image.js +249 -249
- package/widgets/ebus/lib/js/flot/jquery.flot.js +2953 -2953
- package/widgets/ebus/lib/js/flot/jquery.flot.legend.js +437 -437
- package/widgets/ebus/lib/js/flot/jquery.flot.logaxis.js +298 -298
- package/widgets/ebus/lib/js/flot/jquery.flot.navigate.js +834 -834
- package/widgets/ebus/lib/js/flot/jquery.flot.pie.js +794 -794
- package/widgets/ebus/lib/js/flot/jquery.flot.resize.js +60 -60
- package/widgets/ebus/lib/js/flot/jquery.flot.saturated.js +43 -43
- package/widgets/ebus/lib/js/flot/jquery.flot.selection.js +527 -527
- package/widgets/ebus/lib/js/flot/jquery.flot.stack.js +220 -220
- package/widgets/ebus/lib/js/flot/jquery.flot.symbol.js +98 -98
- package/widgets/ebus/lib/js/flot/jquery.flot.threshold.js +143 -143
- package/widgets/ebus/lib/js/flot/jquery.flot.time.js +586 -586
- package/widgets/ebus/lib/js/flot/jquery.flot.touch.js +320 -320
- package/widgets/ebus/lib/js/flot/jquery.flot.touchNavigate.js +360 -360
- package/widgets/ebus/lib/js/flot/jquery.flot.uiConstants.js +10 -10
- package/widgets/ebus/lib/js/flot/jquery.js +9473 -9473
- package/widgets/ebus/lib/js/lib/globalize.culture.en-US.js +33 -33
- package/widgets/ebus/lib/js/lib/globalize.js +1601 -1601
- package/widgets/ebus/lib/js/lib/jquery.event.drag.js +145 -145
- package/widgets/ebus/lib/js/lib/jquery.mousewheel.js +86 -86
- package/widgets/ebus.html +2395 -2395
- package/readme.txt +0 -297
package/lib/support_tools.js
CHANGED
|
@@ -1,371 +1,371 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const heatingcontrolDictionary = require("./vis_words.js").heatingcontrolDictionary;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {string} timeVal
|
|
7
|
-
* @param {string} timeLimit
|
|
8
|
-
*/
|
|
9
|
-
function IsLater(adapter, timeVal, timeLimit) {
|
|
10
|
-
|
|
11
|
-
let ret = false;
|
|
12
|
-
try {
|
|
13
|
-
adapter.log.debug("check IsLater : " + timeVal + " " + timeLimit);
|
|
14
|
-
|
|
15
|
-
if (typeof timeVal === "string" && typeof timeLimit === "string") {
|
|
16
|
-
const valIn = timeVal.split(":");
|
|
17
|
-
const valLimits = timeLimit.split(":");
|
|
18
|
-
|
|
19
|
-
if (valIn.length > 1 && valLimits.length > 1) {
|
|
20
|
-
|
|
21
|
-
if (parseInt(valIn[0]) > parseInt(valLimits[0])
|
|
22
|
-
|| (parseInt(valIn[0]) == parseInt(valLimits[0]) && parseInt(valIn[1]) > parseInt(valLimits[1]))) {
|
|
23
|
-
ret = true;
|
|
24
|
-
adapter.log.debug("yes, IsLater : " + timeVal + " " + timeLimit);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
adapter.log.error("string does not contain : " + timeVal + " " + timeLimit);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
adapter.log.error("not a string " + typeof timeVal + " " + typeof timeLimit);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
adapter.log.error("exception in IsLater [" + e + "]");
|
|
37
|
-
}
|
|
38
|
-
return ret;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {string } timeVal
|
|
43
|
-
* @param {string } [timeLimit]
|
|
44
|
-
*/
|
|
45
|
-
function IsEarlier(adapter, timeVal, timeLimit) {
|
|
46
|
-
|
|
47
|
-
let ret = false;
|
|
48
|
-
try {
|
|
49
|
-
adapter.log.debug("check IsEarlier : " + timeVal + " " + timeLimit);
|
|
50
|
-
|
|
51
|
-
if (typeof timeVal === "string" && typeof timeLimit === "string") {
|
|
52
|
-
const valIn = timeVal.split(":");
|
|
53
|
-
const valLimits = timeLimit.split(":");
|
|
54
|
-
|
|
55
|
-
if (valIn.length > 1 && valLimits.length > 1) {
|
|
56
|
-
|
|
57
|
-
if (parseInt(valIn[0]) < parseInt(valLimits[0])
|
|
58
|
-
|| (parseInt(valIn[0]) == parseInt(valLimits[0]) && parseInt(valIn[1]) < parseInt(valLimits[1]))) {
|
|
59
|
-
ret = true;
|
|
60
|
-
adapter.log.debug("yes, IsEarlier : " + timeVal + " " + timeLimit);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
adapter.log.error("string does not contain : " + timeVal + " " + timeLimit);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
adapter.log.error("not a string " + typeof timeVal + " " + typeof timeLimit);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
adapter.log.error("exception in IsEarlier [" + e + "]");
|
|
73
|
-
}
|
|
74
|
-
return ret;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param {string} timeVal
|
|
79
|
-
* @param {string} timeLimit
|
|
80
|
-
*/
|
|
81
|
-
function IsEqual(adapter, timeVal, timeLimit) {
|
|
82
|
-
|
|
83
|
-
let ret = false;
|
|
84
|
-
try {
|
|
85
|
-
adapter.log.debug("check IsEqual : " + timeVal + " " + timeLimit);
|
|
86
|
-
|
|
87
|
-
if (typeof timeVal === "string" && typeof timeLimit === "string") {
|
|
88
|
-
const valIn = timeVal.split(":");
|
|
89
|
-
const valLimits = timeLimit.split(":");
|
|
90
|
-
|
|
91
|
-
if (valIn.length > 1 && valLimits.length > 1) {
|
|
92
|
-
|
|
93
|
-
if (parseInt(valIn[0]) === parseInt(valLimits[0]) && parseInt(valIn[1]) === parseInt(valLimits[1])) {
|
|
94
|
-
ret = true;
|
|
95
|
-
adapter.log.debug("yes, IsEqual : " + timeVal + " " + timeLimit);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
adapter.log.error("string does not contain : " + timeVal + " " + timeLimit);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
adapter.log.error("not a string " + typeof timeVal + " " + typeof timeLimit);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
adapter.log.error("exception in IsEqual [" + e + "]");
|
|
108
|
-
}
|
|
109
|
-
return ret;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//*******************************************************************
|
|
113
|
-
//
|
|
114
|
-
// find a object in array by key and value
|
|
115
|
-
// returns the object
|
|
116
|
-
function findObjectByKey(array, key, value) {
|
|
117
|
-
if (array !== null && typeof array !== undefined) {
|
|
118
|
-
for (let i = 0; i < array.length; i++) {
|
|
119
|
-
if (array[i][key] === value) {
|
|
120
|
-
return array[i];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
//*******************************************************************
|
|
128
|
-
//
|
|
129
|
-
// find a object in array by key and value
|
|
130
|
-
// returns the object
|
|
131
|
-
function findObjectsByKey(array, key, value) {
|
|
132
|
-
|
|
133
|
-
const ret = [];
|
|
134
|
-
|
|
135
|
-
if (array !== null && typeof array !== undefined) {
|
|
136
|
-
for (let i = 0; i < array.length; i++) {
|
|
137
|
-
if (array[i][key] === value) {
|
|
138
|
-
ret.push(array[i]);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return ret;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//*******************************************************************
|
|
147
|
-
//
|
|
148
|
-
// find a object in array by key and value
|
|
149
|
-
// returns index number
|
|
150
|
-
function findObjectIdByKey(array, key, value) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//array.filter(d => d.key == value);
|
|
154
|
-
|
|
155
|
-
if (array !== null && typeof array !== undefined) {
|
|
156
|
-
|
|
157
|
-
for (let i = 0; i < array.length; i++) {
|
|
158
|
-
if (array[i][key] === value) {
|
|
159
|
-
return i;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return -1;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
//*******************************************************************
|
|
168
|
-
//
|
|
169
|
-
// find all objects in array by key and value
|
|
170
|
-
// returns index number array
|
|
171
|
-
function findObjectsIdByKey(array, key, value) {
|
|
172
|
-
|
|
173
|
-
const ret = [];
|
|
174
|
-
|
|
175
|
-
if (array !== null && typeof array !== undefined) {
|
|
176
|
-
|
|
177
|
-
for (let i = 0; i < array.length; i++) {
|
|
178
|
-
if (array[i][key] === value) {
|
|
179
|
-
ret.push(i);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return ret;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
function timeConverter(SystemLanguage,time, timeonly = false) {
|
|
188
|
-
|
|
189
|
-
let a;
|
|
190
|
-
|
|
191
|
-
if (time != null) {
|
|
192
|
-
a = new Date(time);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
a = new Date();
|
|
196
|
-
}
|
|
197
|
-
let months;
|
|
198
|
-
|
|
199
|
-
if (SystemLanguage === "de") {
|
|
200
|
-
months = ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"];
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
204
|
-
}
|
|
205
|
-
const year = a.getFullYear();
|
|
206
|
-
const month = months[a.getMonth()];
|
|
207
|
-
let date = a.getDate();
|
|
208
|
-
date = date < 10 ? " " + date : date;
|
|
209
|
-
let hour = a.getHours();
|
|
210
|
-
hour = hour < 10 ? "0" + hour : hour;
|
|
211
|
-
let min = a.getMinutes();
|
|
212
|
-
min = min < 10 ? "0" + min : min;
|
|
213
|
-
let sec = a.getSeconds();
|
|
214
|
-
sec = sec < 10 ? "0" + sec : sec;
|
|
215
|
-
|
|
216
|
-
let sRet = "";
|
|
217
|
-
if (timeonly) {
|
|
218
|
-
sRet = hour + ":" + min + ":" + sec;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
sRet = date + " " + month + " " + year + " " + hour + ":" + min + ":" + sec;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return sRet;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function CheckValidTime(adapter, id, time) {
|
|
228
|
-
|
|
229
|
-
let sRet = "00:00";
|
|
230
|
-
try {
|
|
231
|
-
if (time === "null" || typeof time === undefined) {
|
|
232
|
-
adapter.log.error("time value not found for " + id);
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
else if (typeof time !== "string") {
|
|
236
|
-
adapter.log.error("time should be a string but is " + typeof time.val + " for " + id);
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
else if (time.length < 3) {
|
|
240
|
-
adapter.log.error("time not long enough for " + id);
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
else if (!time.includes(":")) {
|
|
244
|
-
adapter.log.error("time ':' missing for " + id);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
const times = time.split(":");
|
|
248
|
-
sRet = "0" + times[0].slice(-2) + ":" + "0" + times[1].slice(-2);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
catch (e) {
|
|
253
|
-
adapter.log.error("exception in CheckValidTime [" + e + "] for " + id + " " + JSON.stringify(time));
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
return sRet;
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
function Check4ValidTemperature(adapter, temperature) {
|
|
262
|
-
|
|
263
|
-
try {
|
|
264
|
-
|
|
265
|
-
if (typeof temperature == "object") {
|
|
266
|
-
adapter.log.warn("target temperature is object " + JSON.stringify(temperature));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (isNaN(temperature) || typeof temperature === "string") {
|
|
270
|
-
|
|
271
|
-
adapter.log.debug("try to convert " + temperature + " to a number");
|
|
272
|
-
return Number(temperature);
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
return temperature;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
catch (e) {
|
|
280
|
-
adapter.log.error("exception in Check4ValidTemperature [" + e + "]");
|
|
281
|
-
return 0;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
function IsSummerTime(adapter, sStartDate, sEndDate) {
|
|
288
|
-
|
|
289
|
-
let ret = false;
|
|
290
|
-
try {
|
|
291
|
-
|
|
292
|
-
adapter.log.debug("check in time " + sStartDate + " " + sEndDate);
|
|
293
|
-
|
|
294
|
-
if (sStartDate.length > 0 && sEndDate.length > 0) {
|
|
295
|
-
const StartPeriod = sStartDate.split(/[.,/ -]/);
|
|
296
|
-
const EndPeriod = sEndDate.split(/[.,/ -]/);
|
|
297
|
-
|
|
298
|
-
if (StartPeriod.length >= 2 && EndPeriod.length >= 2) {
|
|
299
|
-
|
|
300
|
-
const StartDate = new Date();
|
|
301
|
-
StartDate.setDate(parseInt(StartPeriod[0]));
|
|
302
|
-
StartDate.setMonth(parseInt(StartPeriod[1]) - 1);
|
|
303
|
-
adapter.log.debug("Start " + StartDate.toDateString());
|
|
304
|
-
|
|
305
|
-
const EndDate = new Date();
|
|
306
|
-
EndDate.setDate(parseInt(EndPeriod[0]));
|
|
307
|
-
EndDate.setMonth(parseInt(EndPeriod[1]) - 1);
|
|
308
|
-
adapter.log.debug("End " + EndDate.toDateString());
|
|
309
|
-
|
|
310
|
-
const now = new Date();
|
|
311
|
-
|
|
312
|
-
//bei Jahreswechsel
|
|
313
|
-
if (EndDate < StartDate) {
|
|
314
|
-
if (now > EndDate) {
|
|
315
|
-
//end already past, increase end year
|
|
316
|
-
EndDate.setFullYear(EndDate.getFullYear() + 1);
|
|
317
|
-
adapter.log.debug("corrected End " + EndDate.toDateString());
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
//else decrease Start year
|
|
321
|
-
StartDate.setFullYear(StartDate.getFullYear() - 1);
|
|
322
|
-
adapter.log.debug("corrected Start " + StartDate.toDateString());
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if (now >= StartDate && now <= EndDate) {
|
|
327
|
-
adapter.log.debug("we are in period");
|
|
328
|
-
ret = true;
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
adapter.log.debug("we are not in period, after start " + StartDate.toDateString() + " and before end " + EndDate.toDateString());
|
|
332
|
-
ret = false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
catch (e) {
|
|
338
|
-
adapter.log.error("exception catch in IsSummerTime [" + e + "] ");
|
|
339
|
-
}
|
|
340
|
-
return ret;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
function GetTranslation(adapter,text, systemLang) {
|
|
346
|
-
|
|
347
|
-
let translated = text;
|
|
348
|
-
|
|
349
|
-
if (heatingcontrolDictionary[text]) {
|
|
350
|
-
translated = heatingcontrolDictionary[text][systemLang] || heatingcontrolDictionary[text].en;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return translated;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
module.exports = {
|
|
359
|
-
IsLater,
|
|
360
|
-
IsEarlier,
|
|
361
|
-
IsEqual,
|
|
362
|
-
findObjectsIdByKey,
|
|
363
|
-
findObjectIdByKey,
|
|
364
|
-
findObjectsByKey,
|
|
365
|
-
findObjectByKey,
|
|
366
|
-
timeConverter,
|
|
367
|
-
CheckValidTime,
|
|
368
|
-
Check4ValidTemperature,
|
|
369
|
-
IsSummerTime,
|
|
370
|
-
GetTranslation
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const heatingcontrolDictionary = require("./vis_words.js").heatingcontrolDictionary;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} timeVal
|
|
7
|
+
* @param {string} timeLimit
|
|
8
|
+
*/
|
|
9
|
+
function IsLater(adapter, timeVal, timeLimit) {
|
|
10
|
+
|
|
11
|
+
let ret = false;
|
|
12
|
+
try {
|
|
13
|
+
adapter.log.debug("check IsLater : " + timeVal + " " + timeLimit);
|
|
14
|
+
|
|
15
|
+
if (typeof timeVal === "string" && typeof timeLimit === "string") {
|
|
16
|
+
const valIn = timeVal.split(":");
|
|
17
|
+
const valLimits = timeLimit.split(":");
|
|
18
|
+
|
|
19
|
+
if (valIn.length > 1 && valLimits.length > 1) {
|
|
20
|
+
|
|
21
|
+
if (parseInt(valIn[0]) > parseInt(valLimits[0])
|
|
22
|
+
|| (parseInt(valIn[0]) == parseInt(valLimits[0]) && parseInt(valIn[1]) > parseInt(valLimits[1]))) {
|
|
23
|
+
ret = true;
|
|
24
|
+
adapter.log.debug("yes, IsLater : " + timeVal + " " + timeLimit);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
adapter.log.error("string does not contain : " + timeVal + " " + timeLimit);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
adapter.log.error("not a string " + typeof timeVal + " " + typeof timeLimit);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
adapter.log.error("exception in IsLater [" + e + "]");
|
|
37
|
+
}
|
|
38
|
+
return ret;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {string } timeVal
|
|
43
|
+
* @param {string } [timeLimit]
|
|
44
|
+
*/
|
|
45
|
+
function IsEarlier(adapter, timeVal, timeLimit) {
|
|
46
|
+
|
|
47
|
+
let ret = false;
|
|
48
|
+
try {
|
|
49
|
+
adapter.log.debug("check IsEarlier : " + timeVal + " " + timeLimit);
|
|
50
|
+
|
|
51
|
+
if (typeof timeVal === "string" && typeof timeLimit === "string") {
|
|
52
|
+
const valIn = timeVal.split(":");
|
|
53
|
+
const valLimits = timeLimit.split(":");
|
|
54
|
+
|
|
55
|
+
if (valIn.length > 1 && valLimits.length > 1) {
|
|
56
|
+
|
|
57
|
+
if (parseInt(valIn[0]) < parseInt(valLimits[0])
|
|
58
|
+
|| (parseInt(valIn[0]) == parseInt(valLimits[0]) && parseInt(valIn[1]) < parseInt(valLimits[1]))) {
|
|
59
|
+
ret = true;
|
|
60
|
+
adapter.log.debug("yes, IsEarlier : " + timeVal + " " + timeLimit);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
adapter.log.error("string does not contain : " + timeVal + " " + timeLimit);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
adapter.log.error("not a string " + typeof timeVal + " " + typeof timeLimit);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
adapter.log.error("exception in IsEarlier [" + e + "]");
|
|
73
|
+
}
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} timeVal
|
|
79
|
+
* @param {string} timeLimit
|
|
80
|
+
*/
|
|
81
|
+
function IsEqual(adapter, timeVal, timeLimit) {
|
|
82
|
+
|
|
83
|
+
let ret = false;
|
|
84
|
+
try {
|
|
85
|
+
adapter.log.debug("check IsEqual : " + timeVal + " " + timeLimit);
|
|
86
|
+
|
|
87
|
+
if (typeof timeVal === "string" && typeof timeLimit === "string") {
|
|
88
|
+
const valIn = timeVal.split(":");
|
|
89
|
+
const valLimits = timeLimit.split(":");
|
|
90
|
+
|
|
91
|
+
if (valIn.length > 1 && valLimits.length > 1) {
|
|
92
|
+
|
|
93
|
+
if (parseInt(valIn[0]) === parseInt(valLimits[0]) && parseInt(valIn[1]) === parseInt(valLimits[1])) {
|
|
94
|
+
ret = true;
|
|
95
|
+
adapter.log.debug("yes, IsEqual : " + timeVal + " " + timeLimit);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
adapter.log.error("string does not contain : " + timeVal + " " + timeLimit);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
adapter.log.error("not a string " + typeof timeVal + " " + typeof timeLimit);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
adapter.log.error("exception in IsEqual [" + e + "]");
|
|
108
|
+
}
|
|
109
|
+
return ret;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//*******************************************************************
|
|
113
|
+
//
|
|
114
|
+
// find a object in array by key and value
|
|
115
|
+
// returns the object
|
|
116
|
+
function findObjectByKey(array, key, value) {
|
|
117
|
+
if (array !== null && typeof array !== undefined) {
|
|
118
|
+
for (let i = 0; i < array.length; i++) {
|
|
119
|
+
if (array[i][key] === value) {
|
|
120
|
+
return array[i];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//*******************************************************************
|
|
128
|
+
//
|
|
129
|
+
// find a object in array by key and value
|
|
130
|
+
// returns the object
|
|
131
|
+
function findObjectsByKey(array, key, value) {
|
|
132
|
+
|
|
133
|
+
const ret = [];
|
|
134
|
+
|
|
135
|
+
if (array !== null && typeof array !== undefined) {
|
|
136
|
+
for (let i = 0; i < array.length; i++) {
|
|
137
|
+
if (array[i][key] === value) {
|
|
138
|
+
ret.push(array[i]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return ret;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
//*******************************************************************
|
|
147
|
+
//
|
|
148
|
+
// find a object in array by key and value
|
|
149
|
+
// returns index number
|
|
150
|
+
function findObjectIdByKey(array, key, value) {
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
//array.filter(d => d.key == value);
|
|
154
|
+
|
|
155
|
+
if (array !== null && typeof array !== undefined) {
|
|
156
|
+
|
|
157
|
+
for (let i = 0; i < array.length; i++) {
|
|
158
|
+
if (array[i][key] === value) {
|
|
159
|
+
return i;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return -1;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
//*******************************************************************
|
|
168
|
+
//
|
|
169
|
+
// find all objects in array by key and value
|
|
170
|
+
// returns index number array
|
|
171
|
+
function findObjectsIdByKey(array, key, value) {
|
|
172
|
+
|
|
173
|
+
const ret = [];
|
|
174
|
+
|
|
175
|
+
if (array !== null && typeof array !== undefined) {
|
|
176
|
+
|
|
177
|
+
for (let i = 0; i < array.length; i++) {
|
|
178
|
+
if (array[i][key] === value) {
|
|
179
|
+
ret.push(i);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
function timeConverter(SystemLanguage,time, timeonly = false) {
|
|
188
|
+
|
|
189
|
+
let a;
|
|
190
|
+
|
|
191
|
+
if (time != null) {
|
|
192
|
+
a = new Date(time);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
a = new Date();
|
|
196
|
+
}
|
|
197
|
+
let months;
|
|
198
|
+
|
|
199
|
+
if (SystemLanguage === "de") {
|
|
200
|
+
months = ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"];
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
204
|
+
}
|
|
205
|
+
const year = a.getFullYear();
|
|
206
|
+
const month = months[a.getMonth()];
|
|
207
|
+
let date = a.getDate();
|
|
208
|
+
date = date < 10 ? " " + date : date;
|
|
209
|
+
let hour = a.getHours();
|
|
210
|
+
hour = hour < 10 ? "0" + hour : hour;
|
|
211
|
+
let min = a.getMinutes();
|
|
212
|
+
min = min < 10 ? "0" + min : min;
|
|
213
|
+
let sec = a.getSeconds();
|
|
214
|
+
sec = sec < 10 ? "0" + sec : sec;
|
|
215
|
+
|
|
216
|
+
let sRet = "";
|
|
217
|
+
if (timeonly) {
|
|
218
|
+
sRet = hour + ":" + min + ":" + sec;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
sRet = date + " " + month + " " + year + " " + hour + ":" + min + ":" + sec;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return sRet;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function CheckValidTime(adapter, id, time) {
|
|
228
|
+
|
|
229
|
+
let sRet = "00:00";
|
|
230
|
+
try {
|
|
231
|
+
if (time === "null" || typeof time === undefined) {
|
|
232
|
+
adapter.log.error("time value not found for " + id);
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
else if (typeof time !== "string") {
|
|
236
|
+
adapter.log.error("time should be a string but is " + typeof time.val + " for " + id);
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
else if (time.length < 3) {
|
|
240
|
+
adapter.log.error("time not long enough for " + id);
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
else if (!time.includes(":")) {
|
|
244
|
+
adapter.log.error("time ':' missing for " + id);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const times = time.split(":");
|
|
248
|
+
sRet = "0" + times[0].slice(-2) + ":" + "0" + times[1].slice(-2);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
catch (e) {
|
|
253
|
+
adapter.log.error("exception in CheckValidTime [" + e + "] for " + id + " " + JSON.stringify(time));
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
return sRet;
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
function Check4ValidTemperature(adapter, temperature) {
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
|
|
265
|
+
if (typeof temperature == "object") {
|
|
266
|
+
adapter.log.warn("target temperature is object " + JSON.stringify(temperature));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (isNaN(temperature) || typeof temperature === "string") {
|
|
270
|
+
|
|
271
|
+
adapter.log.debug("try to convert " + temperature + " to a number");
|
|
272
|
+
return Number(temperature);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
return temperature;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
adapter.log.error("exception in Check4ValidTemperature [" + e + "]");
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
function IsSummerTime(adapter, sStartDate, sEndDate) {
|
|
288
|
+
|
|
289
|
+
let ret = false;
|
|
290
|
+
try {
|
|
291
|
+
|
|
292
|
+
adapter.log.debug("check in time " + sStartDate + " " + sEndDate);
|
|
293
|
+
|
|
294
|
+
if (sStartDate.length > 0 && sEndDate.length > 0) {
|
|
295
|
+
const StartPeriod = sStartDate.split(/[.,/ -]/);
|
|
296
|
+
const EndPeriod = sEndDate.split(/[.,/ -]/);
|
|
297
|
+
|
|
298
|
+
if (StartPeriod.length >= 2 && EndPeriod.length >= 2) {
|
|
299
|
+
|
|
300
|
+
const StartDate = new Date();
|
|
301
|
+
StartDate.setDate(parseInt(StartPeriod[0]));
|
|
302
|
+
StartDate.setMonth(parseInt(StartPeriod[1]) - 1);
|
|
303
|
+
adapter.log.debug("Start " + StartDate.toDateString());
|
|
304
|
+
|
|
305
|
+
const EndDate = new Date();
|
|
306
|
+
EndDate.setDate(parseInt(EndPeriod[0]));
|
|
307
|
+
EndDate.setMonth(parseInt(EndPeriod[1]) - 1);
|
|
308
|
+
adapter.log.debug("End " + EndDate.toDateString());
|
|
309
|
+
|
|
310
|
+
const now = new Date();
|
|
311
|
+
|
|
312
|
+
//bei Jahreswechsel
|
|
313
|
+
if (EndDate < StartDate) {
|
|
314
|
+
if (now > EndDate) {
|
|
315
|
+
//end already past, increase end year
|
|
316
|
+
EndDate.setFullYear(EndDate.getFullYear() + 1);
|
|
317
|
+
adapter.log.debug("corrected End " + EndDate.toDateString());
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
//else decrease Start year
|
|
321
|
+
StartDate.setFullYear(StartDate.getFullYear() - 1);
|
|
322
|
+
adapter.log.debug("corrected Start " + StartDate.toDateString());
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (now >= StartDate && now <= EndDate) {
|
|
327
|
+
adapter.log.debug("we are in period");
|
|
328
|
+
ret = true;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
adapter.log.debug("we are not in period, after start " + StartDate.toDateString() + " and before end " + EndDate.toDateString());
|
|
332
|
+
ret = false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
adapter.log.error("exception catch in IsSummerTime [" + e + "] ");
|
|
339
|
+
}
|
|
340
|
+
return ret;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
function GetTranslation(adapter,text, systemLang) {
|
|
346
|
+
|
|
347
|
+
let translated = text;
|
|
348
|
+
|
|
349
|
+
if (heatingcontrolDictionary[text]) {
|
|
350
|
+
translated = heatingcontrolDictionary[text][systemLang] || heatingcontrolDictionary[text].en;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
return translated;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
module.exports = {
|
|
359
|
+
IsLater,
|
|
360
|
+
IsEarlier,
|
|
361
|
+
IsEqual,
|
|
362
|
+
findObjectsIdByKey,
|
|
363
|
+
findObjectIdByKey,
|
|
364
|
+
findObjectsByKey,
|
|
365
|
+
findObjectByKey,
|
|
366
|
+
timeConverter,
|
|
367
|
+
CheckValidTime,
|
|
368
|
+
Check4ValidTemperature,
|
|
369
|
+
IsSummerTime,
|
|
370
|
+
GetTranslation
|
|
371
371
|
};
|