mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-28 17:49:08 +03:00
Command returns as enum
This commit is contained in:
@@ -182,15 +182,15 @@ void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_
|
||||
uint8_t cmd_reply = Command::call(device_type, cmd_s.c_str(), (have_data ? value_s.c_str() : nullptr), authenticated, id_n, json);
|
||||
|
||||
// check for errors
|
||||
if (cmd_reply == 2) {
|
||||
if (cmd_reply == CommandRet::NOT_FOUND) {
|
||||
delete response;
|
||||
send_message_response(request, 400, "Command not found"); // Bad Request
|
||||
return;
|
||||
} else if (cmd_reply == 3) {
|
||||
} else if (cmd_reply == CommandRet::ERROR) {
|
||||
delete response;
|
||||
send_message_response(request, 400, "Problems parsing elements"); // Bad Request
|
||||
return;
|
||||
} else if (cmd_reply == 4) {
|
||||
} else if (cmd_reply == CommandRet::NOT_ALLOWED) {
|
||||
delete response;
|
||||
send_message_response(request, 401, "Bad credentials"); // Unauthorized
|
||||
return;
|
||||
|
||||
@@ -135,7 +135,7 @@ void WebDataService::write_value(AsyncWebServerRequest * request, JsonVariant &
|
||||
if (emsdevice->unique_id() == id) {
|
||||
const char * cmd = dv["c"];
|
||||
uint8_t device_type = emsdevice->device_type();
|
||||
uint8_t cmd_return = 1; // OK
|
||||
uint8_t cmd_return = CommandRet::OK;
|
||||
char s[10];
|
||||
// the data could be in any format, but we need string
|
||||
JsonVariant data = dv["v"];
|
||||
@@ -150,7 +150,7 @@ void WebDataService::write_value(AsyncWebServerRequest * request, JsonVariant &
|
||||
}
|
||||
|
||||
// send "Write command sent to device" or "Write command failed"
|
||||
AsyncWebServerResponse * response = request->beginResponse((cmd_return == 1) ? 200 : 204);
|
||||
AsyncWebServerResponse * response = request->beginResponse((cmd_return == CommandRet::OK) ? 200 : 204);
|
||||
request->send(response);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user