UNPKG

hue-hacking-node

Version:

Utility to control Philips Hue light bulbs

881 lines 37.1 kB
"use strict"; /* Copyright (c) 2013 Bryan Johnson; Licensed MIT */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Hue = void 0; var axios_1 = require("axios"); var hue_colors_js_1 = require("./hue-colors.js"); var hue_interfaces_js_1 = require("./hue-interfaces.js"); var offState = { on: false }; var onState = { on: true }; var shortFlashState = { alert: 'select' }; var longFlashState = { alert: 'lselect' }; var colorLoopEffect = { effect: 'colorloop' }; var noEffect = { effect: 'none' }; var _colors = new hue_colors_js_1.HueColors(); var nupnpEndpoint = "https://discovery.meethue.com/"; var _http = axios_1.default.create({ timeout: 5000 }); var Hue = /** @class */ (function (_super) { __extends(Hue, _super); function Hue(config) { var _this = _super.call(this) || this; _this.config = config; _this.lampStates = []; _this.baseApiUrl = ''; _this._http = null; /** * Color manipulation utility */ _this.colors = _colors; _this.setConfig(config); return _this; } /** * Set the IP address of the bridge and the API key to use to control * the Hue lamps. * * @param {HueConfig} config Configuration object. */ Hue.prototype.setConfig = function (config) { this.config = config || { ip: 'localhost', key: 'testapp', retrieveInitialState: false, numberOfLamps: 3 }; this.config.retrieveInitialState = this.config.retrieveInitialState || false; this.config.numberOfLamps = this.config.numberOfLamps || 3; this.config.transitionTime = this.config.transitionTime || 400; this.config.timeout = this.config.timeout || 2000; this._http = axios_1.default.create({ timeout: this.config.timeout }); this.baseApiUrl = "http://".concat(this.config.ip, "/api/").concat(this.config.key); }; /** * Retrieve the existing state of all connected lamps. * * @return {Promise<any>} Promise representing the remote call(s) */ Hue.prototype.retrieveInitialState = function () { return __awaiter(this, void 0, void 0, function () { var promises, _loop_1, this_1, i; var _this = this; return __generator(this, function (_a) { promises = []; if (this.config.retrieveInitialState) { _loop_1 = function (i) { var promise = this_1.getState(i + 1); promises.push(promise); promise.then(function (r) { _this.lampStates[i] = r.data.state; }); }; this_1 = this; for (i = 0; i < this.config.numberOfLamps; i++) { _loop_1(i); } } else { // immediately resolve a void Promise promises.push(Promise.resolve()); } return [2 /*return*/, Promise.all(promises)]; }); }); }; /** * Convenience function to perform an asynchronous HTTP PUT with the * provided JSON data. * * @param {string} url The URL to send the PUT request to * @param {Object} data The JSON data * @return {Promise<AxiosResponse>} Promise representing the remote call to the Hue bridge */ Hue.prototype.putJSON = function (url, data) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._http.put(url, data)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Convenience function used to query the state of a Hue lamp or other * bridge-administered resource. * * @param {string} destination URL to send HTTP GET request to * @return {Promise<AxiosResponse>} Promise representing the remote call to the Hue bridge */ Hue.prototype.get = function (destination) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this._http.get(destination)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Get the full attribute state of an indexed Hue lamp. * * @param {number} lampIndex 1-based index of the Hue lamp * @return {Promise<AxiosResponse>} Promise representing the remote call to the Hue bridge */ Hue.prototype.getState = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var url; return __generator(this, function (_a) { switch (_a.label) { case 0: url = this.buildLampQueryURL(lampIndex); return [4 /*yield*/, this.get(url)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Convenience function used to build a URL to query all connected lamps. * * @return {string} URL to query all connected lamps and their full attribute set */ Hue.prototype.buildLampCompositeURL = function () { return "".concat(this.baseApiUrl, "/lights"); }; /** * Convenience function used to build a URL to query a lamp's status. * * @param {number} lampIndex 1-based index of the Hue lamp. * @return {string} URL to query a specific lamp. */ Hue.prototype.buildLampQueryURL = function (lampIndex) { return "".concat(this.buildLampCompositeURL(), "/").concat(lampIndex); }; /** * Convenience function used to build a state URL for a provided Hue lamp * index. * * @param {number} lampIndex 1-based index of the Hue lamp * @return {string} URL to put state to a lamp */ Hue.prototype.buildStateURL = function (lampIndex) { return "".concat(this.buildLampQueryURL(lampIndex), "/state"); }; /** * Convenience function used to build a state URL for a provided Hue lamp * group. * * @param {number} groupIndex 0-based index of the lamp group (where 0 refers to the reserved group of all connected lamps) * @return {string} URL to trigger a group action */ Hue.prototype.buildGroupActionURL = function (groupIndex) { var group = groupIndex || 0; return "".concat(this.baseApiUrl, "/groups/").concat(group, "/action"); }; /** * Convenience function used to initiate an HTTP PUT request to modify * state. * * @param {number} lampIndex 1-based index of the Hue lamp to modify. * @param {string} data String containing the JSON state object to commit to the lamp. * @return {AxiosPromise} Promise representing the remote call to the Hue bridge */ Hue.prototype.put = function (lampIndex, data) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putJSON(this.buildStateURL(lampIndex), data)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Convenience function used to initiate an HTTP PUT request to modify state of a group of lamps. * * @param {number} Index of the lamp group to modify * @param {Object} Object containing desired lamp state * @return {AxiosPromise} Promise representing the remote call to the Hue bridge */ Hue.prototype.putGroupAction = function (groupIndex, action) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putJSON(this.buildGroupActionURL(groupIndex), action)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Builds a JSON state object for the CIE 1931 color coordinates provided. * If the transitionTime property has been set, it is also included in the * JSON object. * * @param {number[]} xyCoords CIE 1931 X,Y color coordinates. * @return {States.ColorState} State object containing CIE X,Y coordinates. */ Hue.prototype.buildXYState = function (xyCoords) { return { xy: [xyCoords.x, xyCoords.y] }; }; /** * Returns the brightness of the lamp at lampIndex. * * @param {number} lampIndex 1-based index of the lamp to query. * @return {Promise<number>} Promise to retrieve the brightness of the lamp at lampIndex. 0 - 254. */ Hue.prototype.getBrightness = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var url, data; return __generator(this, function (_a) { switch (_a.label) { case 0: url = this.buildLampQueryURL(lampIndex); return [4 /*yield*/, this.get(url)]; case 1: data = (_a.sent()).data; return [2 /*return*/, data.state.bri]; } }); }); }; /** * Builds a JSON state object used to set the brightness of a Hue lamp to * the value of the brightness parameter. * * @param {number} brightness Integer value between 0 and 254. Note that 0 * is not equivalent to the lamp's off state. A value outside of the allowed range will be clamped. * @return {Object} JSON object used to set brightness. */ Hue.prototype.buildBrightnessState = function (brightness) { var clamped = (0, hue_interfaces_js_1.clampToRange)(0, 254, brightness); return { bri: clamped }; }; /** * Builds a JSON state object used to set a brightness decrement of a Hue lamp (a negative bri_inc is effectively a decrement). * * @param {number | undefined} decrement Integer value between 0 and 254. The positive value will be negated. */ Hue.prototype.buildDimState = function (decrement) { return { bri_inc: -Math.abs(decrement || 10) }; }; /** * Builds a JSON state object used to set a brightness increment of a Hue lamp. * * @param {number | undefined} increment Integer value between 0 and 254. A negative value will be converted to an absolute value. */ Hue.prototype.buildBrightenState = function (increment) { var incrementState = this.buildDimState(increment); incrementState.bri_inc = Math.abs(incrementState.bri_inc); return incrementState; }; /** * Query Philips' nupnp endpoint for details of any Hue bridges attached to the LAN. * * @return {Promise<string>} Promise representing the remote call */ Hue.search = function () { return __awaiter(this, void 0, void 0, function () { var nupnpResponse, bridges; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, _http.get(nupnpEndpoint)]; case 1: nupnpResponse = _a.sent(); bridges = nupnpResponse.data; return [2 /*return*/, bridges.map(function (b) { return new hue_interfaces_js_1.HueUPNPResponse(b); })]; } }); }); }; /** * Perform initialization of this Hue instance */ Hue.prototype.init = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.retrieveInitialState()]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Flash the lamp at lampIndex for a short time. * * @param {number} lampIndex 1-based index of the Hue lamp to flash. * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.flash = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.put(lampIndex, shortFlashState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Flash all connected lamps for a short time. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.flashAll = function () { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putGroupAction(0, shortFlashState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Flash the lamp at lampIndex for a long time. * * @param {number} lampIndex 1-based index of the Hue lamp to flash. * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.longFlash = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.put(lampIndex, longFlashState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Flash all connected lamps for a long time. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.longFlashAll = function () { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putGroupAction(0, longFlashState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Set the lamp at lampIndex to the approximate CIE x,y equivalent of * the provided hex color. * * @param {number} lampIndex 1-based index of the Hue lamp to colorize. * @param {string | XYPoint} color String representing a hexadecimal color value (or an XYPoint) * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.setColor = function (lampIndex, color) { return __awaiter(this, void 0, void 0, function () { var cieColor, xyState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: cieColor = color instanceof hue_interfaces_js_1.XYPoint ? color : this.colors.getCIEColor(color); xyState = this.buildXYState(cieColor); return [4 /*yield*/, this.put(lampIndex, xyState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Set the color temperature of the lamp at lampIndex. * * @param {number} lampIndex 1-based index of the Hue lamp to colorize. * @param {number} colorTemperature Color temperature (in Kelvin) to set the lamp to (The approximate range is 2000 - 6000). * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call. */ Hue.prototype.setColorTemperature = function (lampIndex, colorTemperature) { return __awaiter(this, void 0, void 0, function () { var clampedK, convertedTemp, data; return __generator(this, function (_a) { switch (_a.label) { case 0: clampedK = (0, hue_interfaces_js_1.clampToRange)(2000, 6000, colorTemperature); convertedTemp = Math.floor(this.colors.kelvinToMired(clampedK)); return [4 /*yield*/, this.put(lampIndex, { ct: convertedTemp })]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Sets all connected lamps to the approximate CIE x,y equivalent of * the provided hex color. * * @param {string | XYPoint} color String representing a hexadecimal color value (or an XYPoint) * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.setAllColors = function (color) { return __awaiter(this, void 0, void 0, function () { var cieColor, xyState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: cieColor = color instanceof hue_interfaces_js_1.XYPoint ? color : this.colors.getCIEColor(color); xyState = this.buildXYState(cieColor); return [4 /*yield*/, this.putGroupAction(0, xyState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Turn off the lamp at lampIndex. * * @param {number} lampIndex 1-based index of the Hue lamp to turn off. * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.turnOff = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.put(lampIndex, offState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Turn on the lamp at lampIndex. * * @param {number} lampIndex 1-based index of the Hue lamp to turn on. * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.turnOn = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.put(lampIndex, onState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Turn off all connected lamps. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.turnOffAll = function () { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putGroupAction(0, offState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Turn on all connected lamps. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.turnOnAll = function () { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putGroupAction(0, onState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Set the brightness of the lamp at lampIndex. * * @param {number} lampIndex 1-based index of the Hue lamp to modify. * @param {number} brightness Integer value between 0 and 254. * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.setBrightness = function (lampIndex, brightness) { return __awaiter(this, void 0, void 0, function () { var briState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: briState = this.buildBrightnessState(brightness); return [4 /*yield*/, this.put(lampIndex, briState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Set the brightness of all connected lamps. * * @param {number} brightness Integer value between 0 and 254. * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.setAllBrightness = function (brightness) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.setGroupBrightness(0, brightness)]; case 1: return [2 /*return*/, _a.sent()]; } }); }); }; /** * Set the brightness of an indexed group of lamps. * * @param {number} groupIndex 0-based lamp group index. * @param {number} brightness Integer value between 0 and 254. * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.setGroupBrightness = function (groupIndex, brightness) { return __awaiter(this, void 0, void 0, function () { var briState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: briState = this.buildBrightnessState(brightness); return [4 /*yield*/, this.putGroupAction(groupIndex, briState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Dim the lamp at lampIndex by decrement. * * @param {number} lampIndex 1-based lamp index. * @param {number} [decrement] Amount to decrement brightness by (between 0 and 255). * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.dim = function (lampIndex, decrement) { return __awaiter(this, void 0, void 0, function () { var dimState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: dimState = this.buildDimState(decrement); return [4 /*yield*/, this.put(lampIndex, dimState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Dim all lamps by decrement. * * @param {number} [decrement] Amount to decrement brightness by (between 0 and 255). * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.dimAll = function (decrement) { return __awaiter(this, void 0, void 0, function () { var dimState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: dimState = this.buildDimState(decrement); return [4 /*yield*/, this.putGroupAction(0, dimState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Brighten the lamp at lampIndex by increment. * * @param {number} lampIndex 1-based lamp index. * @param {number} [increment] Amount to increment brightness by (between 0 and 255). * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.brighten = function (lampIndex, increment) { return __awaiter(this, void 0, void 0, function () { var brightenState, data; return __generator(this, function (_a) { switch (_a.label) { case 0: brightenState = this.buildBrightenState(increment); return [4 /*yield*/, this.put(lampIndex, brightenState)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Brighten all lamps by increment. * * @param {number} increment Amount to increment brightness by (between 0 and 255). * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ Hue.prototype.brightenAll = function (increment) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.putGroupAction(0, this.buildBrightenState(increment))]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeGroupActionResponse(data)]; } }); }); }; /** * Enable the colorloop effect on the indexed Hue lamp. * * @param {number} lampIndex The indexed lamp to enable the effect on * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.startColorLoop = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.put(lampIndex, colorLoopEffect)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Stop the currently enabled effect (if any) on the indexed Hue lamp. * * @param {number} lampIndex The indexed lamp to enable the effect on * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ Hue.prototype.stopEffect = function (lampIndex) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.put(lampIndex, noEffect)]; case 1: data = (_a.sent()).data; return [2 /*return*/, new hue_interfaces_js_1.HueBridgeStateChangeResponse(data)]; } }); }); }; /** * Get the attributes of all lamps currently connected to the Hue bridge. * * @return {Promise<States.LampState[]>} Promise representing the remote call */ Hue.prototype.getLampStates = function () { return __awaiter(this, void 0, void 0, function () { var lamps; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getLamps()]; case 1: lamps = _a.sent(); return [2 /*return*/, lamps.filter(function (l) { return l.state.reachable; }).map(function (l) { return l.state; })]; } }); }); }; Hue.prototype.getLampState = function (index) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.getState(index)]; case 1: data = (_a.sent()).data; return [2 /*return*/, data.state]; } }); }); }; /** * Get a collection of lamps that the local bridge is aware of. * * @return {Promise<Lamp[]>} Collection of known lamps. */ Hue.prototype.getLamps = function () { return __awaiter(this, void 0, void 0, function () { var url, data; return __generator(this, function (_a) { switch (_a.label) { case 0: url = this.buildLampCompositeURL(); return [4 /*yield*/, this.get(url)]; case 1: data = (_a.sent()).data; return [2 /*return*/, Object.keys(data).map(function (k) { return (__assign(__assign({}, data[k]), { lampIndex: parseInt(k) })); })]; } }); }); }; /** * Return the value of the configured transitionTime property. * * @return {number} Value of the transitionTime property. Null by default if not * set. */ Hue.prototype.getTransitionTime = function () { return this.config.transitionTime; }; /** * Set the value of the transitionTime property. * * @param {number} time Lamp color transition time in approximate milliseconds. */ Hue.prototype.setTransitionTime = function (time) { this.config.transitionTime = time; }; /** * Set the number of lamps available to control. * * @param {number} numLamps The total number of lamps available to interact with. Default is 3. */ Hue.prototype.setnumberOfLamps = function (numLamps) { this.config.numberOfLamps = numLamps; }; /** * Get the number of lamps available to control. */ Hue.prototype.getNumberOfLamps = function () { return this.config.numberOfLamps; }; /** * Get a reference to the bundled color utility module. */ Hue.prototype.getColors = function () { return this.colors; }; /** * Get the currently set options. */ Hue.prototype.getConfig = function () { return this.config; }; /** * Get a handle on the axios instance used to perform HTTP calls. */ Hue.prototype.getHttp = function () { return this._http; }; /** * Get a handle on the separate axios instance used to perform HTTP calls for static functions. */ Hue.getHttp = function () { return _http; }; return Hue; }(hue_interfaces_js_1.HueBridge)); exports.Hue = Hue; //# sourceMappingURL=hue-node.js.map