[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:
parent
22b28bf674
commit
c8cdd2dfa5
@ -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) {
|
public void connect(URI endpointURI) {
|
||||||
if (connectionState == ConnectionState.CONNECTED) {
|
if (connectionState == ConnectionState.CONNECTED) {
|
||||||
return;
|
return;
|
||||||
@ -114,7 +124,7 @@ public class TeslaEventEndpoint implements WebSocketListener, WebSocketPingPongL
|
|||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void closeConnection() {
|
||||||
try {
|
try {
|
||||||
connectionState = ConnectionState.CLOSING;
|
connectionState = ConnectionState.CLOSING;
|
||||||
if (session != null && session.isOpen()) {
|
if (session != null && session.isOpen()) {
|
||||||
|
|||||||
@ -1212,13 +1212,13 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
if (systemTimeStamp - currentTimeStamp > EVENT_TIMESTAMP_MAX_DELTA) {
|
if (systemTimeStamp - currentTimeStamp > EVENT_TIMESTAMP_MAX_DELTA) {
|
||||||
logger.trace("Event : The event endpoint will be reset");
|
logger.trace("Event : The event endpoint will be reset");
|
||||||
eventEndpoint.close();
|
eventEndpoint.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "data:error":
|
case "data:error":
|
||||||
logger.debug("Event : Received an error: '{}'/'{}'", event.value, event.error_type);
|
logger.debug("Event : Received an error: '{}'/'{}'", event.value, event.error_type);
|
||||||
eventEndpoint.close();
|
eventEndpoint.closeConnection();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1263,7 +1263,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
|||||||
"Event : Reached the maximum number of errors ({}) for the current interval ({} seconds)",
|
"Event : Reached the maximum number of errors ({}) for the current interval ({} seconds)",
|
||||||
EVENT_MAXIMUM_ERRORS_IN_INTERVAL, EVENT_ERROR_INTERVAL_SECONDS);
|
EVENT_MAXIMUM_ERRORS_IN_INTERVAL, EVENT_ERROR_INTERVAL_SECONDS);
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
|
||||||
eventEndpoint.close();
|
eventEndpoint.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((System.currentTimeMillis() - eventIntervalTimestamp) > 1000
|
if ((System.currentTimeMillis() - eventIntervalTimestamp) > 1000
|
||||||
@ -1301,6 +1301,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
logger.debug("Event : The event thread was interrupted");
|
logger.debug("Event : The event thread was interrupted");
|
||||||
|
eventEndpoint.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user