mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Synchronize access to account to avoid concurrency issues (#14128)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
parent
377dc86452
commit
f588c07f3a
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user