mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +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;
|
const char * command_p = nullptr;
|
||||||
if (num_paths == 2) {
|
if (num_paths == 2) {
|
||||||
command_p = p.paths()[1].c_str();
|
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'
|
// concatenate the path into one string as it could be in the format 'hc/XXX'
|
||||||
char command[50];
|
char command[50];
|
||||||
snprintf(command, sizeof(command), "%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str());
|
snprintf(command, sizeof(command), "%s/%s", p.paths()[1].c_str(), p.paths()[2].c_str());
|
||||||
command_p = command;
|
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 {
|
} else {
|
||||||
// take it from the JSON
|
// take it from the JSON
|
||||||
if (input.containsKey("entity")) {
|
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) {
|
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, DALLASENSOR and ANALOGSENSOR, the other devices to 'values' for shortname version
|
// 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) {
|
if (device_type < EMSdevice::DeviceType::BOILER) {
|
||||||
command_p = "info";
|
command_p = "info";
|
||||||
} else {
|
} else {
|
||||||
@@ -187,7 +192,7 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
|
|||||||
if (command == nullptr) {
|
if (command == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
// make a copy of the string command for parsing
|
// make a copy of the string command for parsing
|
||||||
char command_s[30];
|
char command_s[30];
|
||||||
strlcpy(command_s, command, sizeof(command_s));
|
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) {
|
} else if (!strncmp(command, "wwc", 3) && start_pos == 5) {
|
||||||
id = command[start_pos - 2] - '0' + 8; // wwc1 has id 9
|
id = command[start_pos - 2] - '0' + 8; // wwc1 has id 9
|
||||||
} else {
|
} else {
|
||||||
id = 0; // special case for extracting the attributes
|
// id = 0; // special case for extracting the attributes
|
||||||
return command;
|
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
|
// calls a command directly
|
||||||
|
|||||||
@@ -920,14 +920,13 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8
|
|||||||
// make a copy of the string command for parsing
|
// make a copy of the string command for parsing
|
||||||
char command_s[30];
|
char command_s[30];
|
||||||
strlcpy(command_s, cmd, sizeof(command_s));
|
strlcpy(command_s, cmd, sizeof(command_s));
|
||||||
char * attribute_s = command_s;
|
char * attribute_s = nullptr;
|
||||||
|
|
||||||
// if id=0 then we have a specific attribute to fetch instead of the complete record
|
// check specific attribute to fetch instead of the complete record
|
||||||
if (id == 0) {
|
char * breakp = strchr(command_s, '/');
|
||||||
char * p = command_s;
|
if (breakp) {
|
||||||
char * breakp = strchr(p, '/');
|
*breakp = '\0';
|
||||||
if (breakp) {
|
if (strlen(breakp + 1)) {
|
||||||
*breakp = '\0';
|
|
||||||
attribute_s = breakp + 1;
|
attribute_s = breakp + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1073,8 +1072,8 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8
|
|||||||
json[value] = "not set";
|
json[value] = "not set";
|
||||||
}
|
}
|
||||||
|
|
||||||
// if id is 0 then we're filtering on an attribute, go find it
|
// if we're filtering on an attribute, go find it
|
||||||
if (id == 0) {
|
if (attribute_s) {
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
EMSESP::logger().debug(F("[DEBUG] Attribute '%s'"), attribute_s);
|
EMSESP::logger().debug(F("[DEBUG] Attribute '%s'"), attribute_s);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user