mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
added INVALID command return err, so detects when incorrect hc given in a command
This commit is contained in:
@@ -179,6 +179,8 @@ std::string Command::return_code_string(const uint8_t return_code) {
|
|||||||
return "Not Authorized";
|
return "Not Authorized";
|
||||||
case CommandRet::FAIL:
|
case CommandRet::FAIL:
|
||||||
return "Failed";
|
return "Failed";
|
||||||
|
case CommandRet::INVALID:
|
||||||
|
return "Invalid";
|
||||||
default:
|
default:
|
||||||
break;
|
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_);
|
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 ((value == nullptr) || (strlen(value) == 0)) {
|
||||||
if (EMSESP::system_.readonly_mode()) {
|
LOG_INFO(("%sCalling command %s"), ro.c_str(), info_s);
|
||||||
LOG_INFO(("[readonly] Calling command '%s/%s' (%s)"), dname, cmd, description);
|
|
||||||
} else {
|
|
||||||
LOG_DEBUG(("Calling command '%s/%s' (%s)"), dname, cmd, description);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (EMSESP::system_.readonly_mode()) {
|
if (id > 0) {
|
||||||
LOG_INFO(("[readonly] Calling command '%s/%s' (%s) with value %s"), dname, cmd, description, value);
|
LOG_INFO(("%sCalling command %s with value %s and id %d"), ro.c_str(), info_s, value, id);
|
||||||
} else {
|
} 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;
|
return_code = ((cf->cmdfunction_json_)(value, id, output)) ? CommandRet::OK : CommandRet::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cf->cmdfunction_ && !EMSESP::cmd_is_readonly(device_type, cmd, id)) {
|
// check if read-only. This also checks for valid tags (e.g. heating circuits)
|
||||||
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR;
|
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
|
// report back
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ enum CommandFlag : uint8_t {
|
|||||||
|
|
||||||
// return status after calling a Command
|
// return status after calling a Command
|
||||||
enum CommandRet : uint8_t {
|
enum CommandRet : uint8_t {
|
||||||
FAIL = 0, // 0 or FALSE
|
FAIL = 0, // 0 or FALSE
|
||||||
OK, // 1 or TRUE
|
OK, // 1 or TRUE
|
||||||
NOT_FOUND, // 2
|
NOT_FOUND, // 2
|
||||||
ERROR, // 3
|
ERROR, // 3
|
||||||
NOT_ALLOWED // needs authentication
|
NOT_ALLOWED, // 4 - needs authentication
|
||||||
|
INVALID // 5 - invalid (tag)
|
||||||
};
|
};
|
||||||
|
|
||||||
using cmd_function_p = std::function<bool(const char * data, const int8_t id)>;
|
using cmd_function_p = std::function<bool(const char * data, const int8_t id)>;
|
||||||
|
|||||||
Reference in New Issue
Block a user