]> git.basschouten.com Git - openhab-addons.git/commitdiff
[shelly] Cancel the init job when the thing handler is disposed (#14290)
authorlolodomo <lg.hc@free.fr>
Mon, 30 Jan 2023 12:24:36 +0000 (13:24 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 12:24:36 +0000 (13:24 +0100)
Fix #14032

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java

index 1df31243e6895102a67b85cdabaf13d6f00248e8..c3bd77c34037c1379bfb95cf2abec4b06055aa08 100755 (executable)
@@ -119,6 +119,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
     private int skipUpdate = 0;
     private boolean refreshSettings = false;
     private @Nullable ScheduledFuture<?> statusJob;
+    private @Nullable ScheduledFuture<?> initJob;
 
     /**
      * Constructor
@@ -171,7 +172,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
     @Override
     public void initialize() {
         // start background initialization:
-        scheduler.schedule(() -> {
+        initJob = scheduler.schedule(() -> {
             boolean start = true;
             try {
                 initializeThingConfig();
@@ -1473,7 +1474,12 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
 
     public void stop() {
         logger.debug("{}: Shutting down", thingName);
-        ScheduledFuture<?> job = this.statusJob;
+        ScheduledFuture<?> job = this.initJob;
+        if (job != null) {
+            job.cancel(true);
+            initJob = null;
+        }
+        job = this.statusJob;
         if (job != null) {
             job.cancel(true);
             statusJob = null;