Skip to content

Commit

Permalink
Fix rule handling of Var or Mem using text
Browse files Browse the repository at this point in the history
Fix rule handling of Var or Mem using text regression from v8.5.0.1 (#9540)
  • Loading branch information
arendst committed Oct 15, 2020
1 parent 29e73da commit 98d2dd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- Convert AdcParam parameters from versions before v9.0.0.2
- Telegram message decoding error regression from v8.5.0.1
- Correct Energy period display shortly after midnight by gominoa (#9536)
- Rule handling of Var or Mem using text regression from v8.5.0.1 (#9540)

## [9.0.0.1] - 20201010
### Added
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Light wakeup exception 0 (divide by zero) when ``WakeupDuration`` is not initialised (#9466)
- Thermostat sensor status corruption regression from v8.5.0.1 (#9449)
- Telegram message decoding error regression from v8.5.0.1
- Rule handling of Var or Mem using text regression from v8.5.0.1 (#9540)
- Correct Energy period display shortly after midnight by gominoa (#9536)

### Removed
Expand Down
14 changes: 10 additions & 4 deletions tasmota/xdrv_10_rules.ino
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,14 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule)
}

String buf = event; // copy the string into a new buffer that will be modified

//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: RulesRuleMatch |%s|"), buf.c_str());

JsonParser parser((char*)buf.c_str());
JsonParserObject obj = parser.getRootObject();
if (!obj) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Event too long (%d)"), event.length());
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Event too long (%d)"), event.length());
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: No valid JSON (%s)"), buf.c_str());
return false; // No valid JSON data
}
String subtype;
Expand Down Expand Up @@ -771,6 +775,8 @@ bool RulesProcessEvent(char *json_event)
ShowFreeMem(PSTR("RulesProcessEvent"));
#endif

//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: ProcessEvent |%s|"), json_event);

String event_saved = json_event;
// json_event = {"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}}
// json_event = {"System":{"Boot":1}}
Expand All @@ -783,7 +789,7 @@ bool RulesProcessEvent(char *json_event)
}
event_saved.toUpperCase();

//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Event %s"), event_saved.c_str());
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Event |%s|"), event_saved.c_str());

for (uint32_t i = 0; i < MAX_RULE_SETS; i++) {
if (GetRuleLen(i) && bitRead(Settings.rule_enabled, i)) {
Expand Down Expand Up @@ -887,7 +893,7 @@ void RulesEvery50ms(void)
for (uint32_t i = 0; i < MAX_RULE_VARS; i++) {
if (bitRead(Rules.vars_event, i)) {
bitClear(Rules.vars_event, i);
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Var%d\":{\"State\":%s}}"), i+1, rules_vars[i]);
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Var%d\":{\"State\":\"%s\"}}"), i+1, rules_vars[i]);
RulesProcessEvent(json_event);
break;
}
Expand All @@ -897,7 +903,7 @@ void RulesEvery50ms(void)
for (uint32_t i = 0; i < MAX_RULE_MEMS; i++) {
if (bitRead(Rules.mems_event, i)) {
bitClear(Rules.mems_event, i);
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Mem%d\":{\"State\":%s}}"), i+1, SettingsText(SET_MEM1 +i));
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Mem%d\":{\"State\":\"%s\"}}"), i+1, SettingsText(SET_MEM1 +i));
RulesProcessEvent(json_event);
break;
}
Expand Down

0 comments on commit 98d2dd8

Please sign in to comment.