From 1183db88b7b3ec3a5903d68227d4edd43de61820 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Fri, 26 Jul 2024 17:59:49 +0200 Subject: [PATCH] command executed only for commands without value, fix hcx custom names --- src/command.cpp | 10 +++++++--- src/console.cpp | 12 ++++++++++-- src/web/WebDataService.cpp | 17 ++++++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index b0ed8aa33..ad29ae25d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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; } diff --git a/src/console.cpp b/src/console.cpp index d733929a5..b9820008c 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -532,10 +532,14 @@ static void setup_commands(std::shared_ptr & 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(); + 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) { } 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) { 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) { 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"); diff --git a/src/web/WebDataService.cpp b/src/web/WebDataService.cpp index a423e5d0b..af89ab1ce 100644 --- a/src/web/WebDataService.cpp +++ b/src/web/WebDataService.cpp @@ -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()) { return_code = Command::call(device_type, cmd, data.as(), true, id, output); } else if (data.is()) { @@ -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()) { return_code = Command::call(device_type, cmd, data.as(), true, id, output); } else if (data.is()) {