From: Jacob Laursen Date: Sun, 8 Oct 2023 11:46:27 +0000 (+0200) Subject: Revert "[shelly] Always try to stop WebSocketClient (#15719)" (#15720) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=94f2837fe0a57185a06e0630642c77bdbb0422e3;p=openhab-addons.git Revert "[shelly] Always try to stop WebSocketClient (#15719)" (#15720) This reverts commit 72622a1409d143915b912de538083cf6bc7e1cc9. Signed-off-by: Jacob Laursen --- diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java index c1a9b67f84..f25188faf1 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java @@ -141,8 +141,10 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac rpcSocket.addMessageHandler(this); initialized = true; } else { - logger.debug("{}: Disconnect Rpc Socket on initialize", thingName); - disconnect(); + if (rpcSocket.isConnected()) { + logger.debug("{}: Disconnect Rpc Socket on initialize", thingName); + disconnect(); + } } } @@ -1215,7 +1217,9 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac } private void disconnect() { - rpcSocket.disconnect(); + if (rpcSocket.isConnected()) { + rpcSocket.disconnect(); + } } public Shelly2RpctInterface getRpcHandler() { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java index faff2738ee..06159751ec 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java @@ -211,7 +211,9 @@ public class Shelly2RpcSocket { s.close(StatusCode.NORMAL, "Socket closed"); session = null; } - client.stop(); + if (client.isStarted()) { + client.stop(); + } } catch (Exception e) { if (e.getCause() instanceof InterruptedException) { logger.debug("{}: Unable to close socket - interrupted", thingName); // e.g. device was rebooted