From 3bacfc33616479d7566fb041aff6124c1b73013d Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 1 Apr 2021 16:31:56 +0200 Subject: [PATCH] value2enum texts from local_EN --- src/devices/boiler.cpp | 14 ++++++------- src/devices/thermostat.cpp | 43 +++++++++++++++++++------------------- src/helpers.cpp | 16 +++++++------- src/helpers.h | 2 +- src/locale_EN.h | 4 ++++ 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index c16bb0f15..60a72dedd 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -246,7 +246,7 @@ void Boiler::check_active(const bool force) { if (heatingActive_ != val || force) { heatingActive_ = val; char s[7]; - Mqtt::publish(F("heating_active"), Helpers::render_boolean(s, b)); + Mqtt::publish(F_(heating_active), Helpers::render_boolean(s, b)); } // check if tap water is active, bits 1 and 4 must be set @@ -265,7 +265,7 @@ void Boiler::check_active(const bool force) { if (tapwaterActive_ != val || force) { tapwaterActive_ = val; char s[7]; - Mqtt::publish(F("tapwater_active"), Helpers::render_boolean(s, b)); + Mqtt::publish(F_(tapwater_active), Helpers::render_boolean(s, b)); EMSESP::tap_water_active(b); // let EMS-ESP know, used in the Shower class } } @@ -933,7 +933,7 @@ bool Boiler::set_pump_delay(const char * value, const int8_t id) { // on a RC35 it's by EMSESP::send_write_request(0x37, 0x10, 2, &set, 1, 0); (set is 1,2,3) 1=hot, 2=eco, 3=intelligent bool Boiler::set_warmwater_mode(const char * value, const int8_t id) { uint8_t set; - if (!Helpers::value2enum(value, set, {F("hot"), F("eco"), F("intelligent")})) { + if (!Helpers::value2enum(value, set, FL_(enum_comfort))) { LOG_WARNING(F("Set boiler warm water mode: Invalid value")); return false; } @@ -1114,11 +1114,11 @@ bool Boiler::set_reset(const char * value, const int8_t id) { return false; } - if (s == "maintenance") { + if (s == Helpers::toLower(uuid::read_flash_string(F_(maintenance)))) { LOG_INFO(F("Reset boiler maintenance message")); write_command(0x05, 0x08, 0xFF, 0x1C); return true; - } else if (s == "error") { + } else if (s == Helpers::toLower(uuid::read_flash_string(F_(error)))) { LOG_INFO(F("Reset boiler error message")); write_command(0x05, 0x00, 0x5A); // error reset return true; @@ -1130,7 +1130,7 @@ bool Boiler::set_reset(const char * value, const int8_t id) { bool Boiler::set_maintenance(const char * value, const int8_t id) { std::string s(12, '\0'); if (Helpers::value2string(value, s)) { - if (s == "reset") { + if (s == Helpers::toLower(uuid::read_flash_string(F_(reset)))) { LOG_INFO(F("Reset boiler maintenance message")); write_command(0x05, 0x08, 0xFF, 0x1C); return true; @@ -1163,7 +1163,7 @@ bool Boiler::set_maintenance(const char * value, const int8_t id) { } uint8_t num; - if (Helpers::value2enum(value, num, {F("off"), F("time"), F("date")})) { + if (Helpers::value2enum(value, num, FL_(enum_off_time_date))) { LOG_INFO(F("Setting maintenance type to %s"), value); write_command(0x15, 0, num, 0x15); return true; diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index c020306f4..9ca1157bb 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -1145,26 +1145,27 @@ bool Thermostat::set_remotetemp(const char * value, const int8_t id) { // 0xA5 - Set the building settings bool Thermostat::set_building(const char * value, const int8_t id) { uint8_t bd = 0; - if (!Helpers::value2enum(value, bd, {F("light"), F("medium"), F("heavy")})) { - LOG_WARNING(F("Set building: Invalid value")); - return false; - } - - LOG_INFO(F("Setting building to %s"), value); - if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { - write_command(0x240, 9, bd + 1, 0x240); + if (Helpers::value2enum(value, bd, FL_(enum_ibaBuildingType))) { + LOG_INFO(F("Setting building to %s"), value); + write_command(0x240, 9, bd , 0x240); + return true; + } } else { - write_command(EMS_TYPE_IBASettings, 6, bd, EMS_TYPE_IBASettings); + if (Helpers::value2enum(value, bd, FL_(enum_ibaBuildingType2))) { + LOG_INFO(F("Setting building to %s"), value); + write_command(EMS_TYPE_IBASettings, 6, bd, EMS_TYPE_IBASettings); + return true; + } } - - return true; + LOG_WARNING(F("Set building: Invalid value")); + return false; } // 0xA5 Set the language settings bool Thermostat::set_language(const char * value, const int8_t id) { uint8_t lg = 0; - if (!Helpers::value2enum(value, lg, {F("german"), F("dutch"), F("french"), F("italian")})) { + if (!Helpers::value2enum(value, lg, FL_(enum_ibaLanguage))) { LOG_WARNING(F("Set language: Invalid value")); return false; } @@ -1178,7 +1179,7 @@ bool Thermostat::set_language(const char * value, const int8_t id) { // Set the control-mode for hc 0-off, 1-RC20, 2-RC3x bool Thermostat::set_control(const char * value, const int8_t id) { uint8_t ctrl = 0; - if (!Helpers::value2enum(value, ctrl, {F("off"), F("rc20"), F("rc3x")})) { + if (!Helpers::value2enum(value, ctrl, FL_(enum_control))) { LOG_WARNING(F("Set control: Invalid value")); return false; } @@ -1200,14 +1201,14 @@ bool Thermostat::set_wwmode(const char * value, const int8_t id) { uint8_t set = 0xFF; if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { - if (!Helpers::value2enum(value, set, {F("off"), F("low"), F("high"), F("auto"), F("own")})) { + if (!Helpers::value2enum(value, set, FL_(enum_wwMode))) { LOG_WARNING(F("Set warm water mode: Invalid mode")); return false; } LOG_INFO(F("Setting warm water mode to %s"), value); write_command(0x02F5, 2, set, 0x02F5); } else { - if (!Helpers::value2enum(value, set, {F("off"), F("on"), F("auto")})) { + if (!Helpers::value2enum(value, set, FL_(enum_wwMode2))) { LOG_WARNING(F("Set warm water mode: Invalid mode")); return false; } @@ -1259,7 +1260,7 @@ bool Thermostat::set_wwcircmode(const char * value, const int8_t id) { uint8_t set = 0xFF; if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { - if (!Helpers::value2enum(value, set, {F("off"), F("on"), F("auto"), F("own")})) { + if (!Helpers::value2enum(value, set, FL_(enum_wwCircMode))) { LOG_WARNING(F("Set warm water circulation mode: Invalid mode")); return false; } @@ -1267,7 +1268,7 @@ bool Thermostat::set_wwcircmode(const char * value, const int8_t id) { write_command(0x02F5, 3, set, 0x02F5); return true; } - if (!Helpers::value2enum(value, set, {F("off"), F("on"), F("auto")})) { + if (!Helpers::value2enum(value, set, FL_(enum_wwCircMode2))) { LOG_WARNING(F("Set warm water circulation mode: Invalid mode")); return false; } @@ -1565,7 +1566,7 @@ bool Thermostat::set_summermode(const char * value, const int8_t id) { return false; } uint8_t set = 0xFF; - if (!Helpers::value2enum(value, set, {F("summer"), F("auto"), F("winter")})) { + if (!Helpers::value2enum(value, set, FL_(enum_summermode))) { LOG_WARNING(F("Setting summer mode: Invalid mode")); return false; } @@ -1583,7 +1584,7 @@ bool Thermostat::set_reducemode(const char * value, const int8_t id) { return false; } uint8_t set = 0xFF; - if (!Helpers::value2enum(value, set, {F("nofrost"), F("reduce"), F("room"), F("outdoor")})) { + if (!Helpers::value2enum(value, set, FL_(enum_reducemode))) { LOG_WARNING(F("Setting reduce mode: Invalid mode")); return false; } @@ -1602,13 +1603,13 @@ bool Thermostat::set_controlmode(const char * value, const int8_t id) { } uint8_t set = 0xFF; if (model() == EMS_DEVICE_FLAG_RC300 || model() == EMS_DEVICE_FLAG_RC100) { - if (Helpers::value2enum(value, set, {F("off"), F("outdoor"), F("simple"), F("MPC"), F("room"), F("power"), F("const")})) { + if (Helpers::value2enum(value, set, FL_(enum_controlmode))) { LOG_INFO(F("Setting control mode to %d for heating circuit %d"), set, hc->hc_num()); write_command(curve_typeids[hc->hc_num() - 1], 0, set, curve_typeids[hc->hc_num() - 1]); return true; } } else if (model() == EMS_DEVICE_FLAG_RC35 || model() == EMS_DEVICE_FLAG_RC30_1) { - if (Helpers::value2enum(value, set, {F("outdoor"), F("room")})) { + if (Helpers::value2enum(value, set, FL_(enum_controlmode2))) { LOG_INFO(F("Setting control mode to %d for heating circuit %d"), set, hc->hc_num()); write_command(set_typeids[hc->hc_num() - 1], 33, set, set_typeids[hc->hc_num() - 1]); return true; diff --git a/src/helpers.cpp b/src/helpers.cpp index ee4bb7ef6..24dc075bc 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -126,9 +126,9 @@ char * Helpers::smallitoa(char * result, const uint16_t value) { char * Helpers::render_boolean(char * result, bool value) { uint8_t bool_format_ = Mqtt::bool_format(); if (bool_format_ == BOOL_FORMAT_ONOFF) { - strlcpy(result, value ? "on" : "off", 5); + strlcpy(result, value ? uuid::read_flash_string(F_(on)).c_str() : uuid::read_flash_string(F_(off)).c_str(), 5); } else if (bool_format_ == BOOL_FORMAT_ONOFF_CAP) { - strlcpy(result, value ? "ON" : "OFF", 5); + strlcpy(result, value ? uuid::read_flash_string(F_(ON)).c_str() : uuid::read_flash_string(F_(OFF)).c_str(), 5); } else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) { strlcpy(result, value ? "true" : "false", 7); } else { @@ -457,12 +457,12 @@ bool Helpers::value2bool(const char * v, bool & value) { std::string bool_str = toLower(v); // convert to lower case - if ((bool_str == "on") || (bool_str == "1") or (bool_str == "true")) { + if ((bool_str == uuid::read_flash_string(F_(on))) || (bool_str == "1") or (bool_str == "true")) { value = true; return true; // is a bool } - if ((bool_str == "off") || (bool_str == "0") or (bool_str == "false")) { + if ((bool_str == uuid::read_flash_string(F_(off))) || (bool_str == "0") or (bool_str == "false")) { value = false; return true; // is a bool } @@ -471,14 +471,14 @@ bool Helpers::value2bool(const char * v, bool & value) { } // checks to see if a string is member of a vector and return the index, also allow true/false for on/off -bool Helpers::value2enum(const char * v, uint8_t & value, const flash_string_vector & strs) { +bool Helpers::value2enum(const char * v, uint8_t & value, const __FlashStringHelper * const * strs) { if ((v == nullptr) || (strlen(v) == 0)) { return false; } std::string str = toLower(v); - for (value = 0; value < strs.size(); value++) { - std::string str1 = uuid::read_flash_string(strs[value]); - if ((str1 == "off" && str == "false") || (str1 == "on" && str == "true") || (str == str1) || (v[0] == ('0' + value) && v[1] == '\0')) { + for (value = 0; strs[value]; value++) { + std::string str1 = toLower(uuid::read_flash_string(strs[value])); + if ((str1 == uuid::read_flash_string(F_(off)) && str == "false") || (str1 == uuid::read_flash_string(F_(on)) && str == "true") || (str == str1) || (v[0] == ('0' + value) && v[1] == '\0')) { return true; } } diff --git a/src/helpers.h b/src/helpers.h index fd58e9f2c..b78d62f5e 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -65,7 +65,7 @@ class Helpers { static bool value2float(const char * v, float & value); static bool value2bool(const char * v, bool & value); static bool value2string(const char * v, std::string & value); - static bool value2enum(const char * v, uint8_t & value, const flash_string_vector & strs); + static bool value2enum(const char * v, uint8_t & value, const __FlashStringHelper * const * strs); #ifdef EMSESP_STANDALONE static char * ultostr(char * ptr, uint32_t value, const uint8_t base); diff --git a/src/locale_EN.h b/src/locale_EN.h index ae9fc7ac7..282ff5ed0 100644 --- a/src/locale_EN.h +++ b/src/locale_EN.h @@ -257,7 +257,11 @@ MAKE_PSTR_LIST(enum_hamode, F_(off), F_(heat), F_(auto), F_(heat), F_(off), F_(h //extra commands MAKE_PSTR(wwtapactivated, "wwtapactivated") MAKE_PSTR(maintenance, "maintenance") +MAKE_PSTR(error, "error") MAKE_PSTR(reset, "reset") +// single mqtt topics +MAKE_PSTR(heating_active, "heating_active") +MAKE_PSTR(tapwater_active, "tapwater_active") // mqtt, commands and text // MAKE_PSTR_LIST(id, F("id"), F("id")) MAKE_PSTR_LIST(burnPeriod, F("burnperiod"), F("min burner periode"))