diff --git a/bundles/org.openhab.binding.tibber/pom.xml b/bundles/org.openhab.binding.tibber/pom.xml index 6b6b76244dbb7..fc8925de66143 100644 --- a/bundles/org.openhab.binding.tibber/pom.xml +++ b/bundles/org.openhab.binding.tibber/pom.xml @@ -1,4 +1,6 @@ - + + 4.0.0 diff --git a/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java b/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java index e9cfa029829e9..7317b5f89e35b 100755 --- a/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java +++ b/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java @@ -21,6 +21,7 @@ import java.net.URISyntaxException; import java.util.Properties; import java.util.concurrent.Executor; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -75,6 +76,7 @@ public class TibberHandler extends BaseThingHandler { private @Nullable Session session; private @Nullable WebSocketClient client; private @Nullable ScheduledFuture pollingJob; + private @Nullable Future sessionFuture; private String rtEnabled = "false"; public TibberHandler(Thing thing) { @@ -326,7 +328,7 @@ public void open() { } try { logger.debug("Connecting Websocket connection"); - client.connect(socket, new URI(SUBSCRIPTION_URL), newRequest); + sessionFuture = client.connect(socket, new URI(SUBSCRIPTION_URL), newRequest); } catch (IOException e) { logger.warn("Websocket Connect Exception: {}", e.getMessage()); } catch (URISyntaxException e) { @@ -354,6 +356,16 @@ public void close() { this.session = null; this.socket = null; } + if (sessionFuture != null && !sessionFuture.isDone()) { + sessionFuture.cancel(true); + } + if (client != null && client.isStarted()) { + try { + client.stop(); + } catch (Exception e) { + logger.warn("Failed to stop websocket client: {}", e.getMessage()); + } + } } public boolean isConnected() {