xled-js
Version:
Library to control Twinkly LED lights
200 lines (199 loc) • 5.35 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { AxiosInstance, AxiosResponse } from "axios";
import * as udp from "node:dgram";
import { Frame } from "./frame.js";
import { Movie } from "./movie.js";
import { rgbColor, hsvColor, deviceMode, timer } from "./interfaces.js";
/**
* 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 color in HSV
*/
getHSVColor(): Promise<hsvColor>;
/**
* Gets the current color in RGB
*/
getRGBColor(): Promise<rgbColor>;
/**
* Sets the color in RGB when in color mode
*
* @param {rgbColor} color A RGB color
*/
setRGBColor(color: rgbColor): Promise<void>;
setRGBColorRealTime(color: rgbColor): Promise<void>;
/**
* Sets the color in HSV when in color mode
*
* @param {hsvColor} color A HSV color
*/
setHSVColor(color: hsvColor): 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, data: any, contentType?: string): 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>;
sendMovieConfig(movie: Movie): Promise<any>;
sendMovieToDevice(movie: Movie): Promise<any>;
sendRealTimeFrame(frame: Frame): Promise<any>;
sendRealTimeFrameUDP(frame: Frame): Promise<void>;
getListOfMovies(): Promise<Movie[]>;
addMovie(movie: Movie): Promise<any>;
getLayout(): Promise<any>;
getNLeds(): Promise<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;
}
/**
* Easy way to create an entire frame of one color
*
* @export
* @class OneColorFrame
* @typedef {OneColorFrame}
* @extends {Frame}
*/
export declare class OneColorFrame extends Frame {
/**
* Creates an instance of OneColorFrame.
*
* @constructor
* @param {rgbColor} rgb
* @param {number} nleds Number of LEDs to include in this frame (probably the number of LEDs in the string)
*/
constructor(rgb: rgbColor, nleds: number);
}