Skip to content

Commit

Permalink
Improve windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jun 16, 2024
1 parent 931cbdc commit d2ef4e3
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/vehicle-services/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ export class WindowService extends BaseService {
}

getPosition(): number {
return this.parent.accessory.context?.vehicle_state?.fd_window |
this.parent.accessory.context?.vehicle_state?.fp_window |
this.parent.accessory.context?.vehicle_state?.rd_window |
this.parent.accessory.context?.vehicle_state?.rp_window
? 100
: 0;
if (!this.parent.accessory.context?.vehicle_state) {
return 0;
}
return this.parent.accessory.context.vehicle_state.fd_window * 25 +
this.parent.accessory.context.vehicle_state.fp_window * 25 +
this.parent.accessory.context.vehicle_state.rd_window * 25 +
this.parent.accessory.context.vehicle_state.rp_window * 25;
}

async setPosition(value: CharacteristicValue) {
const { latitude, longitude } =
this.parent.accessory.context?.drive_state ?? {};
async setPosition(value: CharacteristicValue): Promise<void> {
if (value === 100 || value === 0) {

return this.parent.vehicle
.window_control(value === 100 ? "close" : "vent", latitude, longitude)
.then(() => value);
this.log.info("Setting windows to", value);
const { latitude, longitude } =
this.parent.accessory.context?.drive_state ?? {};

await this.parent.vehicle
.window_control(value === 100 ? "vent" : "close", latitude, longitude);
}
}
}

0 comments on commit d2ef4e3

Please sign in to comment.