mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-10 01:39:54 +03:00
allow id for attribute
This commit is contained in:
@@ -90,11 +90,16 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
const char * command_p = nullptr;
|
||||
if (num_paths == 2) {
|
||||
command_p = p.paths()[1].c_str();
|
||||
} else if (num_paths >= 3) {
|
||||
} else if (num_paths == 3) {
|
||||
// concatenate the path into one string as it could be in the format 'hc/XXX'
|
||||
char command[50];
|
||||
snprintf(command, sizeof(command), "%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str());
|
||||
command_p = command;
|
||||
} else if (num_paths > 3) {
|
||||
// concatenate the path into one string as it could be in the format 'hc/XXX'
|
||||
char command[50];
|
||||
snprintf(command, sizeof(command), "%s/%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str(), p.paths()[3].c_str());
|
||||
command_p = command;
|
||||
} else {
|
||||
// take it from the JSON
|
||||
if (input.containsKey("entity")) {
|
||||
@@ -110,7 +115,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
||||
if (command_p == nullptr) {
|
||||
// handle dead endpoints like api/system or api/boiler
|
||||
// default to 'info' for SYSTEM, DALLASENSOR and ANALOGSENSOR, the other devices to 'values' for shortname version
|
||||
if (num_paths < 3) {
|
||||
if (num_paths < (id_n > 0 ? 4 : 3)) {
|
||||
if (device_type < EMSdevice::DeviceType::BOILER) {
|
||||
command_p = "info";
|
||||
} else {
|
||||
@@ -187,7 +192,7 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
|
||||
if (command == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
// make a copy of the string command for parsing
|
||||
char command_s[30];
|
||||
strlcpy(command_s, command, sizeof(command_s));
|
||||
@@ -214,11 +219,29 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
|
||||
} else if (!strncmp(command, "wwc", 3) && start_pos == 5) {
|
||||
id = command[start_pos - 2] - '0' + 8; // wwc1 has id 9
|
||||
} else {
|
||||
id = 0; // special case for extracting the attributes
|
||||
// id = 0; // special case for extracting the attributes
|
||||
return command;
|
||||
}
|
||||
|
||||
return (command + start_pos);
|
||||
*/
|
||||
if (!strncmp(command, "hc", 2) && strlen(command) >= 3) {
|
||||
id = command[2] - '0';
|
||||
command += 3;
|
||||
} else if (!strncmp(command, "wwc", 3) && strlen(command) >= 4) {
|
||||
if (command[3] == '1' && command[4] == '0') {
|
||||
id = 19; // wwc10
|
||||
command += 5;
|
||||
} else {
|
||||
id = command[3] - '0' + 8; // wwc1 has id 9
|
||||
command += 4;
|
||||
}
|
||||
}
|
||||
if (command[0] == '/' || command[0] == '.' || command[0] == '_') {
|
||||
command++;
|
||||
}
|
||||
if (command[0] == '\0') {
|
||||
return nullptr;
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
// calls a command directly
|
||||
|
||||
Reference in New Issue
Block a user