iobroker.sprinklecontrol 0.2.19 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +8 -6
- package/admin/i18n/de/translations.json +13 -4
- package/admin/i18n/en/translations.json +12 -3
- package/admin/i18n/es/translations.json +13 -4
- package/admin/i18n/fr/translations.json +13 -4
- package/admin/i18n/it/translations.json +13 -4
- package/admin/i18n/nl/translations.json +13 -4
- package/admin/i18n/pl/translations.json +13 -4
- package/admin/i18n/pt/translations.json +13 -4
- package/admin/i18n/ru/translations.json +13 -4
- package/admin/i18n/uk/translations.json +13 -4
- package/admin/i18n/zh-cn/translations.json +13 -4
- package/admin/index_m.html +941 -919
- package/admin/index_m.js +807 -779
- package/admin/words.js +12 -3
- package/io-package.json +218 -174
- package/lib/evaporation.js +497 -455
- package/lib/myConfig.js +190 -266
- package/lib/sendMessageText.js +196 -162
- package/lib/tools.js +211 -148
- package/lib/valveControl.js +1414 -978
- package/main.js +1416 -1245
- package/package.json +9 -14
package/lib/tools.js
CHANGED
|
@@ -1,148 +1,211 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if(
|
|
29
|
-
if(tmp.length <
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
tmp[
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
tmp[
|
|
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
|
-
const
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* func addTime (02:12:24 + 00:15) || (807) => 02:12:39
|
|
5
|
+
*
|
|
6
|
+
* @param time1 {string|number} z.B. 02:12:24 || 807 => 02:12:39
|
|
7
|
+
* @param time2 {string|number|undefined} z.B. 02:12:24 || 807 => 02:12:39 || undef.
|
|
8
|
+
* @returns {string} z.B. mm:ss || hh:mm:ss
|
|
9
|
+
*/
|
|
10
|
+
function addTime(time1, time2){
|
|
11
|
+
const wert = string2seconds(time1) + string2seconds(time2);
|
|
12
|
+
return seconds2string(wert);
|
|
13
|
+
|
|
14
|
+
// private functions
|
|
15
|
+
function seconds2string(n){
|
|
16
|
+
n = Math.abs(n);
|
|
17
|
+
const h = Math.trunc(n / 3600);
|
|
18
|
+
const m = Math.trunc((n / 60 ) % 60);
|
|
19
|
+
const sec = Math.trunc(n % 60);
|
|
20
|
+
return (h === 0)?(`${frmt(m)}:${frmt(sec)}`):(`${frmt(h)}:${m}:${frmt(sec)}`);
|
|
21
|
+
} // end function seconds2string
|
|
22
|
+
|
|
23
|
+
function string2seconds(n) {
|
|
24
|
+
if(!n || (n === '--:--')) return 0;
|
|
25
|
+
if(Number.isInteger(n)) return n;
|
|
26
|
+
const tmp = n.split(':').reverse();
|
|
27
|
+
if(!tmp.length) tmp[0] = 0; // Sekunden
|
|
28
|
+
if(tmp.length < 2) tmp[1] = 0; // Minuten
|
|
29
|
+
if(tmp.length < 3) tmp[2] = 0; // Stunden
|
|
30
|
+
while(tmp[0] > 59) {
|
|
31
|
+
tmp[0] -= 60;
|
|
32
|
+
++tmp[1];
|
|
33
|
+
}
|
|
34
|
+
while(tmp[1] > 59) {
|
|
35
|
+
tmp[1] -= 60;
|
|
36
|
+
++tmp[2];
|
|
37
|
+
}
|
|
38
|
+
return (tmp[2] * 3600 + tmp[1] * 60 + 1 * tmp[0]);
|
|
39
|
+
} // string2seconds
|
|
40
|
+
|
|
41
|
+
function frmt(n) {
|
|
42
|
+
return n < 10 ? `0${ n }` : n;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // end - function addTime
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* func Format Time
|
|
50
|
+
* → hier wird der übergebene Zeitstempel, myDate, in das angegebene Format, timeFormat, umgewandelt.
|
|
51
|
+
* Ist myDate nicht angegeben, so wird die aktuelle Zeit verwendet.
|
|
52
|
+
*
|
|
53
|
+
* @param {Date=} myDate - wenn nicht angegeben; dann wird aktuelles Datum verwendet
|
|
54
|
+
* @returns {{dayNr: number; kW: number; day: number; dayTime: string; past: boolean}}
|
|
55
|
+
* - kW: (number) Rückgabe der KW;
|
|
56
|
+
* - dayNr: (number) Tag des Jahres (Tagesnummer)
|
|
57
|
+
* - day: (number) Wochentag
|
|
58
|
+
* - dd.mm. hh:mm: (string) Rückgabe Datum und Zeit
|
|
59
|
+
* - past: true => (boolean) Heute schon vorbei
|
|
60
|
+
*/
|
|
61
|
+
function formatTime(myDate) { // 'kW' 'dd.mm. hh:mm'
|
|
62
|
+
function zweiStellen (s) {
|
|
63
|
+
while (s.toString().length < 2) {
|
|
64
|
+
s = `0${ s }`;
|
|
65
|
+
}
|
|
66
|
+
return s;
|
|
67
|
+
}
|
|
68
|
+
const d = (myDate)? new Date(myDate):new Date();
|
|
69
|
+
const tag = zweiStellen(d.getDate());
|
|
70
|
+
const monat = zweiStellen(d.getMonth() + 1);
|
|
71
|
+
const stunde = zweiStellen(d.getHours());
|
|
72
|
+
const minute = zweiStellen(d.getMinutes());
|
|
73
|
+
const currentThursday = new Date(d.getTime() +(3-((d.getDay()+6) % 7)) * 86400000);
|
|
74
|
+
// At the beginning or end of a year the thursday could be in another year.
|
|
75
|
+
const yearOfThursday = currentThursday.getFullYear();
|
|
76
|
+
// Get first Thursday of the year
|
|
77
|
+
const firstThursday = new Date(new Date(yearOfThursday,0,4).getTime() +(3-((new Date(yearOfThursday,0,4).getDay()+6) % 7)) * 86400000);
|
|
78
|
+
|
|
79
|
+
const start = new Date(d.getFullYear(), 0, 0);
|
|
80
|
+
const diff = (+d - +start) + ((start.getTimezoneOffset() - d.getTimezoneOffset()) * 60 * 1000);
|
|
81
|
+
const oneDay = 1000 * 60 * 60 * 24;
|
|
82
|
+
const dayNr = Math.floor(diff / oneDay);
|
|
83
|
+
|
|
84
|
+
// +1 we start with week number 1
|
|
85
|
+
// +0.5 an easy and dirty way to round result (in combination with Math.floor)
|
|
86
|
+
const kW = Math.floor(1 + 0.5 + (currentThursday.getTime() - firstThursday.getTime()) / 86400000/7);
|
|
87
|
+
|
|
88
|
+
// Wochentag 0:So;1:Mo;...6:Sa
|
|
89
|
+
const day = d.getDay();
|
|
90
|
+
|
|
91
|
+
// 'dd.mm. hh:mm':
|
|
92
|
+
const dayTime = `${tag}.${monat} ${stunde}:${minute}`;
|
|
93
|
+
|
|
94
|
+
// true → Heute schon vorbei
|
|
95
|
+
const cd = new Date();
|
|
96
|
+
const cStunde = zweiStellen(cd.getHours());
|
|
97
|
+
const cMinute = zweiStellen(cd.getMinutes());
|
|
98
|
+
const past = ((stunde > cStunde) || ((stunde === cStunde) && (minute > cMinute)));
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
dayNr: dayNr,
|
|
102
|
+
kW: kW,
|
|
103
|
+
day: day,
|
|
104
|
+
dayTime: dayTime,
|
|
105
|
+
past: past
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* TREND - Zwischenwert ermitteln
|
|
111
|
+
*
|
|
112
|
+
* @param {number} a1 - Istwert a1 der Zeitachse
|
|
113
|
+
* @param {number} a2 - Istwert a2 der Zeitachse
|
|
114
|
+
* @param {number} b1 - Sollwert b1 der Wertachse
|
|
115
|
+
* @param {number} b2 - Sollwert b2 der Wertachse
|
|
116
|
+
* @param {number} sollA3 - Sollwert soll_A3 der Zeitachse
|
|
117
|
+
* @returns {number} Zwischenwert
|
|
118
|
+
*/
|
|
119
|
+
function trend (a1,a2,b1,b2,sollA3) {
|
|
120
|
+
return (sollA3-a1)*(b2-b1)/(a2-a1)+b1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Signature of the callback
|
|
124
|
+
// type CallBackFind<T> = (
|
|
125
|
+
// value: T,
|
|
126
|
+
// index?: number,
|
|
127
|
+
// collection?: T[]
|
|
128
|
+
// ) => Promise<boolean>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Async Find function
|
|
132
|
+
*
|
|
133
|
+
* You can use as follows
|
|
134
|
+
* const array = [1, 2, 3, 4];
|
|
135
|
+
* const output = await findAsync<number>(array, async (i) => {
|
|
136
|
+
* return Promise.resolve(i === 2);
|
|
137
|
+
* });
|
|
138
|
+
*
|
|
139
|
+
* @template T
|
|
140
|
+
* @param {T[]} elements
|
|
141
|
+
* @param {any} cb
|
|
142
|
+
* @returns {Promise<T | undefined>}
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
async function findAsync( elements, cb) {
|
|
146
|
+
for (const [index, element] of elements.entries()) {
|
|
147
|
+
if (await cb(element, index, elements)) {
|
|
148
|
+
return element;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// You can use as follows
|
|
156
|
+
// const array = [1, 2, 3, 4];
|
|
157
|
+
|
|
158
|
+
// const output = await findAsync<number>(array, async (i) => {
|
|
159
|
+
// return Promise.resolve(i === 2);
|
|
160
|
+
// });
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* sleep Funktion mit .cancel bzw .continues Token
|
|
165
|
+
*
|
|
166
|
+
* @param {number} ms - Zeit in Millisekunden
|
|
167
|
+
* @param {object} cancellationToken Objekt zur ansteuerung der inneren Funktion
|
|
168
|
+
* @returns {Promise <string>}
|
|
169
|
+
*/
|
|
170
|
+
function sleep(ms, cancellationToken) {
|
|
171
|
+
return new Promise((resolve) => {
|
|
172
|
+
cancellationToken.clearEntireList = function() {
|
|
173
|
+
clearTimeout(timeout);
|
|
174
|
+
resolve('clearEntireList');
|
|
175
|
+
};
|
|
176
|
+
cancellationToken.boostKill = function() {
|
|
177
|
+
clearTimeout(timeout);
|
|
178
|
+
resolve('boostKill');
|
|
179
|
+
};
|
|
180
|
+
cancellationToken.ack = function() {
|
|
181
|
+
clearTimeout(timeout);
|
|
182
|
+
resolve('ack');
|
|
183
|
+
};
|
|
184
|
+
const timeout = setTimeout(() => {
|
|
185
|
+
resolve('resolved');
|
|
186
|
+
}, ms);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// async function beginTest() {
|
|
190
|
+
// try {
|
|
191
|
+
// const token = {};
|
|
192
|
+
// const promise = sleep(5000, token);
|
|
193
|
+
// await promise;
|
|
194
|
+
// // ... test code ...
|
|
195
|
+
// // ... return whatever;
|
|
196
|
+
// }
|
|
197
|
+
// catch(error) {
|
|
198
|
+
// console.log(error.message);
|
|
199
|
+
// // If button was clicked before the 5000 ms has expired,
|
|
200
|
+
// // and no other error has been thrown,
|
|
201
|
+
// // then the log will show "sleep() cancelled".
|
|
202
|
+
// throw error; // rethrow error to keep beginTest's caller informed.
|
|
203
|
+
// }
|
|
204
|
+
|
|
205
|
+
module.exports = {
|
|
206
|
+
addTime,
|
|
207
|
+
formatTime,
|
|
208
|
+
trend,
|
|
209
|
+
findAsync,
|
|
210
|
+
sleep
|
|
211
|
+
};
|