Skip to content

Commit

Permalink
Use tessie endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jun 16, 2024
1 parent 67e20ee commit 4e4b7c0
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,8 @@ export class VehicleAccessory {
}

async refresh(): Promise<void> {
this.vehicle
.vehicle_data([
"charge_state",
"climate_state",
"drive_state",
"location_data",
"vehicle_state",
])
.then((data) => {
this.platform.TeslaFleetApi.state(this.accessory.context.vin)
.then(({ charge_state, climate_state, drive_state, vehicle_state }) => {
this.accessory.context.state = "online";
this.accessory.context.charge_state = data.charge_state;
this.accessory.context.climate_state = data.climate_state;
Expand All @@ -110,18 +103,12 @@ export class VehicleAccessory {
if (this.accessory.context.state === "online") {
return Promise.resolve();
}
await this.vehicle.wake_up();

let interval = 2000;
for (let x = 0; x < 5; x++) {
await new Promise((resolve) => setTimeout(resolve, interval));
const { state } = await this.vehicle.vehicle();
this.accessory.context.state = state;
if (state === "online") {
return this.platform.TeslaFleetApi.wake(this.accessory.context.vin).then(awake => {
if (awake) {
this.accessory.context.state = "online";
return Promise.resolve();
}
interval = interval + 2000;
}
return Promise.reject("Vehicle didn't wake up");
return Promise.reject("Vehicle did not wake up");
});
}
}

0 comments on commit 4e4b7c0

Please sign in to comment.