diff --git a/src/command.cpp b/src/command.cpp index d8c7b8406..3af705d56 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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 diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 981b4f9cd..581effa6c 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -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 char command_s[30]; 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 - if (id == 0) { - char * p = command_s; - char * breakp = strchr(p, '/'); - if (breakp) { - *breakp = '\0'; + // check specific attribute to fetch instead of the complete record + char * breakp = strchr(command_s, '/'); + if (breakp) { + *breakp = '\0'; + if (strlen(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"; } - // if id is 0 then we're filtering on an attribute, go find it - if (id == 0) { + // if we're filtering on an attribute, go find it + if (attribute_s) { #if defined(EMSESP_DEBUG) EMSESP::logger().debug(F("[DEBUG] Attribute '%s'"), attribute_s); #endif