UNPKG

xled2

Version:

Library to control Twinkly LED lights

303 lines (302 loc) 7.45 kB
/// <reference types="node" /> /// <reference types="node" /> import { AxiosInstance, AxiosResponse } from "axios"; import * as udp from "node:dgram"; /** * Represents a Twinkly device * @public * */ export declare class Light { ipaddr: string; challenge: string; net: AxiosInstance; token: AuthenticationToken | undefined; activeLoginCall: boolean; nleds: number | undefined; udpClient: udp.Socket; /** * Creates an instance of Light. * * @constructor * @param {string} ipaddr IP Address of the Twinkly device */ constructor(ipaddr: string, timeout?: number); autoEndLoginCall(): Promise<void>; /** * Sends a login request * * @returns {*} */ login(): Promise<void>; /** * Check that we are logged in to the device */ verify(): Promise<void>; /** * Ensure that we are logged into to the device, and if not initiate a login request */ ensureLoggedIn(): Promise<void>; /** * Gets details about the device * * @returns {Promise<object>} Results vary, see https://xled-docs.readthedocs.io/en/latest/rest_api.html#device-details */ getDeviceDetails(): Promise<object>; /** * Turns the device off * * @returns {unknown} */ setOff(): Promise<void>; /** * Sets the state * @experimental * @param {boolean} state - Set on/off */ setState(state: boolean): Promise<void>; /** * Get the name of the device * * @returns {Promise<string>} Name of device */ getName(): Promise<string>; /** * Sets the name of the device * * @param {string} name Desired device name, max 32 charachters * @returns {Promise<void>} */ setName(name: string): Promise<void>; /** * Gets time when lights will turn on and off * * @returns {Promise<timer>} */ getTimer(): Promise<timer>; /** * Sets the brightness level * * @param {number} value * @param {string} [mode="enabled"] * @param {string} [type="A"] * @returns {} */ setBrightness(value: number, mode?: string, type?: string): Promise<void>; /** * Gets the current brightness level * * @returns {number} Current brightness in range 0..100 */ getBrightness(): Promise<number>; /** * Gets the current colour in HSV */ getHSVColour(): Promise<hsvColour>; /** * Gets the current colour in RGB */ getRGBColour(): Promise<rgbColour>; /** * Sets the colour in RGB when in colour mode * * @param {rgbColour} colour A RGB colour */ setRGBColour(colour: rgbColour): Promise<void>; setRGBColourRealTime(colour: rgbColour): Promise<void>; /** * Sets the colour in HSV when in colour mode * * @param {hsvColour} colour A HSV colour */ setHSVColour(colour: hsvColour): Promise<void>; /** * Gets the LED operation mode * * @returns {deviceMode} mode */ getMode(): Promise<deviceMode>; /** * Sets the LED operation mode * * @param {deviceMode} mode */ setMode(mode: deviceMode): Promise<void>; /** * Sends a POST request to the device, appending the required tokens * * @param {string} url * @param {object} params */ sendPostRequest(url: string, params: object): Promise<any>; /** * Sends a GET request to the device, appending the required tokens * * @param {string} url * @param {object} params */ sendGetRequest(url: string, params?: object, requiresToken?: boolean): Promise<any>; sendRealTimeFrame(frame: Frame): Promise<any>; sendRealTimeFrameUDP(frame: Frame): Promise<void>; getListOfMovies(): Promise<Movie[]>; addMovie(movie: Movie): Promise<void>; getLayout(): Promise<any>; getNLeds(): Promise<number>; } export declare class Movie { id: number; name: string; unique_id: string; descriptor_type: string; leds_per_frame: number; frames_number: number; fps: number; constructor(data: any); export(): { id: number; name: string; unique_id: string; descriptor_type: string; leds_per_frame: number; frames: number; fps: number; }; } /** * Represents an authentication token used to login to an xled instance * @internal */ export declare class AuthenticationToken { token: string; expiry: Date; challengeResponse: string; /** * Creates an instance of AuthenticationToken. * * @constructor * @param {AxiosResponse} res Response from POST request */ constructor(res: AxiosResponse); /** * * @returns Token as string */ getToken(): string; /** * * @returns Token as buffer, for UDP use */ getTokenDecoded(): Buffer; /** * * @returns Challenge response generated by the XLED instance */ getChallengeResponse(): string; } export interface rgbColour { /** Red 0..255 */ red: number; /** Green 0..255 */ green: number; /** Blue 0..255 */ blue: number; } export interface hsvColour { /** Hue 0..359 */ hue: number; /** Saturation 0..255 */ saturation: number; /** Value (brightness) 0..255 */ value: number; } export declare enum deviceMode { demo = "demo", color = "color", off = "off", effect = "effect", movie = "movie", playlist = "playlist", rt = "rt" } export interface timer { /** Current time according to the device, seconds after midnight */ time_now: number; /** Time to switch lights on, seconds after midnight. -1 if not set. */ time_on: number; /** Time to switch lights off, seconds after midnight. -1 if not set. */ time_off: number; } /** * A frame of LEDs, used when you wish to set colour pixel by pixel * * @export * @class Frame * @typedef {Frame} */ export declare class Frame { leds: Led[]; /** * Creates an instance of Frame. * * @constructor * @param {Led[]} leds Array of Led, of same length as nleds */ constructor(leds: Led[]); /** * Output the frame as a Uint8Array of bytes * * @returns {Uint8Array} */ toOctet(): Uint8Array; /** * Get the number of LEDs in this frame * * @returns {number} */ getNLeds(): number; } /** * Easy way to create an entire frame of one colour * * @export * @class OneColourFrame * @typedef {OneColourFrame} * @extends {Frame} */ export declare class OneColourFrame extends Frame { /** * Creates an instance of OneColourFrame. * * @constructor * @param {rgbColour} rgb * @param {number} nleds Number of LEDs to include in this frame (probably the number of LEDs in the string) */ constructor(rgb: rgbColour, nleds: number); } /** * A RGB led * * @export * @class Led * @typedef {Led} */ export declare class Led { red: number; green: number; blue: number; /** * Creates an instance of Led. * * @constructor * @param {number} red * @param {number} green * @param {number} blue */ constructor(red: number, green: number, blue: number); /** * Returns the LED in octet form * * @returns {Uint8Array} */ toOctet(): Uint8Array; }