UNPKG

@pst-on-npm/homebridge-enocean

Version:
132 lines • 6.43 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.LightbulbAccessory = void 0; const EnoCore = __importStar(require("enocean-core")); const EnoMessageFactory_1 = require("../enocean/EnoMessageFactory"); const InformationServiceHelper_1 = require("../serviceHelper/InformationServiceHelper"); const EnoTransmittingAccessory_1 = require("./EnoTransmittingAccessory"); /** * EnoTemperatureSensorAccessory * An instance of this class is created for each temperature sensor * Creates a relative humidity service as well depending on EEP */ class LightbulbAccessory extends EnoTransmittingAccessory_1.EnoTransmittingAccessory { _service; _stateOn; _brightness; constructor(platform, accessory, config) { super(platform, accessory, config); if (accessory.context.on === undefined) { accessory.context.on = false; } this._stateOn = accessory.context.on; this._brightness = accessory.context.brightness ?? 100; // 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.Lightbulb) || this.accessory.addService(this.hap.Service.Lightbulb, config.name); 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/Lightbulb // Register handlers for the Characteristics this._service.getCharacteristic(this.hap.Characteristic.On) .onGet(async () => { return this._stateOn; }); this._service.getCharacteristic(this.hap.Characteristic.On).onSet(this.On_OnSet.bind(this)); if (/\+brightness/i.test(this.config.model)) { this._service.getCharacteristic(this.hap.Characteristic.Brightness) .onGet(async () => { return this._brightness; }); this._service.getCharacteristic(this.hap.Characteristic.Brightness).onSet(this.Brightness_OnSet.bind(this)); } } async Brightness_OnSet(value) { this.platform.log.info(`${this.accessory.displayName}: SET brightness ${value}`); this._brightness = value; this.accessory.context.brightness = this._brightness; if (this._gateway && this._senderId) { let erp1 = undefined; if (this.config.eepId.rorg === EnoCore.RORGs.FOURBS) { erp1 = EnoMessageFactory_1.EnoMessageFactory.newFourBSGatewayDimmingMessage(this._stateOn, this._brightness); } if (erp1 !== undefined) { this.sendErp1Telegram(erp1); } } } async On_OnSet(value) { this.platform.log.info(`${this.accessory.displayName}: SET on ${value}`); this._stateOn = value; this.accessory.context.on = this._stateOn; if (this._gateway && this._senderId) { let erp1 = undefined; if (this.config.eepId.rorg === EnoCore.RORGs.FOURBS) { if (this._gateway.isTeachInMode()) { erp1 = EnoMessageFactory_1.EnoMessageFactory.newFourBSTeachInMessage(this._senderId, this.config.eepId, this.config.manufacturerId); } else { erp1 = EnoMessageFactory_1.EnoMessageFactory.newFourBSGatewayDimmingMessage(this._stateOn, this._brightness); } } if (erp1 !== undefined) { await this.sendErp1Telegram(erp1); } } } EnoGateway_eepMessageReceived(message) { this.platform.log.debug(`${this.accessory.displayName}: ${message.toString()}`); if (message.values.isOn !== undefined) { this._stateOn = (message.values.isOn ?? false) || (message.values.buttons?.includes('B0') ?? false); this.accessory.context.on = this._stateOn; this.platform.log.info(`${this.accessory.displayName}: UPDATE on ${this._stateOn}`); this._service.updateCharacteristic(this.hap.Characteristic.On, this._stateOn); } // TODO Consider adding brightness characteristic automatically if (message.values.brightness !== undefined && this._stateOn) { this._brightness = (message.values.brightness); this.accessory.context.brightness = this._brightness; this.platform.log.info(`${this.accessory.displayName}: UPDATE brightness ${this._brightness}`); this._service.updateCharacteristic(this.hap.Characteristic.Brightness, this._brightness); } } } exports.LightbulbAccessory = LightbulbAccessory; //# sourceMappingURL=LightbulbAccessory.js.map