homebridge-freeathome-local-api
Version:
Control your free@home setup using the local API provided by your System Access Point
39 lines • 1.82 kB
JavaScript
import { FreeAtHomeAccessory } from "./freeAtHomeAccessory.js";
/** A switch sensor accessory. */
export class SwitchSensorAccessory extends FreeAtHomeAccessory {
platform;
accessory;
service;
/**
* Constructs a new switch 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;
// 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 !== "idp0000")
return;
this.platform.log.info(
// eslint-disable-next-line max-len
`${this.accessory.displayName} ("Switch Sensor" ${this.serialNumber}) triggered ${this.platform.Characteristic.ProgrammableSwitchEvent.name}`);
this.service
.getCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent)
.sendEventNotification(this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
}
}
//# sourceMappingURL=switchSensorAccessory.js.map