]> git.basschouten.com Git - openhab-addons.git/commitdiff
Revert "[shelly] Always try to stop WebSocketClient (#15719)" (#15720)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sun, 8 Oct 2023 11:46:27 +0000 (13:46 +0200)
committerGitHub <noreply@github.com>
Sun, 8 Oct 2023 11:46:27 +0000 (13:46 +0200)
This reverts commit 72622a1409d143915b912de538083cf6bc7e1cc9.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java

index c1a9b67f84878c33ce25ebdf164e762272e0cb32..f25188faf17e778806eb0fcd0b5df1293884d162 100644 (file)
@@ -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() {
index faff2738ee27ef412aebf3579b567ea1eb3e4ec1..06159751ecd9c4b82c379136e657e4eadd9f7a37 100644 (file)
@@ -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