diff --git a/.vscode/settings.json b/.vscode/settings.json index 89d2e29..73c9562 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,8 @@ { "files.eol": "\n", "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" + "source.fixAll.eslint": false }, - "editor.rulers": [ 140 ], + "editor.rulers": [140], "eslint.enable": true -} \ No newline at end of file +} diff --git a/src/utils/wake.ts b/src/utils/wait.ts similarity index 79% rename from src/utils/wake.ts rename to src/utils/wait.ts index d7e7ef2..409a17d 100644 --- a/src/utils/wake.ts +++ b/src/utils/wait.ts @@ -2,7 +2,7 @@ * Returns a Promise that waits for the given number of milliseconds * (via setTimeout), then resolves. */ -export async function wait(ms: number = 0) { +export async function wait(ms: number = 1000) { return new Promise((resolve) => { setTimeout(resolve, ms); }); diff --git a/src/vehicle-services/chargelimit.ts b/src/vehicle-services/chargelimit.ts index d3f8327..3724b94 100644 --- a/src/vehicle-services/chargelimit.ts +++ b/src/vehicle-services/chargelimit.ts @@ -2,6 +2,7 @@ import { Characteristic, CharacteristicValue } from "homebridge"; import { debounce } from "../utils/debounce.js"; import { VehicleAccessory } from "../vehicle.js"; import { BaseService } from "./base.js"; +import { wait } from "../utils/wait.js"; export class ChargeLimitService extends BaseService { @@ -30,6 +31,7 @@ export class ChargeLimitService extends BaseService { value = Math.max(this.min, Math.min(this.max, value as number)); await this.parent.wakeUpAndWait() .then(() => this.vehicle.set_charge_limit(value)) + //.then(() => wait()) .then(() => characteristic.updateValue(value)) .catch((e) => this.log.error(`${this.name} vehicle set_charge_limit failed: ${e}`)); } diff --git a/src/vehicle-services/lock.ts b/src/vehicle-services/lock.ts index dcc06ca..31ca3d5 100644 --- a/src/vehicle-services/lock.ts +++ b/src/vehicle-services/lock.ts @@ -1,3 +1,4 @@ +import { wait } from "../utils/wait.js"; import { VehicleAccessory } from "../vehicle.js"; import { BaseService } from "./base.js"; @@ -11,15 +12,19 @@ export class LockService extends BaseService { const targetState = this.service .getCharacteristic(this.parent.platform.Characteristic.LockTargetState) .onSet(async (value) => { + console.log(value) + this.service.setCharacteristic(this.parent.platform.Characteristic.LockTargetState, value) targetState.updateValue(value); await this.parent.wakeUpAndWait().then(() => value ? this.parent.vehicle.door_lock() - .then(() => currentState.updateValue(1)) + //.then(() => wait()) + .then(() => currentState.updateValue(value)) .catch((e) => this.log.error(`${this.name} vehicle door_lock failed: ${e}`)) : this.parent.vehicle.door_unlock() - .then(() => currentState.updateValue(0)) + //.then(() => wait()) + .then(() => currentState.updateValue(value)) .catch((e) => this.log.error(`${this.name} vehicle door_unlock failed: ${e}`)) ); });