mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
remove obsolete return_not_found()
This commit is contained in:
@@ -298,6 +298,8 @@ const char * Command::get_attribute(const char * cmd) {
|
|||||||
return nullptr;
|
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) {
|
bool Command::set_attribute(JsonObject output, const char * cmd, const char * attribute) {
|
||||||
if (attribute == nullptr) {
|
if (attribute == nullptr) {
|
||||||
return true;
|
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
|
output["api_data"] = data; // always as a string
|
||||||
return true;
|
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
|
// 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);
|
logger_.debug("%sCalled command %s", ro.c_str(), info_s);
|
||||||
} else {
|
} else {
|
||||||
if (id > 0) {
|
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 {
|
} else {
|
||||||
LOG_INFO(("%sCalled command %s with value %s"), ro.c_str(), info_s, value);
|
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_) {
|
for (auto & cf : cmdfunctions_) {
|
||||||
if (Helpers::toLower(cmd) == Helpers::toLower(cf.cmd_) && (cf.device_type_ == device_type) && (!device_id || cf.device_id_ == device_id)
|
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;
|
return &cf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -639,9 +649,9 @@ void Command::show(uuid::console::Shell & shell, uint8_t device_type, bool verbo
|
|||||||
shell.print('*');
|
shell.print('*');
|
||||||
}
|
}
|
||||||
shell.print(COLOR_RESET);
|
shell.print(COLOR_RESET);
|
||||||
|
shell.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shell.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -813,15 +813,6 @@ bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8
|
|||||||
return false; // not found
|
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
|
// search for recognized device_ids : Me, All, otherwise print hex value
|
||||||
std::string EMSESP::device_tostring(const uint8_t device_id) {
|
std::string EMSESP::device_tostring(const uint8_t device_id) {
|
||||||
if ((device_id & 0x7F) == EMSbus::ems_bus_id()) {
|
if ((device_id & 0x7F) == EMSbus::ems_bus_id()) {
|
||||||
|
|||||||
@@ -222,8 +222,6 @@ class EMSESP {
|
|||||||
static void scan_devices();
|
static void scan_devices();
|
||||||
static void clear_all_devices();
|
static void clear_all_devices();
|
||||||
|
|
||||||
static bool return_not_found(JsonObject output, const char * msg, const char * cmd);
|
|
||||||
|
|
||||||
static std::deque<std::unique_ptr<EMSdevice>> emsdevices;
|
static std::deque<std::unique_ptr<EMSdevice>> emsdevices;
|
||||||
|
|
||||||
// services
|
// services
|
||||||
|
|||||||
Reference in New Issue
Block a user