mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
command executed only for commands without value, fix hcx custom names
This commit is contained in:
@@ -109,7 +109,9 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
|
||||
// some commands may be prefixed with hc. dhw. or hc/ or dhw/ so extract these if they exist
|
||||
// parse_command_string returns the extracted command
|
||||
command_p = parse_command_string(command_p, id_n);
|
||||
if (device_type > EMSdevice::DeviceType::BOILER) {
|
||||
command_p = parse_command_string(command_p, id_n);
|
||||
}
|
||||
if (command_p == nullptr) {
|
||||
// handle dead endpoints like api/system or api/boiler
|
||||
// default to 'info' for SYSTEM, the other devices to 'values' for shortname version
|
||||
@@ -159,7 +161,10 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
strlcpy(device_s, d, device_end - d + 1);
|
||||
data_p = device_end + 1;
|
||||
int8_t id_d = -1;
|
||||
data_p = parse_command_string(data_p, id_d);
|
||||
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
|
||||
if (device_type > EMSdevice::DeviceType::BOILER) {
|
||||
data_p = parse_command_string(data_p, id_d);
|
||||
}
|
||||
if (data_p == nullptr) {
|
||||
return CommandRet::INVALID;
|
||||
}
|
||||
@@ -170,7 +175,6 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
strcat(data_s, "/value");
|
||||
}
|
||||
|
||||
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
|
||||
if (Command::call(device_type, data_s, "", true, id_d, output) != CommandRet::OK) {
|
||||
return CommandRet::INVALID;
|
||||
}
|
||||
|
||||
@@ -532,10 +532,14 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
|
||||
JsonDocument doc;
|
||||
int8_t id = -1;
|
||||
const char * cmd = Command::parse_command_string(arguments[1].c_str(), id);
|
||||
const char * cmd = Helpers::toLower(arguments[1]).c_str();
|
||||
uint8_t return_code = CommandRet::OK;
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
bool has_data = false;
|
||||
|
||||
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||
}
|
||||
if (cmd == nullptr) {
|
||||
cmd = device_type == EMSdevice::DeviceType::SYSTEM ? F_(info) : F_(values);
|
||||
}
|
||||
@@ -550,6 +554,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
} else if (arguments[2] == "?") {
|
||||
return_code = Command::call(device_type, cmd, nullptr, true, id, json);
|
||||
} else {
|
||||
has_data = true;
|
||||
// has a value but no id so use -1
|
||||
return_code = Command::call(device_type, cmd, arguments.back().c_str(), true, id, json);
|
||||
}
|
||||
@@ -558,6 +563,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
if (arguments[2] == "?") {
|
||||
return_code = Command::call(device_type, cmd, nullptr, true, atoi(arguments[3].c_str()), json);
|
||||
} else {
|
||||
has_data = true;
|
||||
return_code = Command::call(device_type, cmd, arguments[2].c_str(), true, atoi(arguments[3].c_str()), json);
|
||||
}
|
||||
}
|
||||
@@ -572,10 +578,12 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
serializeJsonPretty(doc, shell);
|
||||
shell.println();
|
||||
return;
|
||||
} else {
|
||||
} else if (has_data) {
|
||||
// show message if no data returned (e.g. for analogsensor, temperaturesensor, custom)
|
||||
shell.println("Command executed. Check log for messages.");
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (return_code == CommandRet::NOT_FOUND) {
|
||||
shell.println("Unknown command");
|
||||
|
||||
@@ -221,10 +221,6 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
||||
// using the unique ID from the web find the real device type
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice->unique_id() == unique_id) {
|
||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||
int8_t id = -1; // default
|
||||
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||
|
||||
// create JSON for output
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject output = response->getRoot();
|
||||
@@ -233,6 +229,11 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
||||
// authenticated is always true
|
||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
||||
uint8_t device_type = emsdevice->device_type();
|
||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||
int8_t id = -1; // default
|
||||
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||
}
|
||||
if (data.is<const char *>()) {
|
||||
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
||||
} else if (data.is<int>()) {
|
||||
@@ -263,13 +264,15 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
||||
|
||||
// special check for custom entities (which have a unique id of 99)
|
||||
if (unique_id == 99) {
|
||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||
int8_t id = -1;
|
||||
cmd = Command::parse_command_string(cmd, id);
|
||||
auto * response = new AsyncJsonResponse(false);
|
||||
JsonObject output = response->getRoot();
|
||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
||||
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;
|
||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||
int8_t id = -1;
|
||||
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||
}
|
||||
if (data.is<const char *>()) {
|
||||
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
||||
} else if (data.is<int>()) {
|
||||
|
||||
Reference in New Issue
Block a user