From 7f2b3643f54930b14080271bbd7ca127a12e26d3 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 1 Dec 2018 18:12:33 -0300 Subject: [PATCH 1/2] RULES: Added BREAK as an alternative ENDON RULES: Added BREAK as an alternative ENDON that will stop the execution of the following rules. If a rule that ends with BREAK, is triggered, then the following rules of that set will not be executed. This is useful for cases like: https://github.com/arendst/Sonoff-Tasmota/issues/4477 --- sonoff/xdrv_10_rules.ino | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 1fde3dff7..251c91e47 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -264,6 +264,8 @@ bool RuleSetProcess(byte rule_set, String &event_saved) rules_trigger_count[rule_set] = 0; int plen = 0; + int plen2 = 0; + bool stop_all_rules = false; while (true) { rules = rules.substring(plen); // Select relative to last rule rules.trim(); @@ -278,7 +280,14 @@ bool RuleSetProcess(byte rule_set, String &event_saved) String event_trigger = rule.substring(3, pevt); // "INA219#CURRENT>0.100" plen = rule.indexOf(" ENDON"); - if (plen == -1) { return serviced; } // Bad syntax - No endon + plen2 = rule.indexOf(" BREAK"); + if ((plen == -1) && (plen2 == -1)) { return serviced; } // Bad syntax - No ENDON neither BREAK + + if (plen == -1) { plen = 9999; } + if (plen2 == -1) { plen2 = 9999; } + plen = min(plen, plen2); + if (plen == plen2) { stop_all_rules = true; } // If BREAK was used, Stop execution of this rule set + String commands = rules.substring(pevt +4, plen); // "Backlog Dimmer 10;Color 100000" plen += 6; rules_event_value = ""; @@ -320,6 +329,7 @@ bool RuleSetProcess(byte rule_set, String &event_saved) ExecuteCommand(command, SRC_RULE); serviced = true; + if (stop_all_rules) { return serviced; } // If BREAK was used, Stop execution of this rule set } rules_trigger_count[rule_set]++; } From c68fe7e7ada34f248eeb0c2ed51a8049ac5bcc64 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sat, 1 Dec 2018 19:00:34 -0300 Subject: [PATCH 2/2] RULES: Added BREAK as an alternative ENDON --- sonoff/xdrv_10_rules.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 251c91e47..0a06fe149 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -285,7 +285,7 @@ bool RuleSetProcess(byte rule_set, String &event_saved) if (plen == -1) { plen = 9999; } if (plen2 == -1) { plen2 = 9999; } - plen = min(plen, plen2); + plen = tmin(plen, plen2); if (plen == plen2) { stop_all_rules = true; } // If BREAK was used, Stop execution of this rule set String commands = rules.substring(pevt +4, plen); // "Backlog Dimmer 10;Color 100000"