Skip to content

Commit

Permalink
2. fix #865
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Dec 31, 2022
1 parent 5575084 commit b16a16d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 9 additions & 3 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
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;
}
}
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/emsesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b16a16d

Please sign in to comment.