UNPKG

homebridge-lutron-caseta-leap-fast

Version:
86 lines 4.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OccupancySensor = void 0; const OccupancySensorRouter_1 = require("./OccupancySensorRouter"); const platform_1 = require("./platform"); class OccupancySensor { constructor(platform, accessory, bridge) { this.platform = platform; this.accessory = accessory; this.bridge = bridge; this.fullName = accessory.context.device.FullyQualifiedName.join(' '); this.state = 'Unknown'; this.accessory .getService(this.platform.api.hap.Service.AccessoryInformation) .setCharacteristic(this.platform.api.hap.Characteristic.Manufacturer, 'Lutron Electronics Co., Inc') .setCharacteristic(this.platform.api.hap.Characteristic.Model, this.accessory.context.device.ModelNumber) .setCharacteristic(this.platform.api.hap.Characteristic.SerialNumber, this.accessory.context.device.SerialNumber.toString()); this.service = this.accessory.getService(this.platform.api.hap.Service.OccupancySensor) || this.accessory.addService(this.platform.api.hap.Service.OccupancySensor); this.service.setCharacteristic(this.platform.api.hap.Characteristic.Name, this.fullName); // If the status is 'Occupied', the sensor is occupied. If 'Unoccupied' // or 'Unknown', unoccupied. this.service.setCharacteristic(this.platform.api.hap.Characteristic.OccupancyDetected, this.platform.api.hap.Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED); this.service.getCharacteristic(this.platform.api.hap.Characteristic.OccupancyDetected).on("get" /* this.platform.api.hap.CharacteristicEventTypes.GET */, ((cb) => { if (this.state === 'Occupied') { cb(null, this.platform.api.hap.Characteristic.OccupancyDetected.OCCUPANCY_DETECTED); } else { cb(null, this.platform.api.hap.Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED); } }).bind(this)); // If the status is 'Unknown', the sensor is not active. If 'Occupied' // or 'Unoccupied', active. this.service.setCharacteristic(this.platform.api.hap.Characteristic.StatusActive, false); this.service.getCharacteristic(this.platform.api.hap.Characteristic.StatusActive).on("get" /* this.platform.api.hap.CharacteristicEventTypes.GET */, ((cb) => { if (this.state === 'Unknown') { cb(null, false); } else { cb(null, true); } }).bind(this)); } update(update) { // This method contains the logic that manages mapping the three LEAP // occupancy sensor states to the two Homekit characteristics. // // If the status is 'Occupied', the sensor is occupied. If 'Unoccupied' // or 'Unknown', unoccupied. // // If the status is 'Unknown', the sensor is not active. If 'Occupied' // or 'Unoccupied', active. this.state = update; switch (update) { case 'Occupied': { this.service.setCharacteristic(this.platform.api.hap.Characteristic.OccupancyDetected, this.platform.api.hap.Characteristic.OccupancyDetected.OCCUPANCY_DETECTED); this.service.setCharacteristic(this.platform.api.hap.Characteristic.StatusActive, true); } break; case 'Unoccupied': { this.service.setCharacteristic(this.platform.api.hap.Characteristic.OccupancyDetected, this.platform.api.hap.Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED); this.service.setCharacteristic(this.platform.api.hap.Characteristic.StatusActive, true); } break; case 'Unknown': default: { this.service.setCharacteristic(this.platform.api.hap.Characteristic.OccupancyDetected, this.platform.api.hap.Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED); this.service.setCharacteristic(this.platform.api.hap.Characteristic.StatusActive, false); } } } async initialize() { const area = (await this.bridge.getHref(this.accessory.context.device.AssociatedArea)); const router = OccupancySensorRouter_1.OccupancySensorRouter.getInstance(); await router.register(this.bridge, area.Area.AssociatedOccupancyGroups[0], this.update.bind(this)); return { kind: platform_1.DeviceWireResultType.Success, name: this.fullName, }; } } exports.OccupancySensor = OccupancySensor; //# sourceMappingURL=OccupancySensor.js.map