value2enum texts from local_EN

This commit is contained in:
MichaelDvP
2021-04-01 16:31:56 +02:00
parent 45a6cd3606
commit 3bacfc3361
5 changed files with 42 additions and 37 deletions

View File

@@ -246,7 +246,7 @@ void Boiler::check_active(const bool force) {
if (heatingActive_ != val || force) { if (heatingActive_ != val || force) {
heatingActive_ = val; heatingActive_ = val;
char s[7]; 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 // 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) { if (tapwaterActive_ != val || force) {
tapwaterActive_ = val; tapwaterActive_ = val;
char s[7]; 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 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 // 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) { bool Boiler::set_warmwater_mode(const char * value, const int8_t id) {
uint8_t set; 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")); LOG_WARNING(F("Set boiler warm water mode: Invalid value"));
return false; return false;
} }
@@ -1114,11 +1114,11 @@ bool Boiler::set_reset(const char * value, const int8_t id) {
return false; return false;
} }
if (s == "maintenance") { if (s == Helpers::toLower(uuid::read_flash_string(F_(maintenance)))) {
LOG_INFO(F("Reset boiler maintenance message")); LOG_INFO(F("Reset boiler maintenance message"));
write_command(0x05, 0x08, 0xFF, 0x1C); write_command(0x05, 0x08, 0xFF, 0x1C);
return true; return true;
} else if (s == "error") { } else if (s == Helpers::toLower(uuid::read_flash_string(F_(error)))) {
LOG_INFO(F("Reset boiler error message")); LOG_INFO(F("Reset boiler error message"));
write_command(0x05, 0x00, 0x5A); // error reset write_command(0x05, 0x00, 0x5A); // error reset
return true; 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) { bool Boiler::set_maintenance(const char * value, const int8_t id) {
std::string s(12, '\0'); std::string s(12, '\0');
if (Helpers::value2string(value, s)) { 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")); LOG_INFO(F("Reset boiler maintenance message"));
write_command(0x05, 0x08, 0xFF, 0x1C); write_command(0x05, 0x08, 0xFF, 0x1C);
return true; return true;
@@ -1163,7 +1163,7 @@ bool Boiler::set_maintenance(const char * value, const int8_t id) {
} }
uint8_t num; 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); LOG_INFO(F("Setting maintenance type to %s"), value);
write_command(0x15, 0, num, 0x15); write_command(0x15, 0, num, 0x15);
return true; return true;

View File

@@ -1145,26 +1145,27 @@ bool Thermostat::set_remotetemp(const char * value, const int8_t id) {
// 0xA5 - Set the building settings // 0xA5 - Set the building settings
bool Thermostat::set_building(const char * value, const int8_t id) { bool Thermostat::set_building(const char * value, const int8_t id) {
uint8_t bd = 0; 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)) { 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 { } 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;
}
} }
LOG_WARNING(F("Set building: Invalid value"));
return true; return false;
} }
// 0xA5 Set the language settings // 0xA5 Set the language settings
bool Thermostat::set_language(const char * value, const int8_t id) { bool Thermostat::set_language(const char * value, const int8_t id) {
uint8_t lg = 0; 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")); LOG_WARNING(F("Set language: Invalid value"));
return false; 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 // Set the control-mode for hc 0-off, 1-RC20, 2-RC3x
bool Thermostat::set_control(const char * value, const int8_t id) { bool Thermostat::set_control(const char * value, const int8_t id) {
uint8_t ctrl = 0; 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")); LOG_WARNING(F("Set control: Invalid value"));
return false; return false;
} }
@@ -1200,14 +1201,14 @@ bool Thermostat::set_wwmode(const char * value, const int8_t id) {
uint8_t set = 0xFF; uint8_t set = 0xFF;
if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { 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")); LOG_WARNING(F("Set warm water mode: Invalid mode"));
return false; return false;
} }
LOG_INFO(F("Setting warm water mode to %s"), value); LOG_INFO(F("Setting warm water mode to %s"), value);
write_command(0x02F5, 2, set, 0x02F5); write_command(0x02F5, 2, set, 0x02F5);
} else { } 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")); LOG_WARNING(F("Set warm water mode: Invalid mode"));
return false; return false;
} }
@@ -1259,7 +1260,7 @@ bool Thermostat::set_wwcircmode(const char * value, const int8_t id) {
uint8_t set = 0xFF; uint8_t set = 0xFF;
if ((model() == EMS_DEVICE_FLAG_RC300) || (model() == EMS_DEVICE_FLAG_RC100)) { 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")); LOG_WARNING(F("Set warm water circulation mode: Invalid mode"));
return false; return false;
} }
@@ -1267,7 +1268,7 @@ bool Thermostat::set_wwcircmode(const char * value, const int8_t id) {
write_command(0x02F5, 3, set, 0x02F5); write_command(0x02F5, 3, set, 0x02F5);
return true; 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")); LOG_WARNING(F("Set warm water circulation mode: Invalid mode"));
return false; return false;
} }
@@ -1565,7 +1566,7 @@ bool Thermostat::set_summermode(const char * value, const int8_t id) {
return false; return false;
} }
uint8_t set = 0xFF; 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")); LOG_WARNING(F("Setting summer mode: Invalid mode"));
return false; return false;
} }
@@ -1583,7 +1584,7 @@ bool Thermostat::set_reducemode(const char * value, const int8_t id) {
return false; return false;
} }
uint8_t set = 0xFF; 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")); LOG_WARNING(F("Setting reduce mode: Invalid mode"));
return false; return false;
} }
@@ -1602,13 +1603,13 @@ bool Thermostat::set_controlmode(const char * value, const int8_t id) {
} }
uint8_t set = 0xFF; uint8_t set = 0xFF;
if (model() == EMS_DEVICE_FLAG_RC300 || model() == EMS_DEVICE_FLAG_RC100) { 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()); 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]); write_command(curve_typeids[hc->hc_num() - 1], 0, set, curve_typeids[hc->hc_num() - 1]);
return true; return true;
} }
} else if (model() == EMS_DEVICE_FLAG_RC35 || model() == EMS_DEVICE_FLAG_RC30_1) { } 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()); 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]); write_command(set_typeids[hc->hc_num() - 1], 33, set, set_typeids[hc->hc_num() - 1]);
return true; return true;

