diff --git a/src/core/command.cpp b/src/core/command.cpp index 72d4ae43c..463efe19a 100644 --- a/src/core/command.cpp +++ b/src/core/command.cpp @@ -298,6 +298,8 @@ const char * Command::get_attribute(const char * cmd) { return nullptr; } +// returns the attribute in the given JSON object as a key/value pair called api_data +// or errors if the attribute is not found bool Command::set_attribute(JsonObject output, const char * cmd, const char * attribute) { if (attribute == nullptr) { return true; @@ -309,7 +311,14 @@ bool Command::set_attribute(JsonObject output, const char * cmd, const char * at output["api_data"] = data; // always as a string return true; } - return EMSESP::return_not_found(output, attribute, cmd); // not found + + // not found + output.clear(); + + char error[100]; + snprintf(error, sizeof(error), "no %s in %s", attribute, cmd); + output["message"] = error; + return false; } // calls a command directly @@ -431,7 +440,8 @@ uint8_t Command::call(const uint8_t device_type, const char * command, const cha logger_.debug("%sCalled command %s", ro.c_str(), info_s); } else { if (id > 0) { - LOG_INFO(("%sCalled command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id); + (device_id) ? LOG_INFO(("%sCalled command %s with value %s and id %d on device 0x%02X"), ro.c_str(), info_s, value, id, device_id) + : LOG_INFO(("%sCalled command %s with value %s and id %d"), ro.c_str(), info_s, value, id); } else { LOG_INFO(("%sCalled command %s with value %s"), ro.c_str(), info_s, value); } @@ -481,7 +491,7 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ui for (auto & cf : cmdfunctions_) { if (Helpers::toLower(cmd) == Helpers::toLower(cf.cmd_) && (cf.device_type_ == device_type) && (!device_id || cf.device_id_ == device_id) - && (flag == CommandFlag::CMD_FLAG_DEFAULT || (flag & 0x3F) == (cf.flags_ & 0x3F))) { + && (cf.device_type_ < EMSdevice::DeviceType::BOILER || flag == CommandFlag::CMD_FLAG_DEFAULT || (flag & 0x3F) == (cf.flags_ & 0x3F))) { return &cf; } } @@ -639,9 +649,9 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo shell.print('*'); } shell.print(COLOR_RESET); + shell.println(); } } - shell.println(); } } diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index a188bc74c..8e73d40b6 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -813,15 +813,6 @@ bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8 return false; // not found } -// sends JSON error message, used with API calls -bool EMSESP::return_not_found(JsonObject output, const char * msg, const char * cmd) { - output.clear(); - char error[100]; - snprintf(error, sizeof(error), "no %s in %s", msg, cmd); - output["message"] = error; - return false; -} - // search for recognized device_ids : Me, All, otherwise print hex value std::string EMSESP::device_tostring(const uint8_t device_id) { if ((device_id & 0x7F) == EMSbus::ems_bus_id()) { diff --git a/src/core/emsesp.h b/src/core/emsesp.h index 5f659bbd4..7ae4915d0 100644 --- a/src/core/emsesp.h +++ b/src/core/emsesp.h @@ -222,8 +222,6 @@ class EMSESP { static void scan_devices(); static void clear_all_devices(); - static bool return_not_found(JsonObject output, const char * msg, const char * cmd); - static std::deque> emsdevices; // services