[tesla] Adapt calls to new products API endpoint (#16331)

Signed-off-by: Paul Smedley <paul@smedley.id.au>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Kai Kreuzer 2024-01-27 20:11:08 +01:00 committed by Ciprian Pascu
parent 1e9d41442e
commit f730fb66d8
3 changed files with 7 additions and 4 deletions

View File

@ -36,6 +36,7 @@ public class TeslaBindingConstants {
public static final String URI_OWNERS = "https://owner-api.teslamotors.com";
public static final String VALETPIN = "valetpin";
public static final String VEHICLES = "vehicles";
public static final String PRODUCTS = "products";
public static final String VIN = "vin";
// SSO URI constants

View File

@ -76,6 +76,7 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
// REST Client API variables
private final WebTarget teslaTarget;
WebTarget vehiclesTarget; // this cannot be marked final as it is used in the runnable
WebTarget productsTarget; // this cannot be marked final as it is used in the runnable
final WebTarget vehicleTarget;
final WebTarget dataRequestTarget;
final WebTarget commandTarget;
@ -107,6 +108,7 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
this.thingTypeMigrationService = thingTypeMigrationService;
this.vehiclesTarget = teslaTarget.path(API_VERSION).path(VEHICLES);
this.productsTarget = teslaTarget.path(API_VERSION).path(PRODUCTS);
this.vehicleTarget = vehiclesTarget.path(PATH_VEHICLE_ID);
this.dataRequestTarget = vehicleTarget.path(PATH_DATA_REQUEST).queryParam("endpoints",
"location_data;charge_state;climate_state;vehicle_state;gui_settings;vehicle_config");
@ -211,7 +213,7 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
if (authHeader != null) {
// get a list of vehicles
Response response = vehiclesTarget.request(MediaType.APPLICATION_JSON_TYPE)
Response response = productsTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Authorization", authHeader).get();
logger.debug("Querying the vehicle: Response: {}: {}", response.getStatus(),
@ -374,7 +376,7 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
if (authenticationResult.getStatus() == ThingStatus.ONLINE) {
// get a list of vehicles
Response response = vehiclesTarget.request(MediaType.APPLICATION_JSON_TYPE)
Response response = productsTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Authorization", "Bearer " + logonToken.access_token).get();
if (response != null && response.getStatus() == 200 && response.hasEntity()) {

View File

@ -791,8 +791,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
if (authHeader != null) {
try {
// get a list of vehicles
synchronized (account.vehiclesTarget) {
Response response = account.vehiclesTarget.request(MediaType.APPLICATION_JSON_TYPE)
synchronized (account.productsTarget) {
Response response = account.productsTarget.request(MediaType.APPLICATION_JSON_TYPE)
.header("Authorization", authHeader).get();
logger.debug("Querying the vehicle, response : {}, {}", response.getStatus(),