From ca61cb06d0b5d869355ebc37ff0be0d83d3d6967 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 5 Apr 2021 10:39:43 +0200 Subject: [PATCH] Fix possible rule issue --- tasmota/tasmota.ino | 1 + tasmota/xdrv_10_rules.ino | 7 ++----- tasmota/xdrv_10_scripter.ino | 2 +- tasmota/xdrv_interface.ino | 11 +++++------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index ca32ead57..27ba36e05 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -138,6 +138,7 @@ struct { int16_t save_data_counter; // Counter and flag for config save to Flash RulesBitfield rules_flag; // Rule state flags (16 bits) + bool rule_teleperiod; // Process rule based on teleperiod data using prefix TELE- bool serial_local; // Handle serial locally bool fallback_topic_flag; // Use Topic or FallbackTopic bool backlog_mutex; // Command backlog pending diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 46bc5a607..4d76dbdb7 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -174,7 +174,6 @@ struct RULES { uint16_t last_minute = 60; uint16_t vars_event = 0; // Bitmask supporting MAX_RULE_VARS bits 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 @@ -420,7 +419,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all // Step1: Analyse rule String rule_expr = rule; // "TELE-INA219#CURRENT>0.100" - if (Rules.teleperiod) { + if (TasmotaGlobal.rule_teleperiod) { int ppos = rule_expr.indexOf(F("TELE-")); // "TELE-INA219#CURRENT>0.100" or "INA219#CURRENT>0.100" if (ppos == -1) { return false; } // No pre-amble in rule rule_expr = rule.substring(5); // "INA219#CURRENT>0.100" or "SYSTEM#BOOT" @@ -854,7 +853,7 @@ void RulesInit(void) bitWrite(Settings.rule_once, i, 0); } } - Rules.teleperiod = false; + TasmotaGlobal.rule_teleperiod = false; } void RulesEvery50ms(void) @@ -2340,9 +2339,7 @@ bool Xdrv10(uint8_t function) result = DecodeCommand(kRulesCommands, RulesCommand); break; case FUNC_RULES_PROCESS: - Rules.teleperiod = (XdrvMailbox.index); // Signal teleperiod event result = RulesProcess(); - Rules.teleperiod = false; break; case FUNC_SAVE_BEFORE_RESTART: RulesSaveBeforeRestart(); diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 6b21f24ce..d107373ce 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -7855,7 +7855,7 @@ bool Xdrv10(uint8_t function) break; case FUNC_RULES_PROCESS: if (bitRead(Settings.rule_enabled, 0)) { - if (XdrvMailbox.index) { // Signal teleperiod event + if (TasmotaGlobal.rule_teleperiod) { // Signal teleperiod event if (TasmotaGlobal.mqtt_data[0]) { Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data); } diff --git a/tasmota/xdrv_interface.ino b/tasmota/xdrv_interface.ino index 063e59855..6dfab4f36 100644 --- a/tasmota/xdrv_interface.ino +++ b/tasmota/xdrv_interface.ino @@ -1080,16 +1080,15 @@ void XsnsDriverState(void) /*********************************************************************************************/ bool XdrvRulesProcess(bool teleperiod) { - XdrvMailbox.index = teleperiod; // Signal teleperiod event + TasmotaGlobal.rule_teleperiod = teleperiod; // Signal teleperiod event + bool rule_handled = XdrvCallDriver(10, FUNC_RULES_PROCESS); #ifdef USE_BERRY // events are passed to both Rules engine AND Berry engine - bool rule_handled = XdrvCallDriver(10, FUNC_RULES_PROCESS); - XdrvMailbox.index = teleperiod; // Signal teleperiod event bool berry_handled = XdrvCallDriver(52, FUNC_RULES_PROCESS); - return rule_handled || berry_handled; -#else - return XdrvCallDriver(10, FUNC_RULES_PROCESS); + rule_handled |= berry_handled; #endif + TasmotaGlobal.rule_teleperiod = false; + return rule_handled; } #ifdef USE_DEBUG_DRIVER