View File

@@ -126,9 +126,9 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
char * Helpers::render_boolean(char * result, bool value) { char * Helpers::render_boolean(char * result, bool value) {
uint8_t bool_format_ = Mqtt::bool_format(); uint8_t bool_format_ = Mqtt::bool_format();
if (bool_format_ == BOOL_FORMAT_ONOFF) { 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) { } 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) { } else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) {
strlcpy(result, value ? "true" : "false", 7); strlcpy(result, value ? "true" : "false", 7);
} else { } else {
@@ -457,12 +457,12 @@ bool Helpers::value2bool(const char * v, bool & value) {
std::string bool_str = toLower(v); // convert to lower case 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; value = true;
return true; // is a bool 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; value = false;
return true; // is a bool 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 // 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)) { if ((v == nullptr) || (strlen(v) == 0)) {
return false; return false;
} }
std::string str = toLower(v); std::string str = toLower(v);
for (value = 0; value < strs.size(); value++) { for (value = 0; strs[value]; value++) {
std::string str1 = uuid::read_flash_string(strs[value]); std::string str1 = toLower(uuid::read_flash_string(strs[value]));
if ((str1 == "off" && str == "false") || (str1 == "on" && str == "true") || (str == str1) || (v[0] == ('0' + value) && v[1] == '\0')) { 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; return true;
} }
} }

View File

@@ -65,7 +65,7 @@ class Helpers {
static bool value2float(const char * v, float & value); static bool value2float(const char * v, float & value);
static bool value2bool(const char * v, bool & value); static bool value2bool(const char * v, bool & value);
static bool value2string(const char * v, std::string & 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 #ifdef EMSESP_STANDALONE
static char * ultostr(char * ptr, uint32_t value, const uint8_t base); static char * ultostr(char * ptr, uint32_t value, const uint8_t base);

View File

@@ -257,7 +257,11 @@ MAKE_PSTR_LIST(enum_hamode, F_(off), F_(heat), F_(auto), F_(heat), F_(off), F_(h
//extra commands //extra commands
MAKE_PSTR(wwtapactivated, "wwtapactivated") MAKE_PSTR(wwtapactivated, "wwtapactivated")
MAKE_PSTR(maintenance, "maintenance") MAKE_PSTR(maintenance, "maintenance")
MAKE_PSTR(error, "error")
MAKE_PSTR(reset, "reset") MAKE_PSTR(reset, "reset")
// single mqtt topics
MAKE_PSTR(heating_active, "heating_active")
MAKE_PSTR(tapwater_active, "tapwater_active")
// mqtt, commands and text // mqtt, commands and text
// MAKE_PSTR_LIST(id, F("id"), F("id")) // MAKE_PSTR_LIST(id, F("id"), F("id"))
MAKE_PSTR_LIST(burnPeriod, F("burnperiod"), F("min burner periode")) MAKE_PSTR_LIST(burnPeriod, F("burnperiod"), F("min burner periode"))