From 73b805b1153edd39543c1d9704069f862e76a061 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Sat, 5 Feb 2022 08:32:56 +1000 Subject: [PATCH] [mqtt] connectionStateChanged(CONNECTED) called twice (#12200) Signed-off-by: Jimmy Tanagra --- .../binding/mqtt/handler/AbstractBrokerHandler.java | 2 -- .../org/openhab/binding/mqtt/handler/BrokerHandler.java | 7 +++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java index 6eb28d782..f68f65f69 100644 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java +++ b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/AbstractBrokerHandler.java @@ -114,8 +114,6 @@ public abstract class AbstractBrokerHandler extends BaseBridgeHandler implements }).thenAccept(v -> { if (!v) { connectionStateChanged(MqttConnectionState.DISCONNECTED, new TimeoutException("Timeout")); - } else { - connectionStateChanged(MqttConnectionState.CONNECTED, null); } }); connectionFuture.complete(connection); diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/BrokerHandler.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/BrokerHandler.java index d7cf35686..c48da5ccd 100644 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/BrokerHandler.java +++ b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/BrokerHandler.java @@ -59,19 +59,18 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba @Override public void connectionStateChanged(MqttConnectionState state, @Nullable Throwable error) { super.connectionStateChanged(state, error); - // Store generated client ID if none was set by the user final MqttBrokerConnection connection = this.connection; - String clientID = config.clientID; if (connection != null && state == MqttConnectionState.CONNECTED) { + String clientID = config.clientID; if (clientID == null || clientID.isBlank()) { + // Store generated client ID if none was set by the user clientID = connection.getClientId(); config.clientID = clientID; Configuration editConfig = editConfiguration(); editConfig.put("clientid", clientID); updateConfiguration(editConfig); - } else { - publish(config.birthTopic, config.birthMessage, config.birthRetain); } + publish(config.birthTopic, config.birthMessage, config.birthRetain); } }