homebridge-freeathome-local-api
Version:
Control your free@home setup using the local API provided by your System Access Point
44 lines • 2.05 kB
JavaScript
import { FreeAtHomeAccessory } from "./freeAtHomeAccessory.js";
import { getDataPointByPairingID } from "./util.js";
const pairingID = 2;
/** A trigger sensor accessory. */
export class TriggerSensorAccessory extends FreeAtHomeAccessory {
platform;
accessory;
service;
stateChannel;
/**
* Constructs a new trigger sensor accessory instance.
* @param platform The free@home Homebridge platform controlling the accessory
* @param accessory The platform accessory.
*/
constructor(platform, accessory) {
super(platform, accessory);
this.platform = platform;
this.accessory = 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);
}
updateDatapoint(datapoint) {
// 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);
}
}
//# sourceMappingURL=triggerSensorAccessory.js.map