UNPKG

@pst-on-npm/homebridge-enocean

Version:
123 lines • 6.87 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.TemperatureSensorAccessory = void 0; const EnoCore = __importStar(require("enocean-core")); const BatteryServiceHelper_1 = require("../serviceHelper/BatteryServiceHelper"); const InformationServiceHelper_1 = require("../serviceHelper/InformationServiceHelper"); const HistoryServiceFactory_1 = require("../serviceHelper/HistoryServiceFactory"); const EnoAccessory_1 = require("./EnoAccessory"); const StatusActiveWrapper_1 = require("../serviceHelper/StatusActiveWrapper"); /** * EnoTemperatureSensorAccessory * An instance of this class is created for each temperature sensor * Creates a relative humidity service as well depending on EEP */ class TemperatureSensorAccessory extends EnoAccessory_1.EnoAccessory { _gateway; _statusActiveWrapper; _service; _batteryService; _relativeHumidityService; _currentTemperature; _currentRelativeHumidity; _historyService = undefined; constructor(platform, accessory, config) { super(platform, accessory, config); this._currentTemperature = accessory.context.currentTemperature; this._currentRelativeHumidity = accessory.context.currentRelativeHumidity; this._statusActiveWrapper = new StatusActiveWrapper_1.StatusActiveWrapper(platform.log, accessory.displayName); this._statusActiveWrapper.statusActiveChanged = (statusActive) => { this._service.updateCharacteristic(this.hap.Characteristic.StatusActive, statusActive); }; // Get the historyService if available in the platform this._historyService = HistoryServiceFactory_1.HistoryServiceFactory .getOptionalHistoryService(platform, accessory, config); // Set accessory information service InformationServiceHelper_1.InformationServiceHelper.setupService(platform, accessory, config); // Get the TemperatureSensor service if it exists, otherwise create a new TemperatureSensor service // you can create multiple services for each accessory this._service = this.accessory.getService(this.hap.Service.TemperatureSensor) || this.accessory.addService(this.hap.Service.TemperatureSensor); this._service .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName); // Each service must implement at-minimum the "required characteristics" for the given service type // see https://developers.homebridge.io/#/service/TemperatureSensor // Register handlers for the Characteristics this._service.getCharacteristic(this.hap.Characteristic.StatusActive) .onGet(async () => this.getProperty(this._statusActiveWrapper.statusActive)); this._service.getCharacteristic(this.hap.Characteristic.CurrentTemperature) .onGet(async () => this.getProperty(this._currentTemperature)); if (config.manufacturerId === EnoCore.Manufacturers.ELTAKO) { this._batteryService = new BatteryServiceHelper_1.BatteryServiceHelper(platform, accessory); } if (/^A5-04/i.test(config.eepId.toString())) { // This has a humidity sensor // Get the HumiditySensor service if it exists, otherwise create a new HumiditySensor service this._relativeHumidityService = this.accessory.getService(this.hap.Service.HumiditySensor) || this.accessory.addService(this.hap.Service.HumiditySensor); this._relativeHumidityService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName); this._relativeHumidityService.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity) .onGet(async () => this.getProperty(this._currentRelativeHumidity)); } } async setGateway(gateway) { this._gateway = gateway; // Register message receiver in the gateway await this._gateway.registerEnoAccessory(this.config, this.EnoGateway_eepMessageReceived.bind(this)); } EnoGateway_eepMessageReceived(message) { this.platform.log.debug(`${this.accessory.displayName}: ${message.toString()}`); if (message.values.temperature !== undefined) { this._currentTemperature = message.values.temperature; this._service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this._currentTemperature); this._historyService?.addEntry({ time: Math.round(new Date().valueOf() / 1000), temp: this._currentTemperature }); this.accessory.context.currentTemperature = this._currentTemperature; } if (this._relativeHumidityService !== undefined) { if (message.values.relativeHumidity !== undefined) { this._currentRelativeHumidity = message.values.relativeHumidity; this._relativeHumidityService .updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this._currentRelativeHumidity); this._historyService ?.addEntry({ time: Math.round(new Date().valueOf() / 1000), humidity: this._currentRelativeHumidity }); this.accessory.context.currentRelativeHumidity = this._currentRelativeHumidity; } } this._batteryService?.updateCharacteristics(message); this._statusActiveWrapper.update(); } } exports.TemperatureSensorAccessory = TemperatureSensorAccessory; //# sourceMappingURL=TemperatureSensorAccessory.js.map