homebridge-virtual-accessories
Version:
Virtual HomeKit accessories for Homebridge.
26 lines • 1.24 kB
JavaScript
/* eslint-disable brace-style */
import { InvalidSensorValueType, SensorValueUpdateNotAllowed } from '../../errors.js';
import { BinarySensor } from '../binarySensor.js';
import { Trigger } from './trigger.js';
/**
* WebhookTrigger - Trigger implementation
*/
export class WebhookTrigger extends Trigger {
constructor(sensor, name) {
super(sensor, name);
}
triggerSensor(value, accessoryId) {
this.log.debug(`[${this.accessoryName}] Request update triggered state to ${value}`);
if (accessoryId !== this.sensorConfig.accessoryID) {
this.log.error(`[${this.accessoryName}] Accessory Id ${accessoryId} is not valid for this accessory`);
throw new SensorValueUpdateNotAllowed(`Invalid accessory id: ${accessoryId}`);
}
else if (typeof value !== 'boolean') {
this.log.error(`[${this.accessoryName}] Value ${value} is not valid for a Security System triggered state`);
throw new InvalidSensorValueType(`Invalid sensor value: ${value}`);
}
const sensorState = value ? BinarySensor.TRIGGERED : BinarySensor.NORMAL;
this.sensor.triggerSensorState(sensorState, this);
}
}
//# sourceMappingURL=triggerWebhook.js.map