Revert "[shelly] Always try to stop WebSocketClient (#15719)" (#15720)

This reverts commit 72622a1409d143915b912de538083cf6bc7e1cc9.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2023-10-08 13:46:27 +02:00 committed by GitHub
parent 5a5cfc28fb
commit 94f2837fe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View 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() {

View 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