forked from pgerke/homebridge-freeathome-local-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreeAtHomeAccessory.ts
68 lines (63 loc) · 2.22 KB
/
freeAtHomeAccessory.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
Characteristic,
CharacteristicValue,
PlatformAccessory,
Service,
WithUUID,
} from "homebridge";
import { FreeAtHomeContext } from "./freeAtHomeContext";
import { FreeAtHomeHomebridgePlatform } from "./platform";
import { convertToString } from "./util";
/** The abstract base class for all free@home accessories.*/
export abstract class FreeAtHomeAccessory {
/** The serial number consisting of the free@home device serial and the channel ID. */
protected readonly serialNumber = `${this.accessory.context.deviceSerial} (${this.accessory.context.channelId})`;
/**
* Constructs a new free@home accessory instance.
* @param platform The free@home Homebridge platform controlling the accessory
* @param accessory The platform accessory.
*/
constructor(
protected readonly platform: FreeAtHomeHomebridgePlatform,
protected readonly accessory: PlatformAccessory<FreeAtHomeContext>
) {
// set accessory information
this.accessory
.getService(this.platform.Service.AccessoryInformation)
?.setCharacteristic(
this.platform.Characteristic.Manufacturer,
"BUSCH-JAEGER"
)
.setCharacteristic(
this.platform.Characteristic.Model,
accessory.context.device.displayName ?? "Unknown Model"
)
.setCharacteristic(
this.platform.Characteristic.SerialNumber,
this.serialNumber
);
}
/**
* Asynchonously updates accessory characteristics from a datapoint.
* @param datapoint The updated data point.
* @param value A string representing the new value.
*/
public abstract updateDatapoint(datapoint: string, value: string): void;
protected doUpdateDatapoint(
acccessoryDisplayType: string,
service: Service,
characteristic: WithUUID<new () => Characteristic>,
characteristicValue: CharacteristicValue
): void {
// log event
this.platform.log.info(
`${this.accessory.displayName} (${acccessoryDisplayType} ${
this.serialNumber
}) updated characteristic ${characteristic.name} -> ${convertToString(
characteristicValue
)}`
);
// asynchoronously update the characteristic
service.updateCharacteristic(characteristic, characteristicValue);
}
}