Skip to content

Commit

Permalink
fix bug when traversing ems devices when using cmd allvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Nov 14, 2023
1 parent 0f99415 commit 0b5a7b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ std::string EMSdevice::get_value_uom(const std::string & shortname) const {
return std::string{}; // not found
}

bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const int8_t id, const uint8_t output_target) {
bool EMSdevice::export_values(uint8_t unique_id, JsonObject & output, const int8_t id, const uint8_t output_target) {
bool has_value = false;
uint8_t tag;
if (id >= 1 && id <= (1 + DeviceValueTAG::TAG_HS16 - DeviceValueTAG::TAG_HC1)) {
Expand All @@ -830,7 +830,7 @@ bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const in

if (id > 0 || output_target == EMSdevice::OUTPUT_TARGET::API_VERBOSE) {
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice && (emsdevice->device_type() == device_type)) {
if (emsdevice->unique_id() == unique_id) {
has_value |= emsdevice->generate_values(output, tag, (id < 1), output_target); // use nested for id -1 and 0
}
}
Expand All @@ -842,7 +842,7 @@ bool EMSdevice::export_values(uint8_t device_type, JsonObject & output, const in
JsonObject output_hc = output;
bool nest_created = false;
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice && (emsdevice->device_type() == device_type)) {
if (emsdevice->unique_id() == unique_id) {
if (!nest_created && emsdevice->has_tags(tag)) {
output_hc = output.createNestedObject(EMSdevice::tag_to_mqtt(tag));
nest_created = true;
Expand Down
12 changes: 4 additions & 8 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,10 @@ bool System::command_allvalues(const char * value, const int8_t id, JsonObject &
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXXLARGE);
JsonObject device_output;

for (const auto & device_class : EMSFactory::device_handlers()) {
for (const auto & emsdevice : EMSESP::emsdevices) {
if (emsdevice->device_type() == device_class.first) {
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
device_output = output.createNestedObject(title);
emsesp::EMSdevice::export_values(emsdevice->device_type(), device_output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
}
}
for (const auto & emsdevice : EMSESP::emsdevices) {
std::string title = emsdevice->device_type_2_device_name_translated() + std::string(" ") + emsdevice->to_string();
device_output = output.createNestedObject(title);
emsesp::EMSdevice::export_values(emsdevice->unique_id(), device_output, id, EMSdevice::OUTPUT_TARGET::API_VERBOSE);
}

// Custom entities
Expand Down

0 comments on commit 0b5a7b9

Please sign in to comment.