Skip to content

Commit

Permalink
Fix wake_up
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jun 18, 2024
1 parent 250e199 commit 99223c3
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/vehicle-services/chargecurrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ChargeCurrentService extends BaseService {
async setLevel(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
value = Math.max(this.min, Math.min(this.max, value as number));

await this.parent.vehicle.wake_up()
await this.accessory.wakeUpAndWait()

Check failure on line 33 in src/vehicle-services/chargecurrent.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Property 'wakeUpAndWait' does not exist on type 'PlatformAccessory<VehicleContext>'.

Check failure on line 33 in src/vehicle-services/chargecurrent.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Property 'wakeUpAndWait' does not exist on type 'PlatformAccessory<VehicleContext>'.
.then(() => this.parent.vehicle.set_charging_amps(value))
.then(() => characteristic.updateValue(value));
}
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle-services/chargelimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ChargeLimitService extends BaseService {

async setLevel(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
value = Math.max(this.min, Math.min(this.max, value as number));
await this.vehicle.wake_up()
await this.accessory.wakeUpAndWait()

Check failure on line 33 in src/vehicle-services/chargelimit.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Property 'wakeUpAndWait' does not exist on type 'PlatformAccessory<VehicleContext>'.

Check failure on line 33 in src/vehicle-services/chargelimit.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Property 'wakeUpAndWait' does not exist on type 'PlatformAccessory<VehicleContext>'.
.then(() => this.vehicle.set_charge_limit(value))
.then(() => characteristic.updateValue(value));
}
Expand Down
10 changes: 4 additions & 6 deletions src/vehicle-services/chargeport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ export class ChargePortService extends BaseService {
const targetState = this.service
.getCharacteristic(this.parent.platform.Characteristic.LockTargetState)
//.onGet(this.getState.bind(this))
.onSet((value) => this.setState(value, targetState));
.onSet((value) => this.setState(value, currentState)); // Set current instead

this.parent.emitter.on("vehicle_data", (data) => {
const state = (data.charge_state.charge_port_latch === "Engaged") ?
this.platform.Characteristic.LockTargetState.SECURED :
this.platform.Characteristic.LockTargetState.UNSECURED;
const state = (data.charge_state.charge_port_latch === "Engaged") ? 1 : 0;
currentState.updateValue(state);
targetState.updateValue(state);
});
}

async setState(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
await this.vehicle.wake_up().then(() =>
value === this.parent.platform.Characteristic.LockTargetState.SECURED ?
await this.accessory.wakeUpAndWait().then(() =>

Check failure on line 26 in src/vehicle-services/chargeport.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Property 'wakeUpAndWait' does not exist on type 'PlatformAccessory<VehicleContext>'.

Check failure on line 26 in src/vehicle-services/chargeport.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Property 'wakeUpAndWait' does not exist on type 'PlatformAccessory<VehicleContext>'.
value === 1 ?
this.vehicle.charge_port_door_close()
.then(() =>
characteristic.updateValue(this.parent.platform.Characteristic.LockTargetState.SECURED)
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle-services/chargeswitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ChargeSwitchService extends BaseService {
}

async setOn(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
await this.parent.wake_up().then(() =>
await this.parent.wakeUpAndWait().then(() =>
value ? this.parent.vehicle.charge_start().then(() => characteristic.updateValue(value))
: this.parent.vehicle.charge_stop().then(() => characteristic.updateValue(value))
);
Expand Down
4 changes: 2 additions & 2 deletions src/vehicle-services/climate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ClimateService extends BaseService {
}

async setTargetState(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
await this.vehicle.wake_up()
await this.parent.wakeUpAndWait()
.then(() => value
? this.vehicle
.auto_conditioning_start()
Expand All @@ -80,7 +80,7 @@ export class ClimateService extends BaseService {
}

async setTargetTemp(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
await this.vehicle.wake_up().then(() =>
await this.parent.wakeUpAndWait().then(() =>
this.vehicle.set_temps(value as number, value as number)
.then(() => characteristic.updateValue(value)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle-services/door.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class DoorService extends BaseService {
(!this.open && value > 50) ||
(this.open && value < 50 && this.trunk === "rear")
) {
this.vehicle.wake_up()
this.parent.wakeUpAndWait()
.then(() => this.parent.vehicle.actuate_truck(this.trunk))
.then(() => characteristic.updateValue(value));
}
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle-services/information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export class AccessoryInformationService {
}

async setIdentify(): Promise<void> {
await this.parent.wake_up().then(() => this.parent.vehicle.flash_lights());
await this.parent.wakeUpAndWait().then(() => this.parent.vehicle.flash_lights());
}
}
2 changes: 1 addition & 1 deletion src/vehicle-services/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class LockService extends BaseService {
async setState(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
const open = value === this.parent.platform.Characteristic.LockTargetState.UNSECURED;

await this.parent.wake_up().then(() =>
await this.parent.wakeUpAndWait().then(() =>
open ?
this.parent.vehicle.door_lock()
.then(() => characteristic.updateValue(this.parent.platform.Characteristic.LockTargetState.SECURED)) :
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle-services/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class WindowService extends BaseService {
const { latitude, longitude } =
this.parent.accessory.context?.drive_state ?? {};

await this.parent.vehicle.wake_up()
await this.parent.wakeUpAndWait()
.then(() => this.parent.vehicle.window_control(value === 100 ? "vent" : "close", latitude, longitude))
.then(() => characteristic.updateValue(value));
}
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class VehicleAccessory {
});
}

async wake_up(): Promise<void> {
async wakeUpAndWait(): Promise<void> {
if (this.accessory.context.state === "online") {
return Promise.resolve();
}
Expand Down

0 comments on commit 99223c3

Please sign in to comment.