mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
command executed only for commands without value, fix hcx custom names
This commit is contained in:
@@ -109,7 +109,9 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
|
|
||||||
// some commands may be prefixed with hc. dhw. or hc/ or dhw/ so extract these if they exist
|
// some commands may be prefixed with hc. dhw. or hc/ or dhw/ so extract these if they exist
|
||||||
// parse_command_string returns the extracted command
|
// parse_command_string returns the extracted command
|
||||||
|
if (device_type > EMSdevice::DeviceType::BOILER) {
|
||||||
command_p = parse_command_string(command_p, id_n);
|
command_p = parse_command_string(command_p, id_n);
|
||||||
|
}
|
||||||
if (command_p == nullptr) {
|
if (command_p == nullptr) {
|
||||||
// handle dead endpoints like api/system or api/boiler
|
// handle dead endpoints like api/system or api/boiler
|
||||||
// default to 'info' for SYSTEM, the other devices to 'values' for shortname version
|
// default to 'info' for SYSTEM, the other devices to 'values' for shortname version
|
||||||
@@ -159,7 +161,10 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
strlcpy(device_s, d, device_end - d + 1);
|
strlcpy(device_s, d, device_end - d + 1);
|
||||||
data_p = device_end + 1;
|
data_p = device_end + 1;
|
||||||
int8_t id_d = -1;
|
int8_t id_d = -1;
|
||||||
|
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
|
||||||
|
if (device_type > EMSdevice::DeviceType::BOILER) {
|
||||||
data_p = parse_command_string(data_p, id_d);
|
data_p = parse_command_string(data_p, id_d);
|
||||||
|
}
|
||||||
if (data_p == nullptr) {
|
if (data_p == nullptr) {
|
||||||
return CommandRet::INVALID;
|
return CommandRet::INVALID;
|
||||||
}
|
}
|
||||||
@@ -170,7 +175,6 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
strcat(data_s, "/value");
|
strcat(data_s, "/value");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t device_type = EMSdevice::device_name_2_device_type(device_p);
|
|
||||||
if (Command::call(device_type, data_s, "", true, id_d, output) != CommandRet::OK) {
|
if (Command::call(device_type, data_s, "", true, id_d, output) != CommandRet::OK) {
|
||||||
return CommandRet::INVALID;
|
return CommandRet::INVALID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,10 +532,14 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
int8_t id = -1;
|
int8_t id = -1;
|
||||||
const char * cmd = Command::parse_command_string(arguments[1].c_str(), id);
|
const char * cmd = Helpers::toLower(arguments[1]).c_str();
|
||||||
uint8_t return_code = CommandRet::OK;
|
uint8_t return_code = CommandRet::OK;
|
||||||
JsonObject json = doc.to<JsonObject>();
|
JsonObject json = doc.to<JsonObject>();
|
||||||
|
bool has_data = false;
|
||||||
|
|
||||||
|
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||||
|
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||||
|
}
|
||||||
if (cmd == nullptr) {
|
if (cmd == nullptr) {
|
||||||
cmd = device_type == EMSdevice::DeviceType::SYSTEM ? F_(info) : F_(values);
|
cmd = device_type == EMSdevice::DeviceType::SYSTEM ? F_(info) : F_(values);
|
||||||
}
|
}
|
||||||
@@ -550,6 +554,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
} else if (arguments[2] == "?") {
|
} else if (arguments[2] == "?") {
|
||||||
return_code = Command::call(device_type, cmd, nullptr, true, id, json);
|
return_code = Command::call(device_type, cmd, nullptr, true, id, json);
|
||||||
} else {
|
} else {
|
||||||
|
has_data = true;
|
||||||
// has a value but no id so use -1
|
// has a value but no id so use -1
|
||||||
return_code = Command::call(device_type, cmd, arguments.back().c_str(), true, id, json);
|
return_code = Command::call(device_type, cmd, arguments.back().c_str(), true, id, json);
|
||||||
}
|
}
|
||||||
@@ -558,6 +563,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
if (arguments[2] == "?") {
|
if (arguments[2] == "?") {
|
||||||
return_code = Command::call(device_type, cmd, nullptr, true, atoi(arguments[3].c_str()), json);
|
return_code = Command::call(device_type, cmd, nullptr, true, atoi(arguments[3].c_str()), json);
|
||||||
} else {
|
} else {
|
||||||
|
has_data = true;
|
||||||
return_code = Command::call(device_type, cmd, arguments[2].c_str(), true, atoi(arguments[3].c_str()), json);
|
return_code = Command::call(device_type, cmd, arguments[2].c_str(), true, atoi(arguments[3].c_str()), json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -572,10 +578,12 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
serializeJsonPretty(doc, shell);
|
serializeJsonPretty(doc, shell);
|
||||||
shell.println();
|
shell.println();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else if (has_data) {
|
||||||
// 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("Command executed. Check log for messages.");
|
shell.println("Command executed. Check log for messages.");
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (return_code == CommandRet::NOT_FOUND) {
|
} else if (return_code == CommandRet::NOT_FOUND) {
|
||||||
shell.println("Unknown command");
|
shell.println("Unknown command");
|
||||||
|
|||||||
@@ -221,10 +221,6 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
// using the unique ID from the web find the real device type
|
// using the unique ID from the web find the real device type
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice->unique_id() == unique_id) {
|
if (emsdevice->unique_id() == unique_id) {
|
||||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
|
||||||
int8_t id = -1; // default
|
|
||||||
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
|
||||||
|
|
||||||
// create JSON for output
|
// create JSON for output
|
||||||
auto * response = new AsyncJsonResponse(false);
|
auto * response = new AsyncJsonResponse(false);
|
||||||
JsonObject output = response->getRoot();
|
JsonObject output = response->getRoot();
|
||||||
@@ -233,6 +229,11 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
// authenticated is always true
|
// authenticated is always true
|
||||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
uint8_t return_code = CommandRet::NOT_FOUND;
|
||||||
uint8_t device_type = emsdevice->device_type();
|
uint8_t device_type = emsdevice->device_type();
|
||||||
|
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||||
|
int8_t id = -1; // default
|
||||||
|
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||||
|
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||||
|
}
|
||||||
if (data.is<const char *>()) {
|
if (data.is<const char *>()) {
|
||||||
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
||||||
} else if (data.is<int>()) {
|
} else if (data.is<int>()) {
|
||||||
@@ -263,13 +264,15 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
|
|
||||||
// special check for custom entities (which have a unique id of 99)
|
// special check for custom entities (which have a unique id of 99)
|
||||||
if (unique_id == 99) {
|
if (unique_id == 99) {
|
||||||
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
|
||||||
int8_t id = -1;
|
|
||||||
cmd = Command::parse_command_string(cmd, id);
|
|
||||||
auto * response = new AsyncJsonResponse(false);
|
auto * response = new AsyncJsonResponse(false);
|
||||||
JsonObject output = response->getRoot();
|
JsonObject output = response->getRoot();
|
||||||
uint8_t return_code = CommandRet::NOT_FOUND;
|
uint8_t return_code = CommandRet::NOT_FOUND;
|
||||||
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;
|
uint8_t device_type = EMSdevice::DeviceType::CUSTOM;
|
||||||
|
// parse the command as it could have a hc or dhw prefixed, e.g. hc2/seltemp
|
||||||
|
int8_t id = -1;
|
||||||
|
if (device_type >= EMSdevice::DeviceType::BOILER) {
|
||||||
|
cmd = Command::parse_command_string(cmd, id); // extract hc or dhw
|
||||||
|
}
|
||||||
if (data.is<const char *>()) {
|
if (data.is<const char *>()) {
|
||||||
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
||||||
} else if (data.is<int>()) {
|
} else if (data.is<int>()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user