6.1.1.6 Add modulo option to rules

Add modulo option to rules like rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon (#3466)
This commit is contained in:
Theo Arends 2018-08-13 13:09:22 +02:00
parent e15aeabbcf
commit 8a61c25218
3 changed files with 17 additions and 2 deletions

View File

@ -1,4 +1,7 @@
/* 6.1.1.5
/* 6.1.1.6
* Add modulo option to rules like rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon (#3466)
*
* 6.1.1.5
* Fix some Pow R2 and S31 checksum errors using optimized re-sync
*
* 6.1.1.4

View File

@ -20,6 +20,6 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06010105
#define VERSION 0x06010106
#endif // _SONOFF_VERSION_H_

View File

@ -182,6 +182,11 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule)
pos = rule_name.indexOf("=");
if (pos > 0) {
compare = '=';
} else {
pos = rule_name.indexOf("|"); // Modulo, cannot use % easily as it is used for variable detection
if (pos > 0) {
compare = '%';
}
}
}
}
@ -236,7 +241,14 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule)
// Step 3: Compare rule (value)
if (str_value) {
value = CharToDouble((char*)str_value);
int int_value = int(value);
int int_rule_value = int(rule_value);
switch (compare) {
case '%':
if ((int_value > 0) && (int_rule_value > 0)) {
if ((int_value % int_rule_value) == 0) { match = true; }
}
break;
case '>':
if (value > rule_value) { match = true; }
break;