iobroker.smartcontrol 2.0.1 → 2.1.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 +2 -0
- package/README.md +25 -260
- package/admin/css/LICENSE-github-markdown-css.txt +24 -0
- package/admin/css/github-markdown-dark.min.css +8 -0
- package/admin/css/github-markdown.min.css +8 -0
- package/admin/doc-md/table-trigger-motion_de.md +1 -1
- package/admin/doc-md/table-trigger-motion_en.md +1 -1
- package/admin/doc-md/table-trigger-times_de.md +1 -1
- package/admin/doc-md/table-trigger-times_en.md +1 -1
- package/admin/i18n/en/translations.json +1 -0
- package/admin/index_m.js +207 -3
- package/admin/style.css +76 -8
- package/admin/tsconfig.json +9 -13
- package/io-package.json +31 -19
- package/lib/boolean-value.js +30 -0
- package/lib/constants.js +299 -65
- package/lib/cron-schedule.js +59 -0
- package/lib/helper.js +380 -373
- package/lib/midnight-reschedule.js +31 -0
- package/lib/motion-zone-timer.js +55 -0
- package/lib/num-comparator.js +70 -0
- package/lib/tools.js +12 -6
- package/lib/trigger-class.js +527 -282
- package/main.js +943 -625
- package/package.json +33 -31
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Der interne Midnight-Job und Nutzer-Cron `0 0 * * *` feuern in derselben Sekunde.
|
|
5
|
+
* Sofortiges cancel()+scheduleJob() überspringt den heutigen 00:00-Lauf (#8).
|
|
6
|
+
* Darum erst die 00:00-Auslöser durchlaufen lassen, dann neu planen.
|
|
7
|
+
*/
|
|
8
|
+
const MIDNIGHT_RESCHEDULE_DELAY_MS = 2000;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} cron - 5-Felder (min hour …) oder 6-Felder (sec min hour …)
|
|
12
|
+
* @returns {boolean} true, wenn die Regel um 00:00 Uhr auslöst
|
|
13
|
+
*/
|
|
14
|
+
function cronFiresAtMidnight(cron) {
|
|
15
|
+
if (typeof cron !== 'string') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const parts = cron.trim().split(/\s+/);
|
|
19
|
+
if (parts.length === 5) {
|
|
20
|
+
return parts[0] === '0' && parts[1] === '0';
|
|
21
|
+
}
|
|
22
|
+
if (parts.length === 6) {
|
|
23
|
+
return parts[1] === '0' && parts[2] === '0';
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
MIDNIGHT_RESCHEDULE_DELAY_MS,
|
|
30
|
+
cronFiresAtMidnight,
|
|
31
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Aus-Timer nach Bewegung gelten pro Zone, nicht pro Melder.
|
|
5
|
+
*
|
|
6
|
+
* Warum: Zwei BWM im selben Raum dürfen nicht zwei parallele Timer starten.
|
|
7
|
+
* Sonst schaltet der zuerst abgelaufene Timer das Licht aus, obwohl der
|
|
8
|
+
* andere Melder erst später auf "keine Bewegung" gegangen ist (Issue #147).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Andere aktive Bewegungsmelder derselben Zone (ohne den aktuellen Melder).
|
|
13
|
+
*
|
|
14
|
+
* @param {Array<{active?: boolean, name?: string}>} tableTriggerMotion - Tabelle Bewegungsmelder
|
|
15
|
+
* @param {string[]|undefined|null} zoneTriggerNames - Auslöser-Namen der Zone
|
|
16
|
+
* @param {string} currentTriggerName - Melder, der gerade auslöst
|
|
17
|
+
* @returns {string[]}
|
|
18
|
+
*/
|
|
19
|
+
function getOtherMotionTriggerNames(tableTriggerMotion, zoneTriggerNames, currentTriggerName) {
|
|
20
|
+
const motionNames = [];
|
|
21
|
+
if (Array.isArray(tableTriggerMotion)) {
|
|
22
|
+
for (const row of tableTriggerMotion) {
|
|
23
|
+
// Nur aktive Melder: deaktivierte Zeilen zählen nicht zur Zone
|
|
24
|
+
if (row && row.active && row.name) {
|
|
25
|
+
motionNames.push(row.name);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const others = [];
|
|
30
|
+
if (!Array.isArray(zoneTriggerNames)) {
|
|
31
|
+
return others;
|
|
32
|
+
}
|
|
33
|
+
for (const name of zoneTriggerNames) {
|
|
34
|
+
if (motionNames.includes(name) && name !== currentTriggerName) {
|
|
35
|
+
others.push(name);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return others;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* skip = anderer Melder der Zone ist noch true → keinen Aus-Timer starten
|
|
43
|
+
* restart = Zone ist frei von Bewegung → bestehenden Timer ersetzen (nicht parallel)
|
|
44
|
+
*
|
|
45
|
+
* @param {boolean} otherMotionStillTrue
|
|
46
|
+
* @returns {'skip'|'restart'}
|
|
47
|
+
*/
|
|
48
|
+
function zoneMotionOffTimerAction(otherMotionStillTrue) {
|
|
49
|
+
return otherMotionStillTrue ? 'skip' : 'restart';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
getOtherMotionTriggerNames,
|
|
54
|
+
zoneMotionOffTimerAction,
|
|
55
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vergleichsausdrücke für Zahlen in Auslösern und Bedingungen.
|
|
5
|
+
*
|
|
6
|
+
* Warum: Das alte Regex `>=|<=|>|<` + nur Ziffern hat Minus und Komma nicht erkannt.
|
|
7
|
+
* Damit gingen z. B. `<-200` und `>26,5` beim Speichern durch (#164).
|
|
8
|
+
*
|
|
9
|
+
* Reihenfolge der Operatoren: `<>` vor `<`, sonst würde `<>30` als `<` gelesen.
|
|
10
|
+
*/
|
|
11
|
+
const COMPARATOR_RE = /^(>=|<=|<>|!=|>|<)\s*(-?\d+(?:[.,]\d+)?)\s*$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {unknown} compStr z. B. '< -200', '>-200', '>26,5', '<= 25'
|
|
15
|
+
* @returns {{isComparator: boolean, operand?: string, compNum?: number}}
|
|
16
|
+
*/
|
|
17
|
+
function parseNumComparator(compStr) {
|
|
18
|
+
if (typeof compStr !== 'string') {
|
|
19
|
+
return { isComparator: false };
|
|
20
|
+
}
|
|
21
|
+
const match = compStr.trim().match(COMPARATOR_RE);
|
|
22
|
+
if (!match) {
|
|
23
|
+
return { isComparator: false };
|
|
24
|
+
}
|
|
25
|
+
// Deutsches Komma 26,5 → 26.5, sonst parseFloat stoppt vor dem Komma
|
|
26
|
+
const compNum = parseFloat(match[2].replace(',', '.'));
|
|
27
|
+
if (Number.isNaN(compNum)) {
|
|
28
|
+
return { isComparator: false };
|
|
29
|
+
}
|
|
30
|
+
return { isComparator: true, operand: match[1], compNum };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {unknown} numToCheck aktueller Datenpunkt-Wert
|
|
35
|
+
* @param {unknown} compStr Ausdruck aus der Konfiguration
|
|
36
|
+
* @returns {{isComparator: boolean, result: boolean}}
|
|
37
|
+
*/
|
|
38
|
+
function isNumComparatorMatching(numToCheck, compStr) {
|
|
39
|
+
const parsed = parseNumComparator(compStr);
|
|
40
|
+
if (!parsed.isComparator) {
|
|
41
|
+
return { isComparator: false, result: false };
|
|
42
|
+
}
|
|
43
|
+
if (!(typeof numToCheck === 'string' || typeof numToCheck === 'number')) {
|
|
44
|
+
return { isComparator: true, result: false };
|
|
45
|
+
}
|
|
46
|
+
const n = Number(String(numToCheck).trim().replace(',', '.'));
|
|
47
|
+
if (Number.isNaN(n)) {
|
|
48
|
+
return { isComparator: true, result: false };
|
|
49
|
+
}
|
|
50
|
+
const operand = parsed.operand;
|
|
51
|
+
const compNum = parsed.compNum;
|
|
52
|
+
let result = false;
|
|
53
|
+
if (operand === '>=') {
|
|
54
|
+
result = n >= compNum;
|
|
55
|
+
} else if (operand === '<=') {
|
|
56
|
+
result = n <= compNum;
|
|
57
|
+
} else if (operand === '>') {
|
|
58
|
+
result = n > compNum;
|
|
59
|
+
} else if (operand === '<') {
|
|
60
|
+
result = n < compNum;
|
|
61
|
+
} else if (operand === '!=' || operand === '<>') {
|
|
62
|
+
result = n !== compNum;
|
|
63
|
+
}
|
|
64
|
+
return { isComparator: true, result };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
parseNumComparator,
|
|
69
|
+
isNumComparatorMatching,
|
|
70
|
+
};
|
package/lib/tools.js
CHANGED
|
@@ -2,6 +2,7 @@ const axios = require('axios');
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Tests whether the given variable is a real object and not an Array
|
|
5
|
+
*
|
|
5
6
|
* @param {any} it The variable to test
|
|
6
7
|
* @returns {it is Record<string, any>}
|
|
7
8
|
*/
|
|
@@ -15,16 +16,20 @@ function isObject(it) {
|
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Tests whether the given variable is really an Array
|
|
19
|
+
*
|
|
18
20
|
* @param {any} it The variable to test
|
|
19
21
|
* @returns {it is any[]}
|
|
20
22
|
*/
|
|
21
23
|
function isArray(it) {
|
|
22
|
-
if (typeof Array.isArray === 'function')
|
|
24
|
+
if (typeof Array.isArray === 'function') {
|
|
25
|
+
return Array.isArray(it);
|
|
26
|
+
}
|
|
23
27
|
return Object.prototype.toString.call(it) === '[object Array]';
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* Translates text to the target language. Automatically chooses the right translation API.
|
|
32
|
+
*
|
|
28
33
|
* @param {string} text The text to translate
|
|
29
34
|
* @param {string} targetLang The target languate
|
|
30
35
|
* @param {string} [yandexApiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
@@ -38,13 +43,13 @@ async function translateText(text, targetLang, yandexApiKey) {
|
|
|
38
43
|
}
|
|
39
44
|
if (yandexApiKey) {
|
|
40
45
|
return await translateYandex(text, targetLang, yandexApiKey);
|
|
41
|
-
} else {
|
|
42
|
-
return await translateGoogle(text, targetLang);
|
|
43
46
|
}
|
|
47
|
+
return await translateGoogle(text, targetLang);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
51
|
* Translates text with Yandex API
|
|
52
|
+
*
|
|
48
53
|
* @param {string} text The text to translate
|
|
49
54
|
* @param {string} targetLang The target languate
|
|
50
55
|
* @param {string} [apiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
@@ -56,7 +61,7 @@ async function translateYandex(text, targetLang, apiKey) {
|
|
|
56
61
|
}
|
|
57
62
|
try {
|
|
58
63
|
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
|
|
59
|
-
const response = await axios({url, timeout: 15000});
|
|
64
|
+
const response = await axios({ url, timeout: 15000 });
|
|
60
65
|
if (response.data && response.data['text']) {
|
|
61
66
|
return response.data['text'][0];
|
|
62
67
|
}
|
|
@@ -68,6 +73,7 @@ async function translateYandex(text, targetLang, apiKey) {
|
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
75
|
* Translates text with Google API
|
|
76
|
+
*
|
|
71
77
|
* @param {string} text The text to translate
|
|
72
78
|
* @param {string} targetLang The target languate
|
|
73
79
|
* @returns {Promise<string>}
|
|
@@ -75,7 +81,7 @@ async function translateYandex(text, targetLang, apiKey) {
|
|
|
75
81
|
async function translateGoogle(text, targetLang) {
|
|
76
82
|
try {
|
|
77
83
|
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`;
|
|
78
|
-
const response = await axios({url, timeout: 15000});
|
|
84
|
+
const response = await axios({ url, timeout: 15000 });
|
|
79
85
|
if (isArray(response.data)) {
|
|
80
86
|
// we got a valid response
|
|
81
87
|
return response.data[0][0][0];
|
|
@@ -89,5 +95,5 @@ async function translateGoogle(text, targetLang) {
|
|
|
89
95
|
module.exports = {
|
|
90
96
|
isArray,
|
|
91
97
|
isObject,
|
|
92
|
-
translateText
|
|
98
|
+
translateText,
|
|
93
99
|
};
|