text changes

This commit is contained in:
proddy
2024-07-23 18:55:26 +02:00
parent 0d0d0aa111
commit 48b5970d28
6 changed files with 13 additions and 12 deletions

View File

@@ -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); 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; 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); auto cf = find_command(device_type, device_id, cmd, flag);
if (!cf) { if (!cf) {
std::string err = std::string("unknown command ") + cmd; 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)) { if (!single_command && EMSESP::cmd_is_readonly(device_type, device_id, cmd, id)) {
return_code = CommandRet::INVALID; // error on readonly or invalid hc return_code = CommandRet::INVALID; // error on readonly or invalid hc
} else { } else {
// call it... // call the command...
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR; 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); LOG_WARNING(error);
} else { } else {
if (single_command) { if (single_command) {
LOG_DEBUG(("%sCalling command %s"), ro.c_str(), info_s); LOG_DEBUG(("%sCalled command %s"), ro.c_str(), info_s);
} else { } else {
if (id > 0) { 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 { } 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);
} }
} }
} }

View File

@@ -575,11 +575,12 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
return; return;
} else { } else {
// show message if no data returned (e.g. for analogsensor, temperaturesensor, custom) // show message if no data returned (e.g. for analogsensor, temperaturesensor, custom)
shell.println("No data."); shell.println("No data returned.");
return; return;
} }
} }
if (return_code == CommandRet::NOT_FOUND) { if (return_code == CommandRet::NOT_FOUND) {
shell.println("Unknown command"); shell.println("Unknown command");
shell.print("Available commands are: "); shell.print("Available commands are: ");

View File

@@ -742,8 +742,8 @@ void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
buffer = nullptr; buffer = nullptr;
} }
// builds json with the detail of each value, for a given EMS device // builds json with the detail of each value, for a given device type
// for other types like sensors, scheduler, custom entities it will process single commands like 'info', 'values', 'commands', 'entities'... // 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) { bool EMSESP::get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype) {
// check first for EMS devices // check first for EMS devices
bool found_device = false; bool found_device = false;

View File

@@ -55,8 +55,9 @@ void WebAPIService::webAPIService(AsyncWebServerRequest * request, JsonVariant j
// HTTP GET // HTTP GET
JsonDocument input_doc; // has no body JSON so create dummy as empty input object JsonDocument input_doc; // has no body JSON so create dummy as empty input object
input = input_doc.to<JsonObject>(); input = input_doc.to<JsonObject>();
} else { } else {
// HTTP_POST | HTTP_PUT | HTTP_PATCH // HTTP_POST
input = json.as<JsonObject>(); // extract values from the json. these will be used as default values input = json.as<JsonObject>(); // extract values from the json. these will be used as default values
} }
parse(request, input); parse(request, input);

View File

@@ -245,7 +245,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
return_code = Command::call(device_type, cmd, data.as<bool>() ? "true" : "false", true, id, output); return_code = Command::call(device_type, cmd, data.as<bool>() ? "true" : "false", true, id, output);
} }
// write debug // write log
if (return_code != CommandRet::OK) { if (return_code != CommandRet::OK) {
EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code)); EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code));
} else { } else {

View File

@@ -604,7 +604,6 @@ void WebSchedulerService::test() {
test_value = "(custom/seltemp - boiler/flowtempoffset) * 2.8 + 5"; test_value = "(custom/seltemp - boiler/flowtempoffset) * 2.8 + 5";
command("test10", test_cmd.c_str(), compute(test_value).c_str()); 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 " test_cmd = "{\"method\":\"POST\",\"url\":\"http://192.168.1.42:8123/api/services/script/test_notify2\", \"header\":{\"authorization\":\"Bearer "
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhMmNlYWI5NDgzMmI0ODE2YWQ2NzU4MjkzZDE2YWMxZSIsImlhdCI6MTcyMTM5MTI0NCwiZXhwIjoyMDM2NzUxMjQ0fQ." "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhMmNlYWI5NDgzMmI0ODE2YWQ2NzU4MjkzZDE2YWMxZSIsImlhdCI6MTcyMTM5MTI0NCwiZXhwIjoyMDM2NzUxMjQ0fQ."
"S5sago1tEI6lNhrDCO0dM_WsVQHkD_laAjcks8tWAqo\"}}"; "S5sago1tEI6lNhrDCO0dM_WsVQHkD_laAjcks8tWAqo\"}}";