diff --git a/src/command.cpp b/src/command.cpp index 53488f05e..41754ec45 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -266,13 +266,13 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * if (EMSESP::system_.readonly_mode()) { LOG_INFO(("[readonly] Calling command '%s/%s' (%s)"), dname.c_str(), cmd, cf->description_); } else { - LOG_DEBUG(("Calling command '%s/%s' (%s)"), dname.c_str(), cmd, (cf->description_)); + LOG_DEBUG(("Calling command '%s/%s' (%s)"), dname.c_str(), cmd, cf->description_); } } else { if (EMSESP::system_.readonly_mode()) { LOG_INFO(("[readonly] Calling command '%s/%s' (%s) with value %s"), dname.c_str(), cmd, cf->description_, value); } else { - LOG_DEBUG(("Calling command '%s/%s' (%s) with value %s"), dname.c_str(), cmd, (cf->description_), value); + LOG_DEBUG(("Calling command '%s/%s' (%s) with value %s"), dname.c_str(), cmd, cf->description_, value); } } @@ -348,6 +348,7 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ch // list all commands for a specific device, output as json bool Command::list(const uint8_t device_type, JsonObject & output) { + if (cmdfunctions_.empty()) { output["message"] = "no commands available"; return false; diff --git a/src/command.h b/src/command.h index 8fe24a8b8..098648ee1 100644 --- a/src/command.h +++ b/src/command.h @@ -93,8 +93,6 @@ class Command { return cmdfunctions_; } -#define add_ - static uint8_t call(const uint8_t device_type, const char * cmd, const char * value, const bool is_admin, const int8_t id, JsonObject & output); static uint8_t call(const uint8_t device_type, const char * cmd, const char * value); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index e20784109..7dadafc66 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -496,7 +496,7 @@ void EMSdevice::add_device_value(uint8_t tag, // add the command to our library // cmd is the short_name and the description is the fullname (not the custom fullname) - Command::add(device_type_, short_name, f, Helpers::translated_word(fullname).c_str(), flags); + Command::add(device_type_, short_name, f, Helpers::translated_fullname(fullname), flags); } // single list of options diff --git a/src/helpers.cpp b/src/helpers.cpp index 7e0ab3843..2a248bce2 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -719,4 +719,21 @@ std::string Helpers::translated_word(const char * const * strings, bool to_lower return to_lower ? toLower((strings[index])) : (strings[index]); } +// returns char pointer to translated description or fullname +const char * Helpers::translated_fullname(const char * const * strings) { + uint8_t language_index = EMSESP::system_.language_index(); + uint8_t index = 0; + + // check for empty + if (!strings) { + return nullptr; // it's a nullptr with no translations, return empty to prevent unwanted crash + } + + // see how many translations we have for this entity. if there is no translation for this, revert to EN + if (Helpers::count_items(strings) >= language_index + 1 && strlen(strings[language_index])) { + index = language_index; + } + return strings[index]; +} + } // namespace emsesp diff --git a/src/helpers.h b/src/helpers.h index 9f7efd9f7..0c164f283 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -77,7 +77,9 @@ class Helpers { static uint8_t count_items(const char * const ** list); static uint8_t count_items(const char * const * list); - static std::string translated_word(const char * const * strings, bool to_lower = false); + static std::string translated_word(const char * const * strings, bool to_lower = false); + static const char * translated_fullname(const char * const * strings); + #ifdef EMSESP_STANDALONE static char * ultostr(char * ptr, uint32_t value, const uint8_t base); diff --git a/src/version.h b/src/version.h index b6ae8f255..2947f8d8c 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.5.0b5" +#define EMSESP_APP_VERSION "3.5.0b6"