From eaddae15a14f7435a401df3637d48b597d462b94 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 11 Oct 2020 17:09:26 +0200 Subject: [PATCH] formatting changes --- src/console.cpp | 6 +++--- src/devices/boiler.cpp | 13 ++++--------- src/devices/mixing.cpp | 11 +++++------ src/devices/thermostat.cpp | 6 +++--- src/mqtt.cpp | 8 ++++---- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index b87d2e667..68c9747dd 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -272,10 +272,10 @@ void EMSESPShell::add_console_commands() { uint16_t type_id = Helpers::hextoint(arguments[1].c_str()); EMSESP::set_read_id(type_id); if (arguments.size() == 3) { - uint16_t offset = Helpers::hextoint(arguments.back().c_str()); - EMSESP::send_read_request(type_id, device_id, offset); + uint16_t offset = Helpers::hextoint(arguments.back().c_str()); + EMSESP::send_read_request(type_id, device_id, offset); } else { - EMSESP::send_read_request(type_id, device_id); + EMSESP::send_read_request(type_id, device_id); } }); diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index d1bfedb82..43adae5fd 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -109,7 +109,6 @@ void Boiler::register_mqtt_ha_config() { Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWSetTemp), this->device_type(), "wWSetTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWDisinfectionTemp), this->device_type(), "wWDisinfectionTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(selFlowTemp), this->device_type(), "selFlowTemp", F_(degrees), F_(icontemperature)); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(selBurnPow), this->device_type(), "selBurnPow", F_(percent), nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(curBurnPow), this->device_type(), "curBurnPow", F_(percent), F_(iconpercent)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(pumpMod), this->device_type(), "pumpMod", F_(percent), F_(iconpercent)); @@ -119,7 +118,6 @@ void Boiler::register_mqtt_ha_config() { Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWCircPump), this->device_type(), "wWCircPump", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWCircPumpMode), this->device_type(), "wWCircPumpMode", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWCirc), this->device_type(), "wWCirc", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(outdoorTemp), this->device_type(), "outdoorTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWCurTemp), this->device_type(), "wWCurTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWCurTemp2), this->device_type(), "wWCurTemp2", F_(degrees), F_(icontemperature)); @@ -129,26 +127,22 @@ void Boiler::register_mqtt_ha_config() { Mqtt::register_mqtt_ha_sensor(nullptr, F_(switchTemp), this->device_type(), "switchTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(sysPress), this->device_type(), "sysPress", F_(bar), nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(boilTemp), this->device_type(), "boilTemp", F_(degrees), nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(burnGas), this->device_type(), "burnGas", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(flameCurr), this->device_type(), "flameCurr", F_(uA), nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(heatPump), this->device_type(), "heatPump", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(fanWork), this->device_type(), "fanWork", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(ignWork), this->device_type(), "ignWork", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWHeat), this->device_type(), "wWHeat", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(wwStorageTemp1), this->device_type(), "wwStorageTemp1", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wwStorageTemp2), this->device_type(), "wwStorageTemp2", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(exhaustTemp), this->device_type(), "exhaustTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWActivated), this->device_type(), "wWActivated", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWOneTime), this->device_type(), "wWOneTime", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWDisinfecting), this->device_type(), "wWDisinfecting", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWCharging), this->device_type(), "wWCharging", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWRecharging), this->device_type(), "wWRecharging", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWTempOK), this->device_type(), "wWTempOK", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(wWActive), this->device_type(), "wWActive", nullptr, nullptr); - Mqtt::register_mqtt_ha_sensor(nullptr, F_(heatingActivated), this->device_type(), "heatingActivated", nullptr, nullptr); Mqtt::register_mqtt_ha_sensor(nullptr, F_(heatingTemp), this->device_type(), "heatingTemp", F_(degrees), F_(icontemperature)); Mqtt::register_mqtt_ha_sensor(nullptr, F_(pumpModMax), this->device_type(), "pumpModMax", F_(percent), F_(iconpercent)); @@ -595,10 +589,11 @@ bool Boiler::export_values(JsonObject & output) { // publish values via MQTT void Boiler::publish_values(JsonObject & data) { - // must make sure this doesn't exist 1000. Currently (2.1.0) its 950b. - // otheerwise use DynamicJsonDocument with max size and use .shrinkToFit() + // Warning: must make sure the json size doesn't exceed 1024 bytes (it's currently 950b with 2.1.0b6) + // otherwise use should switch to using DynamicJsonDocument with max size followed by a shrinkToFit() StaticJsonDocument<1024> doc; - JsonObject output = doc.to(); + + JsonObject output = doc.to(); if (export_values(output)) { // see if we need to send out HA MQTT Discovery topics if ((Mqtt::mqtt_format() == Mqtt::Format::HA) && (!mqtt_ha_config_)) { diff --git a/src/devices/mixing.cpp b/src/devices/mixing.cpp index 5fdd33f62..7c4472b26 100644 --- a/src/devices/mixing.cpp +++ b/src/devices/mixing.cpp @@ -162,7 +162,6 @@ void Mixing::publish_values(JsonObject & data) { // publish config topic for HA MQTT Discovery void Mixing::register_mqtt_ha_config(const char * topic) { - // Create the Master device StaticJsonDocument doc; doc["name"] = F("EMS-ESP"); doc["uniq_id"] = F("mixing"); @@ -172,7 +171,7 @@ void Mixing::register_mqtt_ha_config(const char * topic) { snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), System::hostname().c_str(), topic); doc["stat_t"] = stat_t; - doc["val_tpl"] = F("{{value_json.pumpStatus}}"); + doc["val_tpl"] = F("{{value_json.type}}"); // HA needs a single value. We take the type which is wwc or hc JsonObject dev = doc.createNestedObject("dev"); dev["name"] = F("EMS-ESP Mixing"); dev["sw"] = EMSESP_APP_VERSION; @@ -215,7 +214,7 @@ bool Mixing::export_values(uint8_t mqtt_format, JsonObject & output) { output_hc = output.createNestedObject(hc_name); } else { output_hc = output; - output["type"] = "hc"; + output["type"] = F("hc"); } if (Helpers::hasValue(flowTemp_)) { output_hc["flowTemp"] = (float)flowTemp_ / 10; @@ -224,7 +223,7 @@ bool Mixing::export_values(uint8_t mqtt_format, JsonObject & output) { output_hc["flowSetTemp"] = flowSetTemp_; } if (Helpers::hasValue(pumpStatus_)) { - char s[5]; // for formatting strings + char s[5]; output_hc["pumpStatus"] = Helpers::render_value(s, pumpStatus_, EMS_VALUE_BOOL); } if (Helpers::hasValue(status_)) { @@ -236,13 +235,13 @@ bool Mixing::export_values(uint8_t mqtt_format, JsonObject & output) { output_hc = output.createNestedObject(hc_name); } else { output_hc = output; - output["type"] = "wwc"; + output["type"] = F("wwc"); } if (Helpers::hasValue(flowTemp_)) { output_hc["wwTemp"] = (float)flowTemp_ / 10; } if (Helpers::hasValue(pumpStatus_)) { - char s[5]; // for formatting strings + char s[5]; output_hc["pumpStatus"] = Helpers::render_value(s, pumpStatus_, EMS_VALUE_BOOL); } if (Helpers::hasValue(status_)) { diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 29135174e..bcb1413b1 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -1243,11 +1243,11 @@ void Thermostat::process_RC35Set(std::shared_ptr telegram) { changed_ |= telegram->read_value(hc->summertemp, 22); // is * 1 changed_ |= telegram->read_value(hc->nofrosttemp, 23); // is * 1 if (hc->heatingtype == 3) { - changed_ |= telegram->read_value(hc->designtemp, 36); // is * 1 + changed_ |= telegram->read_value(hc->designtemp, 36); // is * 1 } else { - changed_ |= telegram->read_value(hc->designtemp, 17); // is * 1 + changed_ |= telegram->read_value(hc->designtemp, 17); // is * 1 } - changed_ |= telegram->read_value(hc->offsettemp, 6); // is * 2 + changed_ |= telegram->read_value(hc->offsettemp, 6); // is * 2 changed_ |= telegram->read_value(hc->roominfluence, 4); // is * 1 } diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 5860141af..1468a30c9 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -772,9 +772,9 @@ void Mqtt::register_mqtt_ha_sensor(const char * prefix, char stat_t[50]; snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s_data"), hostname_.c_str(), device_name.c_str()); - // state template - char tpl[50]; - snprintf_P(tpl, sizeof(tpl), PSTR("{{value_json.%s}}"), new_entity); + // value template + char val_tpl[50]; + snprintf_P(val_tpl, sizeof(val_tpl), PSTR("{{value_json.%s}}"), new_entity); // ha device char ha_device[40]; @@ -787,7 +787,7 @@ void Mqtt::register_mqtt_ha_sensor(const char * prefix, doc["unit_of_meas"] = uom; } doc["stat_t"] = stat_t; - doc["val_tpl"] = tpl; + doc["val_tpl"] = val_tpl; if (icon != nullptr) { doc["ic"] = icon; }