UNPKG

homebridge-framework

Version:
89 lines (88 loc) 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var homebridge_platform_registration_1 = require("./homebridge-platform-registration"); /** * Represents the helper for registering the platform. */ var Homebridge = /** @class */ (function () { function Homebridge() { } /** * Creates a registration function for the platform and returns it. * @param platform The platform that should be registered. * @returns Returns the registration function that can be exported in the main file. */ Homebridge.register = function (platform) { // Initializes the registration object, which is used to hand over the constructor objects to the platform var registration = new homebridge_platform_registration_1.HomebridgePlatformRegistration(); // Defines a proxy object which is created by homebridge function Proxy(proxyLogger, proxyConfiguration, proxyApi) { registration.api = proxyApi; registration.logger = proxyLogger; registration.configuration = proxyConfiguration; // Registers a global variable that contains the HAP API, so that in can be easily referenced in the code without having to navigate via the homebridge API global.homebridgeFrameworkHap = proxyApi.hap; // Calls the register function so that the objects are registered at the platform platform.register(registration); } // Defines the required configureAccessory function that is called by homebridge Proxy.prototype.configureAccessory = function (accessory) { registration.cachedPlatformAccessories.push(accessory); }; // Returns the registration function return function (api) { var platformPluginConstructor = Proxy; api.registerPlatform(platform.pluginName, platform.platformName, platformPluginConstructor); }; }; Object.defineProperty(Homebridge, "Services", { /** * Gets the HAP service types. */ get: function () { // Checks if the global variable has already been set var hap = global.homebridgeFrameworkHap; if (hap === undefined) { throw new Error("The platform has not been registered yet."); } // Returns the service type (that contains the actual derived service types) return hap.Service; }, enumerable: true, configurable: true }); Object.defineProperty(Homebridge, "Characteristics", { /** * Gets the HAP characteristic types. */ get: function () { // Checks if the global variable has already been set var hap = global.homebridgeFrameworkHap; if (hap === undefined) { throw new Error("The platform has not been registered yet."); } // Returns the characteristic type (that contains the actual derived characteristic types) return hap.Characteristic; }, enumerable: true, configurable: true }); Object.defineProperty(Homebridge, "Categories", { /** * Gets the HAP categories. */ get: function () { // Checks if the global variable has already been set var hap = global.homebridgeFrameworkHap; if (hap === undefined) { throw new Error("The platform has not been registered yet."); } // Returns the characteristic type (that contains the actual derived characteristic types) return hap.Categories; }, enumerable: true, configurable: true }); return Homebridge; }()); exports.Homebridge = Homebridge;