UNPKG

homebridge-hca

Version:

HCA plugin for Homebridge

50 lines (37 loc) 1.75 kB
// 'use strict'; class AccessoryBase { constructor(log, item, client) { if (!log) throw new Error('Accessories must be created with a \'log\' instance.'); if (!item) throw new Error('Accessories must be created with an \'item\' instance.'); if (!client) throw new Error('Accessories must be created with a \'client\' instance.'); this.log = log; this.client = client; this.name = item.voiceAssistantName || item.name; this.manufacturer = item.manufacturer || 'Default-Manufacturer'; this.serialNumber = item.tag || `HCA-${item.id}`; this.model = item.model || 'Default-Model'; this.firmwareRevision = item.firmwareRevision || '0.0.0'; const accessoryUUID = uuid.generate('hca:accessories:' + item.uid); // Accessory.call(this, this.name, accessoryUUID); Object.assign(this, new Accessory(this.name, accessoryUUID)); this.context.item = item; const self = this; this .getService(Service.AccessoryInformation) .setCharacteristic(Characteristic.Name, this.name) .setCharacteristic(Characteristic.Manufacturer, this.manufacturer) .setCharacteristic(Characteristic.SerialNumber, this.serialNumber) .setCharacteristic(Characteristic.Model, this.model) .setCharacteristic(Characteristic.FirmwareRevision, this.firmwareRevision); if (typeof this.identify === "function") { this .on('identify', function (paired, callback) { self.identify(paired, callback); }); } // TODO: Remove after all accessories have been updated. Initialization will occur within the inheriting accessory. if (this.init) this.init(); if (this.bindUpdates) this.bindUpdates(); } } module.exports = AccessoryBase;