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 c1a9b67f8..f25188faf 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 faff2738e..06159751e 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