UNPKG

hue-hacking-node

Version:

Utility to control Philips Hue light bulbs

339 lines (338 loc) 13.1 kB
import { HueColors } from './hue-colors.js'; export interface HueConfig { /** API key / appname registered with the Hue bridge (requires physical access to the hardware to initially configure) */ key: string; /** IP address of your connected Hue bridge */ ip: string; /** Number of lamps that can be controlled by your Hue bridge (3 if no value supplied here) */ numberOfLamps?: number; /** Flag indicating that the initial brightness state should be queried from the bridge */ retrieveInitialState?: boolean; /** Number of milliseconds between lamp state changes */ transitionTime?: number; /** Timeout (in milliseconds) of all remote bridge communication */ timeout?: number; } export declare abstract class HueBridge { /** * 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. */ abstract getBrightness(lampIndex: number): Promise<number>; /** Perform initialization of this Hue instance. */ abstract 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 */ abstract flash(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Flash all connected lamps for a short time. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ abstract 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 */ abstract longFlash(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Flash all connected lamps for a long time. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ abstract 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} color String representing a hexadecimal color value. * @return {Promise<HueBridgeStateChangeResponse>} Promise representing the remote call */ abstract setColor(lampIndex: number, color: string): 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. */ abstract 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} color String representing a hexadecimal color value. * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ abstract setAllColors(color: string): 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 */ abstract 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 */ abstract turnOn(lampIndex: number): Promise<HueBridgeStateChangeResponse>; /** * Turn off all connected lamps. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ abstract turnOffAll(): Promise<HueBridgeGroupActionResponse>; /** * Turn on all connected lamps. * * @return {Promise<HueBridgeGroupActionResponse>} Promise representing the remote call */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract 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 */ abstract getLampStates(): Promise<States.LampState[]>; /** * Get the attributes of a specifically indexed lamp. * * @param index 1-based index of the lamp for which to retrieve current state * @return {Promise<States.LampState} Promise representing the remote call */ abstract 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. */ abstract getLamps(): Promise<Lamp[]>; /** * Return the value of the configured transitionTime property. * * @return {number} Value of the transitionTime property. Null by default if not * set. */ abstract getTransitionTime(): number; /** * Set the value of the transitionTime property. * * @param {number} time Lamp color transition time in approximate milliseconds. */ abstract 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. */ abstract setnumberOfLamps(numLamps: number): void; /** Get the number of lamps available to control. */ abstract getNumberOfLamps(): number; /** Get a reference to the bundled color utility module. */ abstract getColors(): HueColors; /** Get the currently set options. */ abstract getConfig(): HueConfig; } export interface IHueUPNPResponse { id: string; internalipaddress: string; } export declare class HueUPNPResponse implements IHueUPNPResponse { id: string; internalipaddress: string; constructor(data: any); } export declare namespace States { interface PoweredState { on?: boolean; } type AlertOption = 'select' | 'lselect' | 'none'; interface AlertState { alert?: AlertOption; } type EffectOption = 'colorloop' | 'none'; interface EffectState { effect?: EffectOption; } interface ColorState { xy?: number[]; } interface BrightnessState { bri?: number; } interface BrightnessIncrementState { bri_inc?: number; } interface HueState { hue?: number; } interface SaturationState { sat?: number; } interface ColorTempState { ct?: number; } type ColormodeOption = 'hs' | 'xy' | 'ct'; interface ColormodeState { colormode?: ColormodeOption; } interface ReachableState { reachable?: boolean; } interface FullLampState { on: boolean; bri: number; hue: number; sat: number; effect: EffectOption; xy: number[]; ct: number; alert: AlertOption; colormode: ColormodeOption; reachable: boolean; } type LampState = Partial<FullLampState>; } export interface Lamp { lampIndex: number; state: States.LampState; type: string; name: string; modelid: string; swversion: string; pointsymbol?: any; } export type HueStateValue = string | number | number[] | boolean; export interface UpdateConfirmation { success: StateChangeConfirmation | GroupActionConfirmation; } export interface StateChangeConfirmation { attribute: string; value: HueStateValue; } export declare class HueBridgeStateChangeResponse { changedStates: StateChangeConfirmation[]; constructor(response: any[]); } export interface GroupActionConfirmation { address: string; value: HueStateValue; } export declare class HueBridgeGroupActionResponse { acknowledgedActions: GroupActionConfirmation[]; constructor(response: any[]); } /** * Clamp a provided value into a range such that min <= value <= max. * * @param min Smallest possible acceptable value * @param max Largest possible acceptable value * @param value Value that must be between min and max, inclusive */ export declare function clampToRange(min: number, max: number, value: number): number; /** * Convenience wrapper class around the two floating point numbers that represent * a position in the CIE 1931 color gamut triangle. */ export declare class XYPoint { x: number; y: number; constructor(...xy: number[]); /** Return a human readable representation of this XYPoint instance. */ toString(): string; } /** * Convenience wrapper class around the three 0-255 range integer values representing * a traditional RGB color. */ export declare class RGB { private static MIN; private static MAX; r: number; g: number; b: number; constructor(...rgb: number[]); /** Return a human-readable representation of this RGB color value. */ toString(): string; /** Return a usable CSS rgb() function notation representation of this RGB color value. */ toCssString(): string; }