[tesla] Stop the WebSocket client when disposing the thing handler (#14483)

Fix #14341

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2023-03-07 20:50:37 +01:00 committed by GitHub
parent 22b28bf674
commit c8cdd2dfa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -75,6 +75,16 @@ public class TeslaEventEndpoint implements WebSocketListener, WebSocketPingPongL
}
}
public void close() {
try {
if (client.isRunning()) {
client.stop();
}
} catch (Exception e) {
logger.warn("An exception occurred while stopping the WebSocket client : {}", e.getMessage());
}
}
public void connect(URI endpointURI) {
if (connectionState == ConnectionState.CONNECTED) {
return;
@ -114,7 +124,7 @@ public class TeslaEventEndpoint implements WebSocketListener, WebSocketPingPongL
this.session = session;
}
public void close() {
public void closeConnection() {
try {
connectionState = ConnectionState.CLOSING;
if (session != null && session.isOpen()) {

View File

@ -1212,13 +1212,13 @@ public class TeslaVehicleHandler extends BaseThingHandler {
}
if (systemTimeStamp - currentTimeStamp > EVENT_TIMESTAMP_MAX_DELTA) {
logger.trace("Event : The event endpoint will be reset");
eventEndpoint.close();
eventEndpoint.closeConnection();
}
}
break;
case "data:error":
logger.debug("Event : Received an error: '{}'/'{}'", event.value, event.error_type);
eventEndpoint.close();
eventEndpoint.closeConnection();
break;
}
}
@ -1263,7 +1263,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
"Event : Reached the maximum number of errors ({}) for the current interval ({} seconds)",
EVENT_MAXIMUM_ERRORS_IN_INTERVAL, EVENT_ERROR_INTERVAL_SECONDS);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
eventEndpoint.close();
eventEndpoint.closeConnection();
}
if ((System.currentTimeMillis() - eventIntervalTimestamp) > 1000
@ -1301,6 +1301,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
if (Thread.interrupted()) {
logger.debug("Event : The event thread was interrupted");
eventEndpoint.close();
return;
}
}