From 935e04b266fc13f7bd770b956e7143503261d145 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 20 Feb 2022 13:40:58 +0100 Subject: [PATCH] fixes Excluding thermostat entities should also remove the climate discovery topic #368 --- src/emsdevice.h | 3 ++- src/emsesp.cpp | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/emsdevice.h b/src/emsdevice.h index 1ae6b8fce..721cf3010 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -245,7 +245,8 @@ class EMSdevice { void publish_value(void * value); void publish_all_values(); - void publish_mqtt_ha_entity_config(); + void mqtt_ha_entity_config_create(); + void mqtt_ha_entity_config_remove(); const std::string telegram_type_name(std::shared_ptr telegram); diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 5d99037c0..ff6badbfa 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -560,13 +560,18 @@ void EMSESP::publish_device_values(uint8_t device_type) { // group by device type for (const auto & emsdevice : emsdevices) { if (emsdevice && (emsdevice->device_type() == device_type)) { - // specially for HA + // specially for MQTT Discovery // we may have some RETAINED /config topics that reference fields in the data payloads that no longer exist // remove them immediately to prevent HA from complaining // we need to do this first before the data payload is published, and only done once! - if (Mqtt::ha_enabled() && emsdevice->ha_config_firstrun()) { - emsdevice->ha_config_clear(); - emsdevice->ha_config_firstrun(false); + if (Mqtt::ha_enabled()) { + if (emsdevice->ha_config_firstrun()) { + emsdevice->ha_config_clear(); + emsdevice->ha_config_firstrun(false); + } else { + // see if we need to delete and /config topics before adding the payloads + emsdevice->mqtt_ha_entity_config_remove(); + } } // if its a boiler, generate json for each group and publish it directly. not nested @@ -627,7 +632,7 @@ void EMSESP::publish_device_values(uint8_t device_type) { // we want to create the /config topic after the data payload to prevent HA from throwing up a warning if (Mqtt::ha_enabled()) { - emsdevice->publish_mqtt_ha_entity_config(); + emsdevice->mqtt_ha_entity_config_create(); } } }