From 469ca8bf05b9e7f7d560deee4ad24193aa8255e8 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Wed, 19 Aug 2026 11:49:29 +0200 Subject: [PATCH] revert mqtt dev7 changes --- src/core/mqtt.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index 9ca3405db..0115b210a 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -504,7 +504,7 @@ void Mqtt::on_disconnect(espMqttClientTypes::DisconnectReason reason) { // MQTT on_connect - when an MQTT connect is established void Mqtt::on_connect() { - if (connecting_ || !connected()) { + if (connecting_) { return; // prevent duplicated connections and unsuccessful tries } @@ -513,19 +513,17 @@ void Mqtt::on_connect() { connecting_ = true; queuecount_ = mqttClient_->queueSize(); - if (connectcount_ == 0) { // only on first connect and after reconfigure, HA messages are reain - if (ha_enabled_) { - queue_unsubscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#"); - EMSESP::reset_mqtt_ha(); // re-create all HA devices if there are any - ha_status(); // create the EMS-ESP device in HA, which is MQTT retained - } else { - // with disabled HA we subscribe and the broker sends all stored HA-emsesp-configs. - // Around line 272 they are removed (search for "// remove HA topics if we don't use discover") - // If HA is enabled the subscriptions are removed. - // As described in the doc (https://emsesp.org/Troubleshooting?id=home-assistant): - // disable HA, wait 5 minutes (to allow the broker to send all), than reenable HA again. - queue_subscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#"); - } + if (ha_enabled_) { + queue_unsubscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#"); + EMSESP::reset_mqtt_ha(); // re-create all HA devices if there are any + ha_status(); // create the EMS-ESP device in HA, which is MQTT retained + } else { + // with disabled HA we subscribe and the broker sends all stored HA-emsesp-configs. + // Around line 272 they are removed (search for "// remove HA topics if we don't use discover") + // If HA is enabled the subscriptions are removed. + // As described in the doc (https://emsesp.org/Troubleshooting?id=home-assistant): + // disable HA, wait 5 minutes (to allow the broker to send all), than reenable HA again. + queue_subscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#"); } // re-subscribe to all custom registered MQTT topics