diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index af8037124..3cb34e0c1 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -1202,7 +1202,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, {"hot", "eco", "intelligent"})) { + if (!Helpers::value2enum(value, set, {F("hot"), F("eco"), F("intelligent")})) { LOG_WARNING(F("Set boiler warm water mode: Invalid value")); return false; } diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 804a82090..184da790c 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -419,7 +419,7 @@ bool Thermostat::export_values_main(JsonObject & rootThermostat) { // Floordry if (Helpers::hasValue(floordrystatus_) && Helpers::hasValue(floordrytemp_) && (floordrytemp_ > 0)) { char s[10]; - rootThermostat["floordry"] = Helpers::render_enum(s, {"off", "start", "heat", "hold", "cool", "end"}, floordrystatus_); + rootThermostat["floordry"] = Helpers::render_enum(s, {F("off"), F("start"), F("heat"), F("hold"), F("cool"), F("end")}, floordrystatus_); rootThermostat["floordrytemp"] = floordrytemp_; } @@ -447,9 +447,9 @@ bool Thermostat::export_values_main(JsonObject & rootThermostat) { if (Helpers::hasValue(ibaBuildingType_)) { char s[10]; if (model == EMS_DEVICE_FLAG_RC300 || model == EMS_DEVICE_FLAG_RC100) { - rootThermostat["building"] = Helpers::render_enum(s, {"light", "medium", "heavy"}, ibaBuildingType_ - 1); + rootThermostat["building"] = Helpers::render_enum(s, {F("light"), F("medium"), F("heavy")}, ibaBuildingType_ - 1); } else { - rootThermostat["building"] = Helpers::render_enum(s, {"light", "medium", "heavy"}, ibaBuildingType_); + rootThermostat["building"] = Helpers::render_enum(s, {F("light"), F("medium"), F("heavy")}, ibaBuildingType_); } } @@ -457,9 +457,9 @@ bool Thermostat::export_values_main(JsonObject & rootThermostat) { if (Helpers::hasValue(wwMode_)) { char s[10]; if (model == EMS_DEVICE_FLAG_RC300 || model == EMS_DEVICE_FLAG_RC100) { - rootThermostat["wwmode"] = Helpers::render_enum(s, {"off", "low", "high", "auto", "own_prog"}, wwMode_); + rootThermostat["wwmode"] = Helpers::render_enum(s, {F("off"), F("low"), F("high"), F("auto"), F("own_prog")}, wwMode_); } else { - rootThermostat["wwmode"] = Helpers::render_enum(s, {"off", "on", "auto"}, wwMode_); + rootThermostat["wwmode"] = Helpers::render_enum(s, {F("off"), F("on"), F("auto")}, wwMode_); } } @@ -476,7 +476,7 @@ bool Thermostat::export_values_main(JsonObject & rootThermostat) { // Warm Water circulation mode if (Helpers::hasValue(wwCircMode_)) { char s[7]; - rootThermostat["wwcircmode"] = Helpers::render_enum(s, {"off", "on", "auto"}, wwCircMode_); + rootThermostat["wwcircmode"] = Helpers::render_enum(s, {F("off"), F("on"), F("auto")}, wwCircMode_); } return (rootThermostat.size()); @@ -608,7 +608,7 @@ bool Thermostat::export_values_hc(uint8_t mqtt_format, JsonObject & rootThermost // Summer mode if (Helpers::hasValue(hc->summer_setmode)) { char s[7]; - dataThermostat["summermode"] = Helpers::render_enum(s, {"summer", "auto", "winter"}, hc->summer_setmode); + dataThermostat["summermode"] = Helpers::render_enum(s, {F("summer"), F("auto"), F("winter")}, hc->summer_setmode); } // mode - always force showing this when in HA so not to break HA's climate component @@ -1514,7 +1514,7 @@ 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, {"light", "medium", "heavy"})) { + if (!Helpers::value2enum(value, bd, {F("light"), F("medium"), F("heavy")})) { LOG_WARNING(F("Set building: Invalid value")); return false; } @@ -1533,7 +1533,7 @@ bool Thermostat::set_building(const char * value, const int8_t id) { // 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, {"german", "dutch", "french", "italian"})) { + if (!Helpers::value2enum(value, lg, {F("german"), F("dutch"), F("french"), F("italian")})) { LOG_WARNING(F("Set language: Invalid value")); return false; } @@ -1586,14 +1586,14 @@ bool Thermostat::set_roominfluence(const char * value, const int8_t id) { bool Thermostat::set_wwmode(const char * value, const int8_t id) { uint8_t set = 0xFF; if ((this->model() == EMS_DEVICE_FLAG_RC300) || (this->model() == EMS_DEVICE_FLAG_RC100)) { - if (!Helpers::value2enum(value, set, {"off", "low", "high", "auto", "own"})) { + if (!Helpers::value2enum(value, set, {F("off"), F("low"), F("high"), F("auto"), F("own")})) { 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, {"off", "on", "auto"})) { + if (!Helpers::value2enum(value, set, {F("off"), F("on"), F("auto")})) { LOG_WARNING(F("Set warm water mode: Invalid mode")); return false; } @@ -1631,7 +1631,7 @@ bool Thermostat::set_wwtemplow(const char * value, const int8_t id) { // sets the thermostat ww circulation working mode, where mode is a string bool Thermostat::set_wwcircmode(const char * value, const int8_t id) { uint8_t set = 0xFF; - if (!Helpers::value2enum(value, set, {"off", "on", "auto"})) { + if (!Helpers::value2enum(value, set, {F("off"), F("on"), F("auto")})) { LOG_WARNING(F("Set warm water circulation mode: Invalid mode")); return false; } @@ -1909,7 +1909,7 @@ bool Thermostat::set_summermode(const char * value, const int8_t id) { return false; } uint8_t set = 0xFF; - if (!Helpers::value2enum(value, set, {"summer", "auto", "winter"})) { + if (!Helpers::value2enum(value, set, {F("summer"), F("auto"), F("winter")})) { LOG_WARNING(F("Setting summer mode: Invalid mode")); return false; } diff --git a/src/devices/thermostat.h b/src/devices/thermostat.h index 486e49daa..8e949ca69 100644 --- a/src/devices/thermostat.h +++ b/src/devices/thermostat.h @@ -133,7 +133,7 @@ class Thermostat : public EMSdevice { std::vector summer_typeids; std::string datetime_; // date and time stamp - std::string errorCode_; // code as string i.e. "A22(816)" + std::string errorCode_; // code from 0xA2 as string i.e. "A22(816)" bool changed_ = false; bool ha_registered_ = false; diff --git a/src/helpers.cpp b/src/helpers.cpp index 2dfe27324..328b69d71 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -136,19 +136,20 @@ char * Helpers::render_boolean(char * result, bool value) { } // depending on format render a number or a string -char * Helpers::render_enum(char * result, const std::vector & value, const uint8_t no) { +char * Helpers::render_enum(char * result, const std::vector value, const uint8_t no) { if (no >= value.size()) { return nullptr; // out of bounds } + std::string str = uuid::read_flash_string(value[no]); if (bool_format() == BOOL_FORMAT_ONOFF) { - strcpy(result, value[no].c_str()); + strcpy(result, str.c_str()); } else if (bool_format() == BOOL_FORMAT_TRUEFALSE) { - if (no == 0 && value[0] == "off") { + if (no == 0 && uuid::read_flash_string(value[0]) == "off") { strlcpy(result, "false", 7); - } else if (no == 1 && value[1] == "on") { + } else if (no == 1 && uuid::read_flash_string(value[1]) == "on") { strlcpy(result, "true", 6); } else { - strcpy(result, value[no].c_str()); + strcpy(result, str.c_str()); } } else { itoa(result, no); @@ -462,13 +463,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 std::vector & strs) { +bool Helpers::value2enum(const char * v, uint8_t & value, const std::vector strs) { if ((v == nullptr) || (strlen(v) == 0)) { return false; } std::string str = toLower(v); for (value = 0; value < strs.size(); value++) { - if ((strs[value] == "off" && str == "false") || (strs[value] == "on" && str == "true") || (str == strs[value]) || (v[0] == '0' + 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)) { return true; } } diff --git a/src/helpers.h b/src/helpers.h index 80e4ec171..ce4cdd584 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -39,7 +39,7 @@ class Helpers { static char * render_value(char * result, const int16_t value, const uint8_t format); static char * render_value(char * result, const char * value, uint8_t format); static char * render_boolean(char * result, bool value); - static char * render_enum(char * result, const std::vector & value, const uint8_t no); + static char * render_enum(char * result, const std::vector value, const uint8_t no); static char * hextoa(char * result, const uint8_t value); static std::string data_to_hex(const uint8_t * data, const uint8_t length); @@ -62,7 +62,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 std::vector & strs); + static bool value2enum(const char * v, uint8_t & value, const std::vector strs); static void bool_format(uint8_t bool_format) { bool_format_ = bool_format;