Skip to content

Commit

Permalink
[tesla] Adapt calls to new products API endpoint (openhab#16331)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Smedley <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
  • Loading branch information
kaikreuzer authored and austvik committed Mar 27, 2024
1 parent b8627bb commit 0934d1a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +108,7 @@ public TeslaAccountHandler(Bridge bridge, Client teslaClient, HttpClientFactory
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");
Expand Down Expand Up @@ -211,7 +213,7 @@ protected Vehicle[] queryVehicles() {

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(),
Expand Down Expand Up @@ -374,7 +376,7 @@ protected String invokeAndParse(String vehicleId, String command, String payLoad

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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ protected Vehicle queryVehicle() {
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(),
Expand Down

0 comments on commit 0934d1a

Please sign in to comment.