diff --git a/src/command.cpp b/src/command.cpp index 8c6cd7019..6c8936976 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -179,6 +179,8 @@ std::string Command::return_code_string(const uint8_t return_code) { return "Not Authorized"; case CommandRet::FAIL: return "Failed"; + case CommandRet::INVALID: + return "Invalid"; default: break; } @@ -270,18 +272,22 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * } auto description = Helpers::translated_word(cf->description_); + char info_s[100]; + if (strlen(description)) { + snprintf(info_s, sizeof(info_s), "'%s/%s' (%s)", dname, cmd, description); + } else { + snprintf(info_s, sizeof(info_s), "'%s/%s'", dname, cmd); + } + + std::string ro = EMSESP::system_.readonly_mode() ? "[readonly] " : ""; if ((value == nullptr) || (strlen(value) == 0)) { - if (EMSESP::system_.readonly_mode()) { - LOG_INFO(("[readonly] Calling command '%s/%s' (%s)"), dname, cmd, description); - } else { - LOG_DEBUG(("Calling command '%s/%s' (%s)"), dname, cmd, description); - } + LOG_INFO(("%sCalling command %s"), ro.c_str(), info_s); } else { - if (EMSESP::system_.readonly_mode()) { - LOG_INFO(("[readonly] Calling command '%s/%s' (%s) with value %s"), dname, cmd, description, value); + if (id > 0) { + LOG_INFO(("%sCalling command %s with value %s and id %d"), ro.c_str(), info_s, value, id); } else { - LOG_DEBUG(("Calling command '%s/%s' (%s) with value %s"), dname, cmd, description, value); + LOG_INFO(("%sCalling command %s with value %s"), ro.c_str(), info_s, value); } } @@ -290,8 +296,13 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * return_code = ((cf->cmdfunction_json_)(value, id, output)) ? CommandRet::OK : CommandRet::ERROR; } - if (cf->cmdfunction_ && !EMSESP::cmd_is_readonly(device_type, cmd, id)) { - return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR; + // check if read-only. This also checks for valid tags (e.g. heating circuits) + if (cf->cmdfunction_) { + if (EMSESP::cmd_is_readonly(device_type, cmd, id)) { + return_code = CommandRet::INVALID; // readonly or invalid hc + } else { + return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR; + } } // report back diff --git a/src/command.h b/src/command.h index d131f0574..187a213d7 100644 --- a/src/command.h +++ b/src/command.h @@ -40,12 +40,12 @@ enum CommandFlag : uint8_t { // return status after calling a Command enum CommandRet : uint8_t { - FAIL = 0, // 0 or FALSE - OK, // 1 or TRUE - NOT_FOUND, // 2 - ERROR, // 3 - NOT_ALLOWED // needs authentication - + FAIL = 0, // 0 or FALSE + OK, // 1 or TRUE + NOT_FOUND, // 2 + ERROR, // 3 + NOT_ALLOWED, // 4 - needs authentication + INVALID // 5 - invalid (tag) }; using cmd_function_p = std::function;