From b6eea715fa74e630283726d603f5e24f9f315a6f Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Sun, 10 Jan 2021 16:25:54 +0100 Subject: [PATCH] [mqtt] Only unsubscribe if we subscribed before (#9758) Fix for 9730 Signed-off-by: Jochen Klein --- .../org/openhab/binding/mqtt/discovery/TopicSubscribe.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/discovery/TopicSubscribe.java b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/discovery/TopicSubscribe.java index 10ac1d7c215..4c4624cc346 100644 --- a/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/discovery/TopicSubscribe.java +++ b/bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/discovery/TopicSubscribe.java @@ -53,8 +53,9 @@ public class TopicSubscribe implements MqttMessageSubscriber { @Override public void processMessage(String topic, byte[] payload) { final MqttBrokerConnection connection = this.connection; - if (connection == null) + if (connection == null) { return; + } if (payload.length > 0) { topicDiscoveredListener.receivedMessage(thing, connection, topic, payload); } else { @@ -80,7 +81,8 @@ public class TopicSubscribe implements MqttMessageSubscriber { * @return Completes with true if successful. Exceptionally otherwise. */ public CompletableFuture stop() { - CompletableFuture stopFuture = connection == null ? CompletableFuture.completedFuture(true) + CompletableFuture stopFuture = connection == null || !isStarted + ? CompletableFuture.completedFuture(true) : connection.unsubscribe(topic, this); isStarted = false; return stopFuture;