forked from pgerke/homebridge-freeathome-local-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriggerSensorAccessory.ts
63 lines (55 loc) · 2.16 KB
/
triggerSensorAccessory.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
import { PlatformAccessory, Service } from "homebridge";
import { FreeAtHomeAccessory } from "./freeAtHomeAccessory";
import { FreeAtHomeContext } from "./freeAtHomeContext";
import { FreeAtHomeHomebridgePlatform } from "./platform";
import { getDataPointByPairingID } from "./util";
const pairingID = 2;
/** A trigger sensor accessory. */
export class TriggerSensorAccessory extends FreeAtHomeAccessory {
private readonly service: Service;
private readonly stateChannel: string;
/**
* Constructs a new trigger sensor accessory instance.
* @param platform The free@home Homebridge platform controlling the accessory
* @param accessory The platform accessory.
*/
constructor(
readonly platform: FreeAtHomeHomebridgePlatform,
readonly accessory: PlatformAccessory<FreeAtHomeContext>
) {
super(platform, accessory);
// set initial state
this.stateChannel = getDataPointByPairingID(
this.accessory.context.channel.inputs,
pairingID
);
// get the StatelessProgrammableSwitch service if it exists, otherwise create a new service instance
this.service =
this.accessory.getService(
this.platform.Service.StatelessProgrammableSwitch
) ||
this.accessory.addService(
this.platform.Service.StatelessProgrammableSwitch
);
// register handlers for the switch output state characteristic
this.service
.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent)
.onGet(
// istanbul ignore next
() => this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
);
}
public override updateDatapoint(datapoint: string): void {
// ignore unknown data points
if (datapoint !== this.stateChannel) return;
this.platform.log.info(
// eslint-disable-next-line max-len
`${this.accessory.displayName} ("Trigger Sensor" ${this.serialNumber}) triggered ${this.platform.Characteristic.ProgrammableSwitchEvent.name}`
);
this.service
.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent)
.sendEventNotification(
this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS
);
}
}