revert mqtt dev7 changes

This commit is contained in:
MichaelDvP
2026-08-19 11:49:29 +02:00
parent edd1677526
commit 469ca8bf05
+12 -14
View File
@@ -504,7 +504,7 @@ void Mqtt::on_disconnect(espMqttClientTypes::DisconnectReason reason) {
// MQTT on_connect - when an MQTT connect is established // MQTT on_connect - when an MQTT connect is established
void Mqtt::on_connect() { void Mqtt::on_connect() {
if (connecting_ || !connected()) { if (connecting_) {
return; // prevent duplicated connections and unsuccessful tries return; // prevent duplicated connections and unsuccessful tries
} }
@@ -513,19 +513,17 @@ void Mqtt::on_connect() {
connecting_ = true; connecting_ = true;
queuecount_ = mqttClient_->queueSize(); queuecount_ = mqttClient_->queueSize();
if (connectcount_ == 0) { // only on first connect and after reconfigure, HA messages are reain if (ha_enabled_) {
if (ha_enabled_) { queue_unsubscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#");
queue_unsubscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#"); EMSESP::reset_mqtt_ha(); // re-create all HA devices if there are any
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
ha_status(); // create the EMS-ESP device in HA, which is MQTT retained } else {
} else { // with disabled HA we subscribe and the broker sends all stored HA-emsesp-configs.
// 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")
// 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.
// If HA is enabled the subscriptions are removed. // As described in the doc (https://emsesp.org/Troubleshooting?id=home-assistant):
// 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.
// disable HA, wait 5 minutes (to allow the broker to send all), than reenable HA again. queue_subscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#");
queue_subscribe_message(discovery_prefix_ + "/+/" + Mqtt::basename() + "/#");
}
} }
// re-subscribe to all custom registered MQTT topics // re-subscribe to all custom registered MQTT topics