From 355b71cacfb20cc70d3f9006c02037d889374d1b Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 22 Mar 2021 09:23:57 +0100 Subject: [PATCH] minor tidyups --- src/dallassensor.cpp | 2 +- src/devices/thermostat.cpp | 4 ++-- src/emsdevice.cpp | 3 --- src/emsesp.cpp | 4 ++-- src/emsesp.h | 2 +- src/shower.cpp | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index c30939cb9..7cf472cbe 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -382,7 +382,7 @@ void DallasSensor::publish_values(const bool force) { JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp"); - char topic[100]; + char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; if (dallas_format == Mqtt::Dallas_Format::SENSORID) { // use '_' as HA doesn't like '-' in the topic name std::string topicname = sensor.to_string(); diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 42dfe4f0a..41c223f76 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -377,7 +377,7 @@ void Thermostat::register_mqtt_ha_config_hc(uint8_t hc_num) { doc["temp_cmd_t"] = str3; doc["~"] = Mqtt::base(); // ems-esp - char topic_t[80]; + char topic_t[Mqtt::MQTT_TOPIC_MAX_SIZE]; if (Mqtt::nested_format()) { snprintf_P(topic_t, sizeof(topic_t), PSTR("~/%s"), Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str()); @@ -428,7 +428,7 @@ void Thermostat::register_mqtt_ha_config_hc(uint8_t hc_num) { Mqtt::publish_ha(topic, doc.as()); // publish the config payload with retain flag // enable the a special "thermostat_hc" topic to take both mode strings and floats for each of the heating circuits - std::string topic2(100, '\0'); + std::string topic2(Mqtt::MQTT_TOPIC_MAX_SIZE, '\0'); snprintf_P(&topic2[0], topic2.capacity() + 1, PSTR("thermostat_hc%d"), hc_num); register_mqtt_topic(topic2, [=](const char * m) { return thermostat_ha_cmd(m, hc_num); }); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 10629f487..b9403db0d 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -352,7 +352,6 @@ char * EMSdevice::show_telegram_handlers(char * result) { char str[10]; uint8_t i = 0; - // for (const auto & tf : *telegram_functions_) { for (const auto & tf : telegram_functions_) { snprintf_P(str, sizeof(str), PSTR("0x%02X"), tf.telegram_type_id_); strlcat(result, str, 200); @@ -572,8 +571,6 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter // we have a tag if it matches the filter given, and that the tag name is not empty/"" bool have_tag = ((dv.tag != tag_filter) && !tag_to_string(dv.tag).empty()); - // EMSESP::logger().info(F("**HERE: console=%d nested=%d tag_filter=%d tag=%d type=%d short=%s"), console, nested, tag_filter, dv.tag, dv.type, uuid::read_flash_string(dv.short_name).c_str()); - char name[80]; if (console) { // prefix the tag in brackets, unless it's Boiler because we're naughty and use tag for the MQTT topic diff --git a/src/emsesp.cpp b/src/emsesp.cpp index c573447cc..8589c7b48 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -486,7 +486,7 @@ void EMSESP::publish_device_values(uint8_t device_type) { // publish it under a single topic, only if we have data to publish if (need_publish) { - char topic[20]; + char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; snprintf_P(topic, sizeof(topic), PSTR("%s_data"), EMSdevice::device_type_2_device_name(device_type).c_str()); Mqtt::publish(topic, json); } @@ -688,7 +688,7 @@ void EMSESP::process_version(std::shared_ptr telegram) { uint8_t product_id = telegram->message_data[offset]; // product ID // get version as XX.XX - std::string version(5, '\0'); + std::string version(6, '\0'); snprintf_P(&version[0], version.capacity() + 1, PSTR("%02d.%02d"), telegram->message_data[offset + 1], telegram->message_data[offset + 2]); // some devices store the protocol type (HT3, Buderus) in the last byte diff --git a/src/emsesp.h b/src/emsesp.h index 99f0cdc55..581849c65 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -63,7 +63,7 @@ #define EMSESP_JSON_SIZE_XLARGE_DYN 4096 // for very very large json docs, using DynamicJsonDocument #define EMSESP_JSON_SIZE_XXLARGE_DYN 5120 // for extra very very large json docs, using DynamicJsonDocument -// helpers for call back functions +// helpers for callback functions #define MAKE_PF_CB(__f) [&](std::shared_ptr t) { __f(t); } // for process function callbacks to register_telegram_type() #define MAKE_CF_CB(__f) [&](const char * value, const int8_t id) { return __f(value, id); } // for command function callbacks to register_mqtt_cmd() diff --git a/src/shower.cpp b/src/shower.cpp index 9454a7662..838edbae8 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -114,7 +114,7 @@ void Shower::send_mqtt_stat(bool state, bool force) { JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp"); - char topic[100]; + char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; snprintf_P(topic, sizeof(topic), PSTR("homeassistant/binary_sensor/%s/shower_active/config"), Mqtt::base().c_str()); Mqtt::publish_ha(topic, doc.as()); // publish the config payload with retain flag }