diff --git a/src/vehicle-services/chargecurrent.ts b/src/vehicle-services/chargecurrent.ts index 4ba9431..17a93d6 100644 --- a/src/vehicle-services/chargecurrent.ts +++ b/src/vehicle-services/chargecurrent.ts @@ -30,7 +30,7 @@ export class ChargeCurrentService extends BaseService { async setLevel(value: CharacteristicValue, characteristic: Characteristic): Promise { value = Math.max(this.min, Math.min(this.max, value as number)); - await this.parent.vehicle.wake_up() + await this.accessory.wakeUpAndWait() .then(() => this.parent.vehicle.set_charging_amps(value)) .then(() => characteristic.updateValue(value)); } diff --git a/src/vehicle-services/chargelimit.ts b/src/vehicle-services/chargelimit.ts index b18cfec..4ac653d 100644 --- a/src/vehicle-services/chargelimit.ts +++ b/src/vehicle-services/chargelimit.ts @@ -30,7 +30,7 @@ export class ChargeLimitService extends BaseService { async setLevel(value: CharacteristicValue, characteristic: Characteristic): Promise { value = Math.max(this.min, Math.min(this.max, value as number)); - await this.vehicle.wake_up() + await this.accessory.wakeUpAndWait() .then(() => this.vehicle.set_charge_limit(value)) .then(() => characteristic.updateValue(value)); } diff --git a/src/vehicle-services/chargeport.ts b/src/vehicle-services/chargeport.ts index f89e3d2..86dc59d 100644 --- a/src/vehicle-services/chargeport.ts +++ b/src/vehicle-services/chargeport.ts @@ -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 { - await this.vehicle.wake_up().then(() => - value === this.parent.platform.Characteristic.LockTargetState.SECURED ? + await this.accessory.wakeUpAndWait().then(() => + value === 1 ? this.vehicle.charge_port_door_close() .then(() => characteristic.updateValue(this.parent.platform.Characteristic.LockTargetState.SECURED) diff --git a/src/vehicle-services/chargeswitch.ts b/src/vehicle-services/chargeswitch.ts index cc9f12c..037990f 100644 --- a/src/vehicle-services/chargeswitch.ts +++ b/src/vehicle-services/chargeswitch.ts @@ -22,7 +22,7 @@ export class ChargeSwitchService extends BaseService { } async setOn(value: CharacteristicValue, characteristic: Characteristic): Promise { - 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)) ); diff --git a/src/vehicle-services/climate.ts b/src/vehicle-services/climate.ts index 47c2f35..9d95608 100644 --- a/src/vehicle-services/climate.ts +++ b/src/vehicle-services/climate.ts @@ -63,7 +63,7 @@ export class ClimateService extends BaseService { } async setTargetState(value: CharacteristicValue, characteristic: Characteristic): Promise { - await this.vehicle.wake_up() + await this.parent.wakeUpAndWait() .then(() => value ? this.vehicle .auto_conditioning_start() @@ -80,7 +80,7 @@ export class ClimateService extends BaseService { } async setTargetTemp(value: CharacteristicValue, characteristic: Characteristic): Promise { - 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))); } diff --git a/src/vehicle-services/door.ts b/src/vehicle-services/door.ts index 5f54ed2..a7a7822 100644 --- a/src/vehicle-services/door.ts +++ b/src/vehicle-services/door.ts @@ -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)); } diff --git a/src/vehicle-services/information.ts b/src/vehicle-services/information.ts index bb47a83..6a8d043 100644 --- a/src/vehicle-services/information.ts +++ b/src/vehicle-services/information.ts @@ -38,6 +38,6 @@ export class AccessoryInformationService { } async setIdentify(): Promise { - await this.parent.wake_up().then(() => this.parent.vehicle.flash_lights()); + await this.parent.wakeUpAndWait().then(() => this.parent.vehicle.flash_lights()); } } diff --git a/src/vehicle-services/lock.ts b/src/vehicle-services/lock.ts index 727677b..0a66176 100644 --- a/src/vehicle-services/lock.ts +++ b/src/vehicle-services/lock.ts @@ -25,7 +25,7 @@ export class LockService extends BaseService { async setState(value: CharacteristicValue, characteristic: Characteristic): Promise { 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)) : diff --git a/src/vehicle-services/windows.ts b/src/vehicle-services/windows.ts index caad2dd..e911355 100644 --- a/src/vehicle-services/windows.ts +++ b/src/vehicle-services/windows.ts @@ -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)); } diff --git a/src/vehicle.ts b/src/vehicle.ts index 7598f8f..4c4c91c 100644 --- a/src/vehicle.ts +++ b/src/vehicle.ts @@ -106,7 +106,7 @@ export class VehicleAccessory { }); } - async wake_up(): Promise { + async wakeUpAndWait(): Promise { if (this.accessory.context.state === "online") { return Promise.resolve(); }