Support rules that override button holds

This commit is contained in:
Paul C Diem 2020-11-26 10:36:43 -06:00
parent 3b0cfab8ae
commit b0fb9090bc
2 changed files with 14 additions and 3 deletions

View File

@ -171,6 +171,7 @@ struct RULES {
uint16_t mems_event = 0; // Bitmask supporting MAX_RULE_MEMS bits
bool teleperiod = false;
bool busy = false;
bool no_execute = false; // Don't actually execute rule commands
char event_data[100];
} Rules;
@ -708,6 +709,7 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
#endif
if (RulesRuleMatch(rule_set, event, event_trigger, stop_all_rules)) {
if (Rules.no_execute) return true;
if (plen == plen2) { stop_all_rules = true; } // If BREAK was used on a triggered rule, Stop execution of this rule set
commands.trim();
String ucommand = commands;

View File

@ -767,10 +767,19 @@ bool Xdrv35(uint8_t function)
#endif // USE_PWM_DIMMER_REMOTE
}
// If hold time has arrived, handle it.
// If hold time has arrived and a rule is enabled that handles the button hold, handle it.
else if (button_hold_time[button_index] <= now) {
PWMDimmerHandleButton(button_index, true);
button_held[button_index] = true;
#ifdef USE_RULES
sprintf(TasmotaGlobal.mqtt_data, PSTR("{\"Button%u\":{\"State\":3}}"), button_index + 1);
Rules.no_execute = true;
if (!XdrvRulesProcess()) {
#endif // USE_RULES
PWMDimmerHandleButton(button_index, true);
button_held[button_index] = true;
#ifdef USE_RULES
}
Rules.no_execute = false;
#endif // USE_RULES
}
}