-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { CharacteristicValue } from "homebridge"; | ||
import { debounce } from "../utils/debounce.js"; | ||
import { VehicleAccessory } from "../vehicle.js"; | ||
import { BaseService } from "./base.js"; | ||
|
||
export class ChargeCurrentService extends BaseService { | ||
constructor(parent: VehicleAccessory) { | ||
super(parent, parent.platform.Service.Lightbulb, "charge current", "charge_current"); | ||
|
||
const on = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.On) | ||
.onGet(this.getOn.bind(this)); | ||
|
||
const level = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.ChargingState) | ||
.onGet(this.getLevel.bind(this)) | ||
.onSet(debounce(this.setLevel.bind(this), 3000)); | ||
|
||
this.parent.emitter.on("vehicle_data", () => { | ||
on.updateValue(this.getOn()); | ||
level.updateValue(this.getLevel()); | ||
}); | ||
} | ||
|
||
getOn(): boolean { | ||
return !!this.parent.accessory.context?.charge_state; | ||
} | ||
|
||
getLevel(): number { | ||
return this.parent.accessory.context?.charge_state?.charge_current_request ?? 16; | ||
} | ||
|
||
setLevel(value: CharacteristicValue): Promise<number> { | ||
const min = 2; | ||
const max = this.parent.accessory.context.charge_state.charge_current_request_max ?? 100; | ||
value = Math.max(min, Math.min(max, value as number)); | ||
return this.parent.vehicle.set_charge_limit(value).then(() => value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { CharacteristicValue } from "homebridge"; | ||
import { debounce } from "../utils/debounce.js"; | ||
import { VehicleAccessory } from "../vehicle.js"; | ||
import { BaseService } from "./base.js"; | ||
|
||
export class ChargeLimitService extends BaseService { | ||
constructor(parent: VehicleAccessory) { | ||
super(parent, parent.platform.Service.Lightbulb, "charge limit", "charge_limit"); | ||
|
||
const on = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.On) | ||
.onGet(this.getOn.bind(this)); | ||
|
||
const level = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.ChargingState) | ||
.onGet(this.getLevel.bind(this)) | ||
.onSet(debounce(this.setLevel.bind(this), 3000)); | ||
|
||
this.parent.emitter.on("vehicle_data", () => { | ||
on.updateValue(this.getOn()); | ||
level.updateValue(this.getLevel()); | ||
}); | ||
} | ||
|
||
getOn(): boolean { | ||
return !!this.parent.accessory.context?.charge_state; | ||
} | ||
|
||
getLevel(): number { | ||
return this.parent.accessory.context?.charge_state?.charge_limit_soc ?? 50; | ||
} | ||
|
||
setLevel(value: CharacteristicValue): Promise<number> { | ||
const min = this.parent.accessory.context.charge_state.charge_limit_soc_min ?? 50; | ||
const max = this.parent.accessory.context.charge_state.charge_limit_soc_max ?? 100; | ||
value = Math.max(min, Math.min(max, value as number)); | ||
return this.parent.vehicle.set_charge_limit(value).then(() => value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
import { CharacteristicValue } from "homebridge"; | ||
import { debounce } from "../utils/debounce.js"; | ||
import { VehicleAccessory } from "../vehicle.js"; | ||
import { BaseService } from "./base.js"; | ||
|
||
export class ChargePortService extends BaseService { | ||
constructor(parent: VehicleAccessory) { | ||
Check warning on line 6 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
super(parent, parent.platform.Service.LockMechanism, "charge port", "charge_port"); | ||
Check warning on line 7 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
|
||
const on = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.On) | ||
.onGet(this.getOn.bind(this)); | ||
const currentState = this.service | ||
Check warning on line 9 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
.getCharacteristic(this.parent.platform.Characteristic.LockCurrentState) | ||
Check warning on line 10 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
.onGet(this.getState.bind(this)); | ||
Check warning on line 11 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
|
||
const level = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.ChargingState) | ||
.onGet(this.getLevel.bind(this)) | ||
.onSet(debounce(this.setLevel.bind(this), 3000)); | ||
this.service | ||
Check warning on line 13 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
.getCharacteristic(this.parent.platform.Characteristic.LockTargetState) | ||
Check warning on line 14 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
.onGet(this.getState.bind(this)) | ||
Check warning on line 15 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
.onSet(this.setState.bind(this)); | ||
Check warning on line 16 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
|
||
this.parent.emitter.on("vehicle_data", () => { | ||
Check warning on line 18 in src/services/chargeport.ts GitHub Actions / build (18.x)
|
||
on.updateValue(this.getOn()); | ||
level.updateValue(this.getLevel()); | ||
currentState.updateValue(this.getState()); | ||
}); | ||
} | ||
|
||
getOn(): boolean { | ||
return this.parent.accessory.context?.charge_state?.user_charge_enable_request | ||
?? this.parent.accessory.context?.charge_state?.charge_enable_request; | ||
getState(): number { | ||
return this.parent.accessory.context?.charge_state?.charge_port_latch ? | ||
this.parent.platform.Characteristic.LockTargetState.SECURED : | ||
this.parent.platform.Characteristic.LockTargetState.UNSECURED; | ||
} | ||
|
||
getLevel(): number { | ||
return this.parent.accessory.context?.charge_state?.charge_limit_soc ?? 50; | ||
} | ||
setState(value: CharacteristicValue): Promise<number> { | ||
const open = value === this.parent.platform.Characteristic.LockTargetState.UNSECURED; | ||
|
||
setLevel(value: CharacteristicValue): Promise<number> { | ||
const min = this.parent.accessory.context.charge_state.charge_limit_soc_min ?? 50; | ||
const max = this.parent.accessory.context.charge_state.charge_limit_soc_max ?? 100; | ||
value = Math.max(min, Math.min(max, value as number)); | ||
return this.parent.vehicle.set_charge_limit(value).then(() => value); | ||
if (open) { | ||
return this.parent.vehicle.charge_port_door_open().then(() => | ||
this.parent.platform.Characteristic.LockTargetState.SECURED | ||
); | ||
} | ||
return this.parent.vehicle.charge_port_door_close().then(() => | ||
this.parent.platform.Characteristic.LockTargetState.UNSECURED | ||
); | ||
} | ||
} |