diff --git a/src/command.cpp b/src/command.cpp index d6d12fb88..16d9b1126 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -172,7 +172,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec } uint8_t device_type = EMSdevice::device_name_2_device_type(device_p); - if (CommandRet::OK != Command::call(device_type, data_s, "", true, id_d, output)) { + if (Command::call(device_type, data_s, "", true, id_d, output) != CommandRet::OK) { return CommandRet::INVALID; } @@ -334,7 +334,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * } } - // first see if there is a command registered and it's valid + // see if there is a command registered and it's valid auto cf = find_command(device_type, device_id, cmd, flag); if (!cf) { std::string err = std::string("unknown command ") + cmd; @@ -376,7 +376,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * if (!single_command && EMSESP::cmd_is_readonly(device_type, device_id, cmd, id)) { return_code = CommandRet::INVALID; // error on readonly or invalid hc } else { - // call it... + // call the command... return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR; } } @@ -394,12 +394,12 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * LOG_WARNING(error); } else { if (single_command) { - LOG_DEBUG(("%sCalling command %s"), ro.c_str(), info_s); + LOG_DEBUG(("%sCalled command %s"), ro.c_str(), info_s); } else { if (id > 0) { - LOG_INFO(("%sCalling 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 on device 0x%02X"), ro.c_str(), info_s, value, id, device_id); } else { - LOG_INFO(("%sCalling 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); } } } diff --git a/src/console.cpp b/src/console.cpp index 1067f592f..6d3eb7387 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -575,11 +575,12 @@ static void setup_commands(std::shared_ptr & commands) { return; } else { // show message if no data returned (e.g. for analogsensor, temperaturesensor, custom) - shell.println("No data."); + shell.println("No data returned."); return; } } + if (return_code == CommandRet::NOT_FOUND) { shell.println("Unknown command"); shell.print("Available commands are: "); diff --git a/src/emsesp.cpp b/src/emsesp.cpp index ba181a051..d085f8490 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -742,8 +742,8 @@ void EMSESP::publish_response(std::shared_ptr telegram) { buffer = nullptr; } -// builds json with the detail of each value, for a given EMS device -// for other types like sensors, scheduler, custom entities it will process single commands like 'info', 'values', 'commands', 'entities'... +// builds json with the detail of each value, for a given device type +// device type can be EMS devices looking for entities, or a sensor/scheduler/custom entity etc looking for values extracted from the info command bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype) { // check first for EMS devices bool found_device = false; diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index af835df54..e9c4d5608 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -55,8 +55,9 @@ void WebAPIService::webAPIService(AsyncWebServerRequest * request, JsonVariant j // HTTP GET JsonDocument input_doc; // has no body JSON so create dummy as empty input object input = input_doc.to(); + } else { - // HTTP_POST | HTTP_PUT | HTTP_PATCH + // HTTP_POST input = json.as(); // extract values from the json. these will be used as default values } parse(request, input); diff --git a/src/web/WebDataService.cpp b/src/web/WebDataService.cpp index 7cfb6b2f0..a423e5d0b 100644 --- a/src/web/WebDataService.cpp +++ b/src/web/WebDataService.cpp @@ -245,7 +245,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar return_code = Command::call(device_type, cmd, data.as() ? "true" : "false", true, id, output); } - // write debug + // write log if (return_code != CommandRet::OK) { EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code)); } else { diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index c52613cf5..bc56d6f7a 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -604,7 +604,6 @@ void WebSchedulerService::test() { test_value = "(custom/seltemp - boiler/flowtempoffset) * 2.8 + 5"; command("test10", test_cmd.c_str(), compute(test_value).c_str()); - // TODO add some more HTTP/URI tests test_cmd = "{\"method\":\"POST\",\"url\":\"http://192.168.1.42:8123/api/services/script/test_notify2\", \"header\":{\"authorization\":\"Bearer " "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhMmNlYWI5NDgzMmI0ODE2YWQ2NzU4MjkzZDE2YWMxZSIsImlhdCI6MTcyMTM5MTI0NCwiZXhwIjoyMDM2NzUxMjQ0fQ." "S5sago1tEI6lNhrDCO0dM_WsVQHkD_laAjcks8tWAqo\"}}";