Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Aug 18, 2024
1 parent ae54ce0 commit 65fc256
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
26 changes: 18 additions & 8 deletions src/vehicle-services/chargelimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ 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 {

min: number = 50;
max: number = 100;

constructor(parent: VehicleAccessory) {
super(parent, parent.platform.Service.Lightbulb, "Charge Limit", "charge_limit");
super(
parent,
parent.platform.Service.Lightbulb,
"Charge Limit",
"charge_limit",
);

const on = this.service
.getCharacteristic(this.parent.platform.Characteristic.On);
const on = this.service.getCharacteristic(
this.parent.platform.Characteristic.On,
);

const level = this.service
.getCharacteristic(this.parent.platform.Characteristic.Brightness)
Expand All @@ -27,12 +31,18 @@ export class ChargeLimitService extends BaseService {
});
}

async setLevel(value: CharacteristicValue, characteristic: Characteristic): Promise<void> {
async setLevel(
value: CharacteristicValue,
characteristic: Characteristic,
): Promise<void> {
value = Math.max(this.min, Math.min(this.max, value as number));
await this.parent.wakeUpAndWait()
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}`));
.catch((e) =>
this.log.error(`${this.name} vehicle set_charge_limit failed: ${e}`),
);
}
}
41 changes: 25 additions & 16 deletions src/vehicle-services/lock.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
import { wait } from "../utils/wait.js";
import { VehicleAccessory } from "../vehicle.js";
import { BaseService } from "./base.js";

export class LockService extends BaseService {
constructor(parent: VehicleAccessory) {
super(parent, parent.platform.Service.LockMechanism, "Lock", "lock");

const currentState = this.service
.getCharacteristic(this.parent.platform.Characteristic.LockCurrentState);
const currentState = this.service.getCharacteristic(
this.parent.platform.Characteristic.LockCurrentState,
);

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)
this.service.setCharacteristic(
this.parent.platform.Characteristic.LockTargetState,
value,
);
targetState.updateValue(value);
await this.parent.wakeUpAndWait().then(() =>
value ?
this.parent.vehicle.door_lock()
//.then(() => wait())
.then(() => currentState.updateValue(value))
.catch((e) => this.log.error(`${this.name} vehicle door_lock failed: ${e}`))
:
this.parent.vehicle.door_unlock()
//.then(() => wait())
.then(() => currentState.updateValue(value))
.catch((e) => this.log.error(`${this.name} vehicle door_unlock failed: ${e}`))
value
? this.parent.vehicle
.door_lock()
//.then(() => wait())
.then(() => currentState.updateValue(value))
.catch((e) =>
this.log.error(`${this.name} vehicle door_lock failed: ${e}`),
)
: this.parent.vehicle
.door_unlock()
//.then(() => wait())
.then(() => currentState.updateValue(value))
.catch((e) =>
this.log.error(
`${this.name} vehicle door_unlock failed: ${e}`,
),
),
);
});

Expand All @@ -35,4 +44,4 @@ export class LockService extends BaseService {
targetState.updateValue(state);
});
}
}
}

0 comments on commit 65fc256

Please sign in to comment.