]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt] Only unsubscribe if we subscribed before (#9758)
authorJochen Klein <git@jochen.susca.de>
Sun, 10 Jan 2021 15:25:54 +0000 (16:25 +0100)
committerGitHub <noreply@github.com>
Sun, 10 Jan 2021 15:25:54 +0000 (16:25 +0100)
Fix for 9730

Signed-off-by: Jochen Klein <git@jochen.susca.de>
bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/discovery/TopicSubscribe.java

index 10ac1d7c215f8615eeddb67f316f4829ad06b5ac..4c4624cc34605ca7bb9a27e9705f5307b3bb5c05 100644 (file)
@@ -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<Boolean> stop() {
-        CompletableFuture<Boolean> stopFuture = connection == null ? CompletableFuture.completedFuture(true)
+        CompletableFuture<Boolean> stopFuture = connection == null || !isStarted
+                ? CompletableFuture.completedFuture(true)
                 : connection.unsubscribe(topic, this);
         isStarted = false;
         return stopFuture;