generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
191 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CharacteristicValue, Service } from "homebridge"; | ||
Check warning on line 1 in src/services/door.ts GitHub Actions / build (18.x)
|
||
import { VehicleAccessory } from "../vehicle.js"; | ||
Check warning on line 2 in src/services/door.ts GitHub Actions / build (18.x)
|
||
|
||
export class DoorService { | ||
service: Service; | ||
key: "ft" | "rt"; | ||
Check warning on line 6 in src/services/door.ts GitHub Actions / build (18.x)
|
||
|
||
constructor( | ||
private parent: VehicleAccessory, | ||
private trunk: "front" | "rear" | ||
) { | ||
this.service = | ||
this.parent.accessory.getService(this.parent.platform.Service.Door) || | ||
this.parent.accessory.addService(this.parent.platform.Service.Door); | ||
|
||
this.key = this.trunk === "front" ? "ft" : "rt"; | ||
|
||
const currentPosition = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.CurrentPosition) | ||
.onGet(this.getPosition); | ||
|
||
/*const positionState = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.PositionState) | ||
.onGet(() => this.getChargingState());*/ | ||
|
||
const targetPosition = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.TargetPosition) | ||
.onGet(this.getPosition) | ||
.onSet(this.setPosition); | ||
|
||
this.parent.emitter.on("vehicle_data", () => { | ||
currentPosition.updateValue(this.getPosition()); | ||
targetPosition.updateValue(this.getPosition()); | ||
}); | ||
} | ||
|
||
getPosition(): number { | ||
return this.parent.accessory.context?.vehicle_state?.[this.key] ? 100 : 0; | ||
} | ||
|
||
async setPosition(value: CharacteristicValue) { | ||
console.log(value); | ||
const position = this.getPosition(); | ||
if ( | ||
(position === 0 && value === 100) || | ||
(position === 100 && value === 0 && this.trunk === "rear") | ||
) { | ||
return this.parent.vehicle.actuate_truck(this.trunk).then(() => value); | ||
} | ||
return position; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// https://developers.homebridge.io/#/service/AccessoryInformation | ||
|
||
import { CharacteristicValue, Service } from "homebridge"; | ||
import { VehicleAccessory } from "../vehicle.js"; | ||
|
||
export class AccessoryInformationService { | ||
service: Service; | ||
|
||
constructor(private parent: VehicleAccessory) { | ||
this.service = | ||
this.parent.accessory.getService( | ||
this.parent.platform.Service.AccessoryInformation | ||
) || | ||
this.parent.accessory.addService( | ||
this.parent.platform.Service.AccessoryInformation | ||
); | ||
|
||
this.service // Move this to a separate service | ||
.setCharacteristic( | ||
this.parent.platform.Characteristic.Manufacturer, | ||
"Tesla" | ||
) | ||
.setCharacteristic( | ||
this.parent.platform.Characteristic.Model, | ||
this.parent.vehicle.model | ||
) | ||
.setCharacteristic( | ||
this.parent.platform.Characteristic.SerialNumber, | ||
this.parent.vehicle.vin | ||
); | ||
|
||
const version = this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.FirmwareRevision) | ||
.onGet(this.getVersion); | ||
|
||
this.service | ||
.getCharacteristic(this.parent.platform.Characteristic.Identify) | ||
.onSet(this.setIdentify); | ||
|
||
this.parent.emitter.on("vehicle_data", () => { | ||
version.updateValue(this.getVersion()); | ||
}); | ||
} | ||
|
||
getVersion(): string { | ||
return ( | ||
this.parent.accessory.context?.vehicle_state?.software_update?.version ?? | ||
"unknown" | ||
); | ||
} | ||
|
||
async setIdentify(value: CharacteristicValue) { | ||
console.log(value); | ||
return this.parent | ||
.wake_up() | ||
.then(() => this.parent.vehicle.flash_lights()) | ||
.then(() => false); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Returns a Promise that waits for the given number of milliseconds | ||
* (via setTimeout), then resolves. | ||
*/ | ||
export async function wait(ms: number = 0) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters