node-hue-api
Version:
Philips Hue API Library for Node.js
73 lines (72 loc) • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Scenes = void 0;
const ApiDefinition_1 = require("./http/ApiDefinition");
const scenes_1 = require("./http/endpoints/scenes");
const SceneIdPlaceholder_1 = require("./placeholders/SceneIdPlaceholder");
const hue_bridge_model_1 = require("@peter-murray/hue-bridge-model");
const SCENE_ID_PLACEHOLDER = new SceneIdPlaceholder_1.SceneIdPlaceholder();
class Scenes extends ApiDefinition_1.ApiDefinition {
constructor(hueApi) {
super(hueApi);
}
getAll() {
return this.execute(scenes_1.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(scenes_1.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(scenes_1.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(scenes_1.scenesApi.updateScene, { id: scene, scene: scene });
}
/**
* Updates the light state for a specific light in the scene
*/
updateLightState(id, lightId, sceneLightState) {
return this.execute(scenes_1.scenesApi.updateSceneLightState, { id: id, lightStateId: lightId, lightState: sceneLightState });
}
deleteScene(id) {
return this.execute(scenes_1.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 hue_bridge_model_1.model.GroupState().scene(sceneId));
}
}
exports.Scenes = Scenes;