From 541b40474baf0b4f83e7834a61827c457a8b8c96 Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sat, 27 Jan 2024 20:11:08 +0100 Subject: [PATCH] [tesla] Adapt calls to new products API endpoint (#16331) Signed-off-by: Paul Smedley --- .../binding/tesla/internal/TeslaBindingConstants.java | 1 + .../binding/tesla/internal/handler/TeslaAccountHandler.java | 6 ++++-- .../binding/tesla/internal/handler/TeslaVehicleHandler.java | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaBindingConstants.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaBindingConstants.java index 351fdcd8c94..943e5e0f339 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaBindingConstants.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/TeslaBindingConstants.java @@ -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 diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java index 21267343d5e..59e92f8c61c 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaAccountHandler.java @@ -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()) { diff --git a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java index 7902f8eeaf0..b4af61a80b2 100644 --- a/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java +++ b/bundles/org.openhab.binding.tesla/src/main/java/org/openhab/binding/tesla/internal/handler/TeslaVehicleHandler.java @@ -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(),