UNPKG

node-hue-api

Version:
44 lines (43 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Cache = void 0; const hue_bridge_model_1 = require("@peter-murray/hue-bridge-model"); const LightIdPlaceholder_1 = require("./placeholders/LightIdPlaceholder"); const LIGHT_ID_PLACEHOLDER = new LightIdPlaceholder_1.LightIdPlaceholder(); class Cache { constructor(data) { this.data = data; this._lights = {}; } /** * Obtains a known light from the cache * @param id {Number | String} The id for the light. */ getLight(id) { const lightId = LIGHT_ID_PLACEHOLDER.getValue({ id: id }); let light = this._lights[lightId]; if (!light) { let lightData = this.data.lights[lightId]; if (lightData) { light = hue_bridge_model_1.model.createFromBridge('light', lightId, lightData); this._lights[lightId] = light; } } return light; } /** * Get the modelid for the bridge. */ get modelid() { // BSB001 is the first generation bridge, BSB002 is the current generation one that can support entertainment API return this.data.config.modelid; } /** * Get the API version for the bridge. * @return The Api Version for the bridge. */ get apiversion() { return this.data.config.apiversion; } } exports.Cache = Cache;