UNPKG

node-hue-api

Version:
69 lines (68 loc) 2.71 kB
import { ApiDefinition } from './http/ApiDefinition'; import { scenesApi } from './http/endpoints/scenes'; import { SceneIdPlaceholder } from './placeholders/SceneIdPlaceholder'; import { model } from '@peter-murray/hue-bridge-model'; const SCENE_ID_PLACEHOLDER = new SceneIdPlaceholder(); export class Scenes extends ApiDefinition { constructor(hueApi) { super(hueApi); } getAll() { return this.execute(scenesApi.getAll); } // /** // * @deprecated since 4.x use getScene(id) instead. // */ // get(id) { // util.deprecatedFunction('5.x', 'scenes.get(id)', 'Use scenes.getScene(id) instead.'); // return this.getScene(id); // } getScene(id) { return this.execute(scenesApi.getScene, { id: id }); } // /** // * @deprecated since 4.x use getSceneByName(name) instead. // */ // getByName(name) { // util.deprecatedFunction('5.x', 'scenes.getByName(name)', 'Use scenes.getSceneByName(name) instead.'); // return this.getSceneByName(name); // } getSceneByName(name) { return this.getAll().then((allScenes) => { return allScenes.filter(scene => scene.name === name); }); } createScene(scene) { const self = this; return this.execute(scenesApi.createScene, { scene: scene }) .then(data => { return self.getScene(data.id); }); } // /** // * @deprecated since 4.x use updateScene(scene) instead. // */ // update(id, scene) { // util.deprecatedFunction('5.x', 'scenes.update(id, scene)', 'Use scenes.updateScene(scene) instead.'); // return this.execute(scenesApi.updateScene, {id: id, scene: scene}); // } updateScene(scene) { return this.execute(scenesApi.updateScene, { id: scene, scene: scene }); } /** * Updates the light state for a specific light in the scene */ updateLightState(id, lightId, sceneLightState) { return this.execute(scenesApi.updateSceneLightState, { id: id, lightStateId: lightId, lightState: sceneLightState }); } deleteScene(id) { return this.execute(scenesApi.deleteScene, { id: id }); } activateScene(id) { // Scene activation is done as an intersection of setting a group light state to a scene id, the intersection of the // scene light ids and that of the group is the lights that are targeted to change. const sceneId = SCENE_ID_PLACEHOLDER.getValue({ id: id }); // We target the all lights group here, so that all the lights in the scene are targeted. return this.hueApi.groups.setGroupState(0, new model.GroupState().scene(sceneId)); } }