mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
2. fix #865
This commit is contained in:
@@ -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);
|
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, 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 (num_paths < (id_n > 0 ? 4 : 3)) {
|
||||||
if (device_type == EMSdevice::DeviceType::SYSTEM) {
|
command_p = device_type == EMSdevice::DeviceType::SYSTEM ? F_(info) : F_(values);
|
||||||
command_p = F_(info);
|
|
||||||
} else {
|
|
||||||
command_p = F_(values);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return message(CommandRet::NOT_FOUND, "missing or bad command", output);
|
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
|
id_n += 8; // wwc1 has id 9
|
||||||
} else if (input.containsKey("id")) {
|
} else if (input.containsKey("id")) {
|
||||||
id_n = input["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)
|
#if defined(EMSESP_DEBUG)
|
||||||
LOG_DEBUG("[DEBUG] Calling %s command '%s' to retrieve attributes", dname, cmd);
|
LOG_DEBUG("[DEBUG] Calling %s command '%s' to retrieve attributes", dname, cmd);
|
||||||
#endif
|
#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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ bool EMSdevice::has_tag(const uint8_t tag) const {
|
|||||||
return false;
|
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 {
|
bool EMSdevice::has_cmd(const char * cmd, const int8_t id) const {
|
||||||
uint8_t tag = DeviceValueTAG::TAG_HC1 + id - 1;
|
uint8_t tag = DeviceValueTAG::TAG_HC1 + id - 1;
|
||||||
for (const auto & dv : devicevalues_) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -640,10 +640,12 @@ void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// builds json with the detail of each value, for a specific EMS device type or the dallas sensor
|
// 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) {
|
for (const auto & emsdevice : emsdevices) {
|
||||||
if (emsdevice->device_type() == devicetype && emsdevice->device_id() == device_id) {
|
if (emsdevice->device_type() == devicetype) {
|
||||||
return emsdevice->get_value_info(root, cmd, id);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char error[100];
|
||||||
|
snprintf(error, sizeof(error), "cannot find values for entity '%s'", cmd);
|
||||||
|
root["message"] = error;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ class EMSESP {
|
|||||||
static uint8_t count_devices();
|
static uint8_t count_devices();
|
||||||
static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id);
|
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_device_values(uuid::console::Shell & shell);
|
||||||
static void show_sensor_values(uuid::console::Shell & shell);
|
static void show_sensor_values(uuid::console::Shell & shell);
|
||||||
|
|||||||
Reference in New Issue
Block a user