From ce53ee07e7f5e7a706ae9488745487ae85e4c63c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 8 Apr 2019 13:26:17 +0200 Subject: [PATCH] Fix template activation and/or module selection regression from 6.5.0.4 (#5598) Fix template activation and/or module selection regression from 6.5.0.4 (#5598) --- sonoff/_changelog.ino | 1 + sonoff/sonoff.ino | 6 +++--- sonoff/support.ino | 10 ++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index ec33d7cda..cf71d6a44 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /* 6.5.0.5 20190406 * Add compile time GUI hexadecimal only color options in my_user_config.h (#5586) + * Fix template activation and/or module selection regression from 6.5.0.4 (#5598) * * 6.5.0.4 20190402 * Fix Configure Timer Web GUI (#5568) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 741743618..0c1822dc5 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -876,11 +876,11 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) if ((payload >= 0) && (payload <= MAXMODULE)) { bool present = false; if (0 == payload) { - payload = 255; + payload = USER_MODULE; present = true; } else { payload--; - present = ValidModule(payload); + present = ValidTemplateModule(payload); } if (present) { Settings.last_module = Settings.module; @@ -979,7 +979,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) if (strstr(dataBuf, "{") == nullptr) { // If no JSON it must be parameter if ((payload > 0) && (payload <= MAXMODULE)) { payload--; - if (ValidModule(payload)) { + if (ValidTemplateModule(payload)) { ModuleDefault(payload); // Copy template module if (USER_MODULE == Settings.module) { restart_flag = 2; } } diff --git a/sonoff/support.ino b/sonoff/support.ino index 51c895905..594ca342e 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -846,7 +846,7 @@ uint8_t ModuleNr() return (USER_MODULE == Settings.module) ? 0 : Settings.module +1; } -bool ValidModule(uint8_t index) +bool ValidTemplateModule(uint8_t index) { for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) { if (index == pgm_read_byte(kModuleNiceList + i)) { @@ -856,6 +856,12 @@ bool ValidModule(uint8_t index) return false; } +bool ValidModule(uint8_t index) +{ + if (index == USER_MODULE) { return true; } + return ValidTemplateModule(index); +} + String AnyModuleName(uint8_t index) { if (USER_MODULE == index) { @@ -1023,7 +1029,7 @@ bool JsonTemplate(const char* dataBuf) } if (obj[D_JSON_BASE].success()) { uint8_t base = obj[D_JSON_BASE]; - if ((0 == base) || !ValidModule(base -1)) { base = 18; } + if ((0 == base) || !ValidTemplateModule(base -1)) { base = 18; } Settings.user_template_base = base -1; // Default WEMOS } return true;