Fix teleperiod rule handling regression

Fix teleperiod rule handling regression from v9.3.1.2 (#11851)
This commit is contained in:
Theo Arends 2021-04-23 10:59:33 +02:00
parent 147440fd99
commit 674509a56e
7 changed files with 25 additions and 17 deletions

View File

@ -8,9 +8,12 @@ All notable changes to this project will be documented in this file.
- Command ``Wifi 0/1`` for ESP8266 to turn wifi Off and On. When wifi is Off it is always returned On after a restart except for a wake-up from deepsleep (#11839)
### Changed
- Command ``Power`` should not reset pulsetime (#11805)
- Zigbee refactored storage for device configuration and device last known data (#11838)
### Fixed
- Command ``Power`` should not reset pulsetime (#11805)
- Teleperiod rule handling regression from v9.3.1.2 (#11851)
## [Released]
## [9.4.0] 20210422

View File

@ -83,10 +83,11 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
### Breaking Changed
### Changed
- Command ``Power`` should not reset pulsetime [#11805](https://github.com/arendst/Tasmota/issues/11805)
- Zigbee refactored storage for device configuration and device last known data [#11838](https://github.com/arendst/Tasmota/issues/11838)
### Fixed
- Command ``Power`` should not reset pulsetime [#11805](https://github.com/arendst/Tasmota/issues/11805)
- Teleperiod rule handling regression from v9.3.1.2 [#11851](https://github.com/arendst/Tasmota/issues/11851)
### Noted
- ESP32 single core **tasmota32solo1.bin** binary can only be uploaded using the GUI as OTA upload will trigger the watchdog timer

View File

@ -311,7 +311,7 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FU
FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA,
FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY,
FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET,
FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED,
FUNC_RULES_PROCESS, FUNC_TELEPERIOD_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED,
FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_CONSOLE_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON,
FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN,
FUNC_DEVICE_GROUP_ITEM };

View File

@ -140,7 +140,6 @@ 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_nodelay; // Execute all backlog commands with no delay

View File

@ -174,6 +174,7 @@ 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 +421,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 (TasmotaGlobal.rule_teleperiod) {
if (Rules.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"
@ -433,7 +434,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
// rule_param = "0.100" or "%VAR1%"
#ifdef DEBUG_RULES
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("RUL-RM1: expr %s, name %s, param %s"), rule_expr.c_str(), rule_name.c_str(), rule_param.c_str());
AddLog_P(LOG_LEVEL_DEBUG, PSTR("RUL-RM1: Teleperiod %d, Expr %s, Name %s, Param %s"), Rules.teleperiod, rule_expr.c_str(), rule_name.c_str(), rule_param.c_str());
#endif
char rule_svalue[80] = { 0 };
@ -852,7 +853,7 @@ void RulesInit(void)
bitWrite(Settings.rule_once, i, 0);
}
}
TasmotaGlobal.rule_teleperiod = false;
Rules.teleperiod = false;
}
void RulesEvery50ms(void)
@ -2339,6 +2340,11 @@ bool Xdrv10(uint8_t function)
case FUNC_RULES_PROCESS:
result = RulesProcess();
break;
case FUNC_TELEPERIOD_RULES_PROCESS:
Rules.teleperiod = true;
result = RulesProcess();
Rules.teleperiod = false;
break;
case FUNC_SAVE_BEFORE_RESTART:
RulesSaveBeforeRestart();
break;

View File

@ -7886,13 +7886,14 @@ bool Xdrv10(uint8_t function)
break;
case FUNC_RULES_PROCESS:
if (bitRead(Settings.rule_enabled, 0)) {
if (TasmotaGlobal.rule_teleperiod) { // Signal teleperiod event
if (TasmotaGlobal.mqtt_data[0]) {
Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data);
}
} else {
Run_Scripter(">E", 2, TasmotaGlobal.mqtt_data);
result = glob_script_mem.event_handeled;
Run_Scripter(">E", 2, TasmotaGlobal.mqtt_data);
result = glob_script_mem.event_handeled;
}
break;
case FUNC_TELEPERIOD_RULES_PROCESS:
if (bitRead(Settings.rule_enabled, 0)) {
if (TasmotaGlobal.mqtt_data[0]) {
Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data);
}
}
break;

View File

@ -1080,14 +1080,12 @@ void XsnsDriverState(void)
/*********************************************************************************************/
bool XdrvRulesProcess(bool teleperiod) {
TasmotaGlobal.rule_teleperiod = teleperiod; // Signal teleperiod event
bool rule_handled = XdrvCallDriver(10, FUNC_RULES_PROCESS);
bool rule_handled = XdrvCallDriver(10, (teleperiod) ? FUNC_TELEPERIOD_RULES_PROCESS : FUNC_RULES_PROCESS);
#ifdef USE_BERRY
// events are passed to both Rules engine AND Berry engine
bool berry_handled = XdrvCallDriver(52, FUNC_RULES_PROCESS);
rule_handled |= berry_handled;
#endif
TasmotaGlobal.rule_teleperiod = false;
return rule_handled;
}