@chazepps/homebridge-hejhome
Version:
The Hejhome plugin allows you to access your Hejhome device(s) from HomeKit.
35 lines • 1.54 kB
JavaScript
import { hejEvent } from '../requests/realtime.js';
import { Base } from './base.js';
export const EVENT_MOTION_DETECTED = 'motionDetected';
const CHARACTERISTIC_MANUFACTURER = 'Hejhome';
const CHARACTERISTIC_MODEL = 'Unknown Hejhome device';
export class SensorMo extends Base {
platform;
accessory;
device;
service;
constructor(platform, accessory, device) {
super();
this.platform = platform;
this.accessory = accessory;
this.device = device;
const { Characteristic: { Manufacturer, Model, SerialNumber, Name, }, Service, } = this.platform;
this.accessory
.getService(Service.AccessoryInformation)
.setCharacteristic(Manufacturer, CHARACTERISTIC_MANUFACTURER)
.setCharacteristic(Model, this.device.modelName || CHARACTERISTIC_MODEL)
.setCharacteristic(SerialNumber, this.device.id);
this.service = this.accessory.getService(Service.MotionSensor) || this.accessory.addService(Service.MotionSensor);
this.service.setCharacteristic(Name, this.device.name);
this.registerEventListeners();
}
registerEventListeners() {
hejEvent.addListener(EVENT_MOTION_DETECTED, this.handleMotionDetected.bind(this));
}
handleMotionDetected(deviceId, value) {
const { Characteristic: { MotionDetected } } = this.platform;
const motionDetected = value === 'pir';
this.service.updateCharacteristic(MotionDetected, motionDetected);
}
}
//# sourceMappingURL=sensor_mo.js.map