Skip to content

Commit

Permalink
Make sentry a security system
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jun 21, 2024
1 parent e876344 commit e60b78e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/vehicle-services/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import { BaseService } from "./base.js";

export class SentryService extends BaseService {
constructor(parent: VehicleAccessory) {
super(parent, parent.platform.Service.Switch, "Sentry", "sentry");
super(parent, parent.platform.Service.SecuritySystem, "Sentry", "sentry");

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

const target = this.service
.getCharacteristic(this.parent.platform.Characteristic.SecuritySystemTargetState)
.onSet(async (value) => {
value = value === 3 ? 3 : 0;
target.updateValue(value);
await this.parent.wakeUpAndWait()
.then(() => this.vehicle.set_sentry_mode(value as boolean))
.then(() => on.updateValue(value));
.then(() => this.vehicle.set_sentry_mode(value !== 3))
.then(() => current.updateValue(value));
});

this.parent.emitter.on("vehicle_data", (data) => {
on.updateValue(data.vehicle_state.sentry_mode);
const value = data.vehicle_state.sentry_mode ? 0 : 3;
current.updateValue(value);
target.updateValue(value);
});
}
}

0 comments on commit e60b78e

Please sign in to comment.