UNPKG

hue-hacking-node

Version:

Utility to control Philips Hue light bulbs

341 lines (340 loc) 13.9 kB
import { AxiosInstance } from 'axios'; import { HueColors } from './hue-colors.js'; import { HueBridge, HueBridgeGroupActionResponse, HueBridgeStateChangeResponse, HueConfig, HueUPNPResponse, Lamp, States, XYPoint } from './hue-interfaces.js'; export declare class Hue extends HueBridge { private config?; private lampStates; private baseApiUrl; private _http; constructor(config?: HueConfig); /** * Set the IP address of the bridge and the API key to use to control * the Hue lamps. * * @param {HueConfig} config Configuration object. */ private setConfig; /** * Retrieve the existing state of all connected lamps. * * @return {Promise<any>} Promise representing the remote call(s) */ private retrieveInitialState; /** * 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 */ private putJSON; /** * 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 */ private get; /** * 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 */ private getState; /** * 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 */ private buildLampCompositeURL; /** * 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. */ private buildLampQueryURL; /** * 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 */ private buildStateURL; /** * 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 */ private buildGroupActionURL; /** * 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 */ private put; /** * 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 */ private putGroupAction; /** * 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. */ private buildXYState; /** * 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. */ getBrightness(lampIndex: number): Promise<number>; /** * 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. */ private buildBrightnessState; /** * 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. */ private buildDimState; /** * 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. */ private buildBrightenState; /** * Query Philips' nupnp endpoint for details of any Hue bridges attached to the LAN. * * @return {Promise<string>} Promise representing the remote call */ static search(): Promise<HueUPNPResponse[]>; /** * Color manipulation utility */ colors: HueColors; /** * Perform initialization of this Hue instance */ init(): Promise<void>; /** * 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 */ flash(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Flash all connected lamps for a short time. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ flashAll(): Promise<HueBridgeGroupActionResponse>; /** * 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 */ longFlash(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Flash all connected lamps for a long time. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ longFlashAll(): Promise<HueBridgeGroupActionResponse>; /** * 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 */ setColor(lampIndex: number, color: string | XYPoint): Promise<HueBridgeStateChangeResponse>; /** * 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. */ setColorTemperature(lampIndex: number, colorTemperature: number): Promise<HueBridgeStateChangeResponse>; /** * 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 */ setAllColors(color: string | XYPoint): Promise<HueBridgeGroupActionResponse>; /** * 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 */ turnOff(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * 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 */ turnOn(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Turn off all connected lamps. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ turnOffAll(): Promise<HueBridgeGroupActionResponse>; /** * Turn on all connected lamps. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ turnOnAll(): Promise<HueBridgeGroupActionResponse>; /** * 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 */ setBrightness(lampIndex: number, brightness: number): Promise<HueBridgeStateChangeResponse>; /** * Set the brightness of all connected lamps. * * @param {number} brightness Integer value between 0 and 254. * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ setAllBrightness(brightness: number): Promise<HueBridgeGroupActionResponse>; /** * 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 */ setGroupBrightness(groupIndex: number, brightness: number): Promise<HueBridgeGroupActionResponse>; /** * 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 */ dim(lampIndex: number, decrement?: number): Promise<HueBridgeStateChangeResponse>; /** * 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 */ dimAll(decrement?: number): Promise<HueBridgeGroupActionResponse>; /** * 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 */ brighten(lampIndex: number, increment?: number): Promise<HueBridgeStateChangeResponse>; /** * 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 */ brightenAll(increment?: number): Promise<HueBridgeGroupActionResponse>; /** * 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 */ startColorLoop(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * 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 */ stopEffect(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Get the attributes of all lamps currently connected to the Hue bridge. * * @return {Promise<States.LampState[]>} Promise representing the remote call */ getLampStates(): Promise<States.LampState[]>; getLampState(index: number): Promise<States.LampState>; /** * Get a collection of lamps that the local bridge is aware of. * * @return {Promise<Lamp[]>} Collection of known lamps. */ getLamps(): Promise<Lamp[]>; /** * Return the value of the configured transitionTime property. * * @return {number} Value of the transitionTime property. Null by default if not * set. */ getTransitionTime(): number; /** * Set the value of the transitionTime property. * * @param {number} time Lamp color transition time in approximate milliseconds. */ setTransitionTime(time: number): void; /** * Set the number of lamps available to control. * * @param {number} numLamps The total number of lamps available to interact with. Default is 3. */ setnumberOfLamps(numLamps: number): void; /** * Get the number of lamps available to control. */ getNumberOfLamps(): number; /** * Get a reference to the bundled color utility module. */ getColors(): HueColors; /** * Get the currently set options. */ getConfig(): HueConfig; /** * Get a handle on the axios instance used to perform HTTP calls. */ getHttp(): AxiosInstance; /** * Get a handle on the separate axios instance used to perform HTTP calls for static functions. */ static getHttp(): AxiosInstance; }