Synchronize access to account to avoid concurrency issues (#14128)

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer 2023-01-01 12:02:15 +01:00 committed by GitHub
parent 377dc86452
commit f588c07f3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -818,31 +818,34 @@ public class TeslaVehicleHandler extends BaseThingHandler {
if (authHeader != null) {
try {
// get a list of vehicles
Response response = account.vehiclesTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Authorization", authHeader).get();
synchronized (account.vehiclesTarget) {
Response response = account.vehiclesTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Authorization", authHeader).get();
logger.debug("Querying the vehicle, response : {}, {}", response.getStatus(),
response.getStatusInfo().getReasonPhrase());
logger.debug("Querying the vehicle, response : {}, {}", response.getStatus(),
response.getStatusInfo().getReasonPhrase());
if (!checkResponse(response, true)) {
logger.debug("An error occurred while querying the vehicle");
return null;
}
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();
Vehicle[] vehicleArray = gson.fromJson(jsonObject.getAsJsonArray("response"), Vehicle[].class);
for (Vehicle vehicle : vehicleArray) {
logger.debug("Querying the vehicle: VIN {}", vehicle.vin);
if (vehicle.vin.equals(getConfig().get(VIN))) {
vehicleJSON = gson.toJson(vehicle);
parseAndUpdate("queryVehicle", null, vehicleJSON);
if (logger.isTraceEnabled()) {
logger.trace("Vehicle is id {}/vehicle_id {}/tokens {}", vehicle.id, vehicle.vehicle_id,
vehicle.tokens);
}
return vehicle;
if (!checkResponse(response, true)) {
logger.debug("An error occurred while querying the vehicle");
return null;
}
JsonObject jsonObject = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject();
Vehicle[] vehicleArray = gson.fromJson(jsonObject.getAsJsonArray("response"), Vehicle[].class);
for (Vehicle vehicle : vehicleArray) {
logger.debug("Querying the vehicle: VIN {}", vehicle.vin);
if (vehicle.vin.equals(getConfig().get(VIN))) {
vehicleJSON = gson.toJson(vehicle);
parseAndUpdate("queryVehicle", null, vehicleJSON);
if (logger.isTraceEnabled()) {
logger.trace("Vehicle is id {}/vehicle_id {}/tokens {}", vehicle.id, vehicle.vehicle_id,
vehicle.tokens);
}
return vehicle;
}
}
}
} catch (ProcessingException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());