From e22a46ae341ab7d6ac883182bf52d0efb95ba2ea Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 30 Jan 2023 13:24:36 +0100 Subject: [PATCH] [shelly] Cancel the init job when the thing handler is disposed (#14290) Fix #14032 Signed-off-by: Laurent Garnier --- .../shelly/internal/handler/ShellyBaseHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java index 7143a4d5a64ef..5c1b4c2095114 100755 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java @@ -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 boolean checkRepresentation(String key) { @Override public void initialize() { // start background initialization: - scheduler.schedule(() -> { + initJob = scheduler.schedule(() -> { boolean start = true; try { initializeThingConfig(); @@ -1473,7 +1474,12 @@ public void triggerChannel(String group, String channel, String payload) { 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;