Merge pull request #672 from proddy/dev

fix REST-API - strange characters in description
This commit is contained in:
Proddy
2022-10-09 19:41:46 +02:00
committed by GitHub
6 changed files with 25 additions and 7 deletions

View File

@@ -266,13 +266,13 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
if (EMSESP::system_.readonly_mode()) { if (EMSESP::system_.readonly_mode()) {
LOG_INFO(("[readonly] Calling command '%s/%s' (%s)"), dname.c_str(), cmd, cf->description_); LOG_INFO(("[readonly] Calling command '%s/%s' (%s)"), dname.c_str(), cmd, cf->description_);
} else { } 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 { } else {
if (EMSESP::system_.readonly_mode()) { if (EMSESP::system_.readonly_mode()) {
LOG_INFO(("[readonly] Calling command '%s/%s' (%s) with value %s"), dname.c_str(), cmd, cf->description_, value); LOG_INFO(("[readonly] Calling command '%s/%s' (%s) with value %s"), dname.c_str(), cmd, cf->description_, value);
} else { } 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 // list all commands for a specific device, output as json
bool Command::list(const uint8_t device_type, JsonObject & output) { bool Command::list(const uint8_t device_type, JsonObject & output) {
if (cmdfunctions_.empty()) { if (cmdfunctions_.empty()) {
output["message"] = "no commands available"; output["message"] = "no commands available";
return false; return false;

View File

@@ -93,8 +93,6 @@ class Command {
return cmdfunctions_; 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, 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); static uint8_t call(const uint8_t device_type, const char * cmd, const char * value);

View File

@@ -496,7 +496,7 @@ void EMSdevice::add_device_value(uint8_t tag,
// add the command to our library // add the command to our library
// cmd is the short_name and the description is the fullname (not the custom fullname) // 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 // single list of options

View File

@@ -719,4 +719,21 @@ std::string Helpers::translated_word(const char * const * strings, bool to_lower
return to_lower ? toLower((strings[index])) : (strings[index]); 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 } // namespace emsesp

View File

@@ -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 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 #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

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.5.0b5" #define EMSESP_APP_VERSION "3.5.0b6"