mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
minor tidyups
This commit is contained in:
@@ -382,7 +382,7 @@ void DallasSensor::publish_values(const bool force) {
|
|||||||
JsonArray ids = dev.createNestedArray("ids");
|
JsonArray ids = dev.createNestedArray("ids");
|
||||||
ids.add("ems-esp");
|
ids.add("ems-esp");
|
||||||
|
|
||||||
char topic[100];
|
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
if (dallas_format == Mqtt::Dallas_Format::SENSORID) {
|
if (dallas_format == Mqtt::Dallas_Format::SENSORID) {
|
||||||
// use '_' as HA doesn't like '-' in the topic name
|
// use '_' as HA doesn't like '-' in the topic name
|
||||||
std::string topicname = sensor.to_string();
|
std::string topicname = sensor.to_string();
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ void Thermostat::register_mqtt_ha_config_hc(uint8_t hc_num) {
|
|||||||
doc["temp_cmd_t"] = str3;
|
doc["temp_cmd_t"] = str3;
|
||||||
doc["~"] = Mqtt::base(); // ems-esp
|
doc["~"] = Mqtt::base(); // ems-esp
|
||||||
|
|
||||||
char topic_t[80];
|
char topic_t[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
if (Mqtt::nested_format()) {
|
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());
|
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<JsonObject>()); // publish the config payload with retain flag
|
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
||||||
|
|
||||||
// enable the a special "thermostat_hc<n>" topic to take both mode strings and floats for each of the heating circuits
|
// enable the a special "thermostat_hc<n>" 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);
|
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); });
|
register_mqtt_topic(topic2, [=](const char * m) { return thermostat_ha_cmd(m, hc_num); });
|
||||||
|
|
||||||
|
|||||||
@@ -352,7 +352,6 @@ char * EMSdevice::show_telegram_handlers(char * result) {
|
|||||||
|
|
||||||
char str[10];
|
char str[10];
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
// for (const auto & tf : *telegram_functions_) {
|
|
||||||
for (const auto & tf : telegram_functions_) {
|
for (const auto & tf : telegram_functions_) {
|
||||||
snprintf_P(str, sizeof(str), PSTR("0x%02X"), tf.telegram_type_id_);
|
snprintf_P(str, sizeof(str), PSTR("0x%02X"), tf.telegram_type_id_);
|
||||||
strlcat(result, str, 200);
|
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/""
|
// 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());
|
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];
|
char name[80];
|
||||||
if (console) {
|
if (console) {
|
||||||
// prefix the tag in brackets, unless it's Boiler because we're naughty and use tag for the MQTT topic
|
// prefix the tag in brackets, unless it's Boiler because we're naughty and use tag for the MQTT topic
|
||||||
|
|||||||
@@ -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
|
// publish it under a single topic, only if we have data to publish
|
||||||
if (need_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());
|
snprintf_P(topic, sizeof(topic), PSTR("%s_data"), EMSdevice::device_type_2_device_name(device_type).c_str());
|
||||||
Mqtt::publish(topic, json);
|
Mqtt::publish(topic, json);
|
||||||
}
|
}
|
||||||
@@ -688,7 +688,7 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
|
|||||||
uint8_t product_id = telegram->message_data[offset]; // product ID
|
uint8_t product_id = telegram->message_data[offset]; // product ID
|
||||||
|
|
||||||
// get version as XX.XX
|
// 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]);
|
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
|
// some devices store the protocol type (HT3, Buderus) in the last byte
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
#define EMSESP_JSON_SIZE_XLARGE_DYN 4096 // for very very large json docs, using DynamicJsonDocument
|
#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
|
#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<const Telegram> t) { __f(t); } // for process function callbacks to register_telegram_type()
|
#define MAKE_PF_CB(__f) [&](std::shared_ptr<const Telegram> 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()
|
#define MAKE_CF_CB(__f) [&](const char * value, const int8_t id) { return __f(value, id); } // for command function callbacks to register_mqtt_cmd()
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ void Shower::send_mqtt_stat(bool state, bool force) {
|
|||||||
JsonArray ids = dev.createNestedArray("ids");
|
JsonArray ids = dev.createNestedArray("ids");
|
||||||
ids.add("ems-esp");
|
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());
|
snprintf_P(topic, sizeof(topic), PSTR("homeassistant/binary_sensor/%s/shower_active/config"), Mqtt::base().c_str());
|
||||||
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
Mqtt::publish_ha(topic, doc.as<JsonObject>()); // publish the config payload with retain flag
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user