diff --git a/src/command.cpp b/src/command.cpp index 2686c3b7e..18ffb6a99 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -116,13 +116,9 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec command_p = parse_command_string(command_p, id_n); 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 + // default to 'info' for SYSTEM, the other devices to 'values' for shortname version if (num_paths < (id_n > 0 ? 4 : 3)) { - if (device_type == EMSdevice::DeviceType::SYSTEM) { - command_p = F_(info); - } else { - command_p = F_(values); - } + command_p = device_type == EMSdevice::DeviceType::SYSTEM ? F_(info) : F_(values); } else { return message(CommandRet::NOT_FOUND, "missing or bad command", output); } @@ -138,6 +134,9 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec id_n += 8; // wwc1 has id 9 } else if (input.containsKey("id")) { id_n = input["id"]; + } else if (input.containsKey("hs")) { + id_n = input["hs"]; + id_n += 18; // hs1 has id 19 } } @@ -271,7 +270,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * #if defined(EMSESP_DEBUG) LOG_DEBUG("[DEBUG] Calling %s command '%s' to retrieve attributes", dname, cmd); #endif - return EMSESP::get_device_value_info(output, cmd, id, device_type, device_id) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd + return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd } } diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 0186fb82b..f5b1d85dd 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -278,7 +278,7 @@ bool EMSdevice::has_tag(const uint8_t tag) const { return false; } -// check if the device has a command on the with this tag. +// check if the device has a command with this tag. bool EMSdevice::has_cmd(const char * cmd, const int8_t id) const { uint8_t tag = DeviceValueTAG::TAG_HC1 + id - 1; for (const auto & dv : devicevalues_) { @@ -1421,10 +1421,6 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8 } } - char error[100]; - snprintf(error, sizeof(error), "cannot find values for entity '%s'", cmd); - json["message"] = error; - return false; } diff --git a/src/emsesp.cpp b/src/emsesp.cpp index a976e80bf..d5710f42c 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -640,10 +640,12 @@ void EMSESP::publish_response(std::shared_ptr telegram) { } // builds json with the detail of each value, for a specific EMS device type or the dallas sensor -bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const int8_t id, const uint8_t devicetype, const uint8_t device_id) { +bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const int8_t id, const uint8_t devicetype) { for (const auto & emsdevice : emsdevices) { - if (emsdevice->device_type() == devicetype && emsdevice->device_id() == device_id) { - return emsdevice->get_value_info(root, cmd, id); + if (emsdevice->device_type() == devicetype) { + if (emsdevice->get_value_info(root, cmd, id)) { + return true; + } } } @@ -659,6 +661,10 @@ bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const in return true; } + char error[100]; + snprintf(error, sizeof(error), "cannot find values for entity '%s'", cmd); + root["message"] = error; + return false; } diff --git a/src/emsesp.h b/src/emsesp.h index 10f559d91..f5fcf8214 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -136,7 +136,7 @@ class EMSESP { static uint8_t count_devices(); static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id); - static bool get_device_value_info(JsonObject & root, const char * cmd, const int8_t id, const uint8_t devicetype, const uint8_t device_id); + static bool get_device_value_info(JsonObject & root, const char * cmd, const int8_t id, const uint8_t devicetype); static void show_device_values(uuid::console::Shell & shell); static void show_sensor_values(uuid::console::Shell & shell);