Skip to content

Commit

Permalink
fixes #354
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Feb 12, 2022
1 parent d00ac1f commit 20b876b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,10 @@ void EMSESP::reset_mqtt_ha() {
// this will also create the HA /config topic
// generate_values_json is called to build the device value (dv) object array
void EMSESP::publish_device_values(uint8_t device_type) {
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE_DYN); // use max size
JsonObject json = doc.to<JsonObject>();
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE_DYN);
JsonObject json;
bool need_publish = false;

bool nested = (Mqtt::is_nested());
bool nested = (Mqtt::is_nested());

// group by device type
for (const auto & emsdevice : emsdevices) {
Expand All @@ -572,10 +571,11 @@ void EMSESP::publish_device_values(uint8_t device_type) {

// if its a boiler, generate json for each group and publish it directly. not nested
if (device_type == DeviceType::BOILER) {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, DeviceValueTAG::TAG_BOILER_DATA, false, EMSdevice::OUTPUT_TARGET::MQTT)) {
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_BOILER_DATA), json);
}
doc.clear();
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, DeviceValueTAG::TAG_DEVICE_DATA_WW, false, EMSdevice::OUTPUT_TARGET::MQTT)) {
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_DEVICE_DATA_WW), json);
}
Expand All @@ -587,39 +587,42 @@ void EMSESP::publish_device_values(uint8_t device_type) {
// only publish the single master thermostat
if (emsdevice->device_id() == EMSESP::actual_master_thermostat()) {
if (nested) {
json = doc.to<JsonObject>();
need_publish |= emsdevice->generate_values(json, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::MQTT); // nested
} else {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, DeviceValueTAG::TAG_THERMOSTAT_DATA, false, EMSdevice::OUTPUT_TARGET::MQTT)) { // not nested
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_NONE), json);
}
doc.clear();
for (uint8_t hc_tag = DeviceValueTAG::TAG_HC1; hc_tag <= DeviceValueTAG::TAG_HC8; hc_tag++) {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, hc_tag, false, EMSdevice::OUTPUT_TARGET::MQTT)) { // not nested
Mqtt::publish(Mqtt::tag_to_topic(device_type, hc_tag), json);
}
doc.clear();
}
need_publish = false;
}
need_publish = false;

This comment has been minimized.

Copy link
@MichaelDvP

MichaelDvP Feb 13, 2022

Contributor

Why nested thermostat does not need publish? The position before was right.

This comment has been minimized.

Copy link
@proddy

proddy via email Feb 13, 2022

Author Contributor

This comment has been minimized.

Copy link
@proddy

proddy Feb 13, 2022

Author Contributor

and fixed. silly me.

}
}

// Mixer
else if (device_type == DeviceType::MIXER) {
if (nested) {
json = doc.to<JsonObject>();
need_publish |= emsdevice->generate_values(json, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::MQTT); // nested
} else {
for (uint8_t hc_tag = DeviceValueTAG::TAG_HC1; hc_tag <= DeviceValueTAG::TAG_WWC4; hc_tag++) {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, hc_tag, false, EMSdevice::OUTPUT_TARGET::MQTT)) { // not nested
Mqtt::publish(Mqtt::tag_to_topic(device_type, hc_tag), json);
}
doc.clear();
}
need_publish = false;
}

} else {
// for all other devices add the values to the json
json = doc.to<JsonObject>();
need_publish |= emsdevice->generate_values(json, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::MQTT); // nested
}
}
Expand Down

0 comments on commit 20b876b

Please sign in to comment.