UNPKG

node-hue-api

Version:
40 lines (39 loc) 1.24 kB
import { model } from '@peter-murray/hue-bridge-model'; import { LightIdPlaceholder } from './placeholders/LightIdPlaceholder'; const LIGHT_ID_PLACEHOLDER = new LightIdPlaceholder(); export 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 = 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; } }