generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VehicleService.ts
51 lines (45 loc) · 1.28 KB
/
VehicleService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
CharacteristicGetCallback,
CharacteristicValue,
HAP,
HAPStatus,
Logging,
Nullable,
Service,
} from "homebridge";
import { VehicleDataResponse } from "tesla-fleet-api/dist/types/vehicle_data.js";
import { VehicleAccessory } from "../vehicle.js";
export abstract class VehicleService {
service: Service;
constructor(
public readonly parent: VehicleAccessory,
public readonly serviceType: ServiceType
) {
this.service =
this.parent.accessory.getService(serviceType) ||
this.parent.accessory.addService(serviceType);
this.setupCharacteristics();
}
/*protected createGetter<T extends CharacteristicValue>(
getter: Getter<T>
): GetterCallback {
return (callback) => {
this.context.tesla
.getVehicleData()
.then((data) => getter.call(this, data))
.then((value) => callback(null, value))
.catch((error: Error) => callback(error));
};
}
protected createSetter<T extends CharacteristicValue>(
setter: Setter<T>
): SetterCallback {
return (value, callback) => {
setter
.call(this, value as T)
.then((writeResponse) => callback(null, writeResponse ?? undefined))
.catch((error: Error) => callback(error));
};
}*/
abstract setupCharacteristics(): void;
}