UNPKG

@pst-on-npm/homebridge-enocean

Version:
105 lines • 5.01 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.OutletAccessory = 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 OutletAccessory extends EnoTransmittingAccessory_1.EnoTransmittingAccessory { _service; _stateOn; constructor(platform, accessory, config) { super(platform, accessory, config); if (accessory.context.on === undefined) { accessory.context.on = false; } this._stateOn = accessory.context.on; // 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.Outlet) || this.accessory.addService(this.hap.Service.Outlet, 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/Outlet // 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)); } 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.newFourBSGatewaySwitchingMessage(this._stateOn); } } else if (this.config.eepId.rorg === EnoCore.RORGs.RPS) { erp1 = EnoMessageFactory_1.EnoMessageFactory.newRpsOnMessage(this._stateOn); } 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); } } } exports.OutletAccessory = OutletAccessory; //# sourceMappingURL=OutletAccessory.js.map