UNPKG

@pst-on-npm/homebridge-enocean

Version:
67 lines • 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnoTransmittingAccessory = void 0; const EnoAccessory_1 = require("./EnoAccessory"); /** * An abstract class representing an accessory that can transmit EnOcean messages. * This class extends `EnoAccessory` and implements `IEnoAccessory`. * It provides functionality to set up a gateway, manage sender IDs, and send ERP1 telegrams. * * @abstract */ class EnoTransmittingAccessory extends EnoAccessory_1.EnoAccessory { _gateway; _senderId; /** * Constructs a new instance of the `EnoTransmittingAccessory` class. * * @param platform - The EnOcean Homebridge platform instance. * @param accessory - The platform accessory associated with this EnOcean accessory. * @param config - The device configuration for this accessory. */ constructor(platform, accessory, config) { super(platform, accessory, config); } /** * Sets the gateway for this accessory and allocates a sender ID. * Registers the accessory with the gateway and sets up message handling. * * @param gateway - The EnOcean gateway to associate with this accessory. * @returns A promise that resolves when the gateway is successfully set. * @throws A warning is logged if the sender ID cannot be claimed due to exceeding the limit. */ async setGateway(gateway) { this._gateway = gateway; // Allocate new or persisted sender ID this.accessory.context.localSenderIndex = gateway .claimSenderIndex(this.accessory.context.localSenderIndex); if (this.accessory.context.localSenderIndex !== undefined) { this._senderId = gateway.getSenderId(this.accessory.context.localSenderIndex); } else { this.platform.log.warn(`${this.accessory.displayName}: Failed to claim individual sender id. The limit of 128 might be exceeded.`); } // Register message receiver and senderId in the gateway return this._gateway.registerEnoAccessory(this.config, this.EnoGateway_eepMessageReceived.bind(this), this._senderId); } /** * Sends an ERP1 telegram using the associated gateway. * * @param telegram - The ERP1 telegram to send. * @returns A promise that resolves when the telegram is successfully sent. * @throws An error if no gateway is defined or if the local sender ID is not defined. */ async sendErp1Telegram(telegram) { if (this._gateway === undefined) { throw 'Invalid operation: No gateway devined'; } if (this._senderId === undefined) { throw 'Invalid Operation: local sender ID not defined'; } telegram.sender = this._senderId; telegram.destination = this.config.devId; return this._gateway.enqueueErp1Telegram(telegram); } } exports.EnoTransmittingAccessory = EnoTransmittingAccessory; //# sourceMappingURL=EnoTransmittingAccessory.js.map