fix REST-API - strange characters in http://<hostname>/api/<device>/commands output #671

This commit is contained in:
Proddy
2022-10-09 14:18:29 +02:00
parent 324d27896b
commit 8d6c676fed
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()) {
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;

View File

@@ -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);

View File

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

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]);
}
// 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

View File

@@ -78,6 +78,8 @@ class Helpers {
static uint8_t count_items(const char * const * list);
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);

View File

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