UNPKG

homebridge-tessie

Version:

Connect Homebridge to your Tessie account.

29 lines 1.36 kB
import { debounce } from "../utils/debounce.js"; import { BaseService } from "./base.js"; export class ChargeLimitService extends BaseService { min = 50; max = 100; constructor(parent) { super(parent, parent.platform.Service.Lightbulb, "Charge Limit", "charge_limit"); const on = this.service.getCharacteristic(this.parent.platform.Characteristic.On); const level = this.service .getCharacteristic(this.parent.platform.Characteristic.Brightness) .onSet(debounce((value) => this.setLevel(value, level), 3000)); this.parent.emitter.on("vehicle_data", (data) => { this.min = data.charge_state.charge_limit_soc_min ?? this.min; this.max = data.charge_state.charge_limit_soc_max ?? this.max; on.updateValue(true); level.updateValue(data.charge_state.charge_limit_soc); }); } async setLevel(value, characteristic) { value = Math.max(this.min, Math.min(this.max, value)); 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}`)); } } //# sourceMappingURL=chargelimit.js.map