UNPKG

homebridge-z2m

Version:

Expose your Zigbee devices to HomeKit with ease, by integrating Zigbee2MQTT with Homebridge.

33 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CarbonDioxideSensorHandler = void 0; const hap_1 = require("../../hap"); const helpers_1 = require("../../helpers"); const z2mModels_1 = require("../../z2mModels"); const monitor_1 = require("../monitor"); const basic_1 = require("./basic"); class CarbonDioxideSensorHandler extends basic_1.BasicSensorHandler { static exposesName = 'co2'; static exposesType = z2mModels_1.ExposesKnownTypes.NUMERIC; // Default threshold for CO2 detection (in ppm) static defaultCo2Threshold = 1200; mainCharacteristics = []; constructor(expose, allExposes, accessory) { super(accessory, expose, allExposes, CarbonDioxideSensorHandler.generateIdentifier, (n, t) => new hap_1.hap.Service.CarbonDioxideSensor(n, t)); accessory.log.debug(`Configuring CO2 Sensor for ${this.serviceName}`); const characteristic = (0, helpers_1.getOrAddCharacteristic)(this.service, hap_1.hap.Characteristic.CarbonDioxideLevel); (0, helpers_1.copyExposesRangeToCharacteristic)(expose, characteristic); this.mainCharacteristics.push((0, helpers_1.getOrAddCharacteristic)(this.service, hap_1.hap.Characteristic.CarbonDioxideDetected)); this.monitors.push(new monitor_1.PassthroughCharacteristicMonitor(expose.property, this.service, hap_1.hap.Characteristic.CarbonDioxideLevel)); this.monitors.push(new monitor_1.BinaryConditionCharacteristicMonitor(expose.property, this.service, hap_1.hap.Characteristic.CarbonDioxideDetected, (v) => v >= CarbonDioxideSensorHandler.defaultCo2Threshold, hap_1.hap.Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL, hap_1.hap.Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL)); } static generateIdentifier(endpoint) { let identifier = hap_1.hap.Service.CarbonDioxideSensor.UUID; if (endpoint !== undefined) { identifier += '_' + endpoint.trim(); } return identifier; } } exports.CarbonDioxideSensorHandler = CarbonDioxideSensorHandler; //# sourceMappingURL=carbon_dioxide.js.map