Skip to content

Commit

Permalink
RULES: Added BREAK as an alternative ENDON
Browse files Browse the repository at this point in the history
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: arendst#4477
  • Loading branch information
ascillato authored Dec 1, 2018
1 parent 2e1af64 commit 7f2b364
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sonoff/xdrv_10_rules.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 = "";
Expand Down Expand Up @@ -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]++;
}
Expand Down

0 comments on commit 7f2b364

Please sign in to comment.