From c25b2c195ad1a6cf500cbeb275ea3381f95ff46f Mon Sep 17 00:00:00 2001 From: Aiklyukov Date: Sun, 26 Sep 2021 09:25:34 +0300 Subject: [PATCH] add ts types --- index.d.ts | 5 + types/lib/AsyncEffectInterface.d.ts | 24 ++++ types/lib/Control.d.ts | 178 ++++++++++++++++++++++++++++ types/lib/CustomMode.d.ts | 21 ++++ types/lib/Discovery.d.ts | 16 +++ types/lib/EffectInterface.d.ts | 9 ++ 6 files changed, 253 insertions(+) create mode 100644 index.d.ts create mode 100644 types/lib/AsyncEffectInterface.d.ts create mode 100644 types/lib/Control.d.ts create mode 100644 types/lib/CustomMode.d.ts create mode 100644 types/lib/Discovery.d.ts create mode 100644 types/lib/EffectInterface.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9df42eb --- /dev/null +++ b/index.d.ts @@ -0,0 +1,5 @@ +import Control = require("./types/lib/Control"); +import Discovery = require("./types/lib/Discovery"); +import CustomMode = require("./types/lib/CustomMode"); +import { EffectTimingHelper } from "./types/lib/AsyncEffectInterface"; +export { Control, Discovery, CustomMode, EffectTimingHelper }; diff --git a/types/lib/AsyncEffectInterface.d.ts b/types/lib/AsyncEffectInterface.d.ts new file mode 100644 index 0000000..758a344 --- /dev/null +++ b/types/lib/AsyncEffectInterface.d.ts @@ -0,0 +1,24 @@ +export class AsyncEffectInterface { + constructor(address: any, port: any, parent: any, color_ack: any, apply_masks: any); + userData: {}; + get connected(): boolean; + connect(): any; + start(interval_function: any): any; + stop(): void; + end(): void; + delay(milliseconds: any): any; + setColorAndWarmWhite(red: any, green: any, blue: any, warm_white: any): any; + setColorAndWhites(red: any, green: any, blue: any, warm_white: any, cold_white: any): any; + setColor(red: any, green: any, blue: any): any; + setWarmWhite(warm_white: any): any; + setWhites(warm_white: any, cold_white: any): any; +} +/** + * A class that helps with timing an effect where each of the commands are asynchronous + */ +export class EffectTimingHelper { + constructor(parent: any); + isStarted(): boolean; + start(): void; + delayRemaining(milliseconds: any): Promise; +} diff --git a/types/lib/Control.d.ts b/types/lib/Control.d.ts new file mode 100644 index 0000000..fa2d295 --- /dev/null +++ b/types/lib/Control.d.ts @@ -0,0 +1,178 @@ +export = Control; +declare class Control { + static get patternNames(): string[]; + static ackMask(mask: any): { + power: boolean; + color: boolean; + pattern: boolean; + custom_pattern: boolean; + }; + /** + * Create a new Control instance. This does not connect to the controller, yet. + * @param {String} address IP or hostname of the controller + * @param {Object} options + * @param {boolean} options.wait_for_reply [Deprecated] Wait for the controllers to send data as acknowledgement. (Default: true) + * @param {boolean} options.log_all_received Print all received bytes into stdout for debug purposes (Default: false) + * @param {boolean} options.apply_masks Set the mask bit in setColor and setWarmWhite (Default: false) + * @param {boolean} options.cold_white_support Send a different version of the color change packets, which also set the cold white values (Default: false) + * @param {Number} options.connect_timeout Duration in milliseconds after which the connection attempt will be cancelled if the connection can not be established (Default: null [No timeout]) + * @param {Number} options.command_timeout Duration in milliseconds after which an acknowledged command will be regarded as failed. Set to null to disable. (Default: 1000) + * @param {Object} options.ack + * @param {boolean} options.ack.power Wait for controller to send data to achnowledge power change commands (Default: true) + * @param {boolean} options.ack.color Wait for controller to send data to achnowledge color change commands (Default: true) + * @param {boolean} options.ack.pattern Wait for controller to send data to achnowledge built-in pattern change commands (Default: true) + * @param {boolean} options.ack.custom_pattern Wait for controller to send data to acknowledge custom pattern change commands (Default: true) + */ + constructor(address: string, options?: Partial<{ + wait_for_reply: boolean; + log_all_received: boolean; + apply_masks: boolean; + cold_white_support: boolean; + connect_timeout: number; + command_timeout: number; + ack: Partial<{ + power: boolean; + color: boolean; + pattern: boolean; + custom_pattern: boolean; + }>; + }>); + /** + * Sets the power state either to on or off + * @param {Boolean} on + * @param {function} callback called with (err, success) + * @returns {Promise} + */ + setPower(on: boolean, callback?: Function): Promise; + /** + * Convenience method to call setPower(true) + * @param {function} callback + * @returns {Promise} + */ + turnOn(callback?: Function): Promise; + /** + * Convenience method to call setPower(false) + * @param {function} callback + * @returns {Promise} + */ + turnOff(callback?: Function): Promise; + /** + * Sets the color and warm white values of the controller. + * Also saves the values for further calls to setColor, setWarmWhite, etc + * @param {Number} red + * @param {Number} green + * @param {Number} blue + * @param {Number} ww + * @param {function} callback called with (err, success) + * @returns {Promise} + */ + setColorAndWarmWhite(red: number, green: number, blue: number, ww: number, callback?: Function): Promise; + /** + * Sets the color and white values of the controller. + * Also saves the values for further calls to setColor, setWarmWhite, etc + * @param {Number} red + * @param {Number} green + * @param {Number} blue + * @param {Number} ww warm white + * @param {Number} cw cold white + * @param {function} callback called with (err, success) + * @returns {Promise} + */ + setColorAndWhites(red: number, green: number, blue: number, ww: number, cw: number, callback?: Function): Promise; + /** + * Sets the color values of the controller. + * Depending on apply_masks, only the color values, or color values as well as previous warm white values will be sent + * @param {Number} red + * @param {Number} green + * @param {Number} blue + * @param {function} callback called with (err, success) + * @returns {Promise} + */ + setColor(red: number, green: number, blue: number, callback?: Function): Promise; + /** + * Sets the warm white values of the controller. + * Depending on apply_masks, only the warm white values, or warm white values as well as previous color values will be sent + * @param {Number} ww + * @param {function} callback called with (err, success) + * @returns {Promise} + */ + setWarmWhite(ww: number, callback?: Function): Promise; + /** + * Sets the white values of the controller. + * Depending on apply_masks, only the cold white values, or cold white values as well as previous color values will be sent + * @param {Number} ww warm white + * @param {Number} cw cold white + * @param {function} callback called with (err, success) + * @returns {Promise} + */ + setWhites(ww: number, cw: number, callback?: Function): Promise; + /** + * Convenience method to scale down the colors with a brightness value between 0 and 100 + * If you send red, green and blue to 0, this sets the color to white with the specified brightness (but not warm white!) + * @param {Number} red + * @param {Number} green + * @param {Number} blue + * @param {Number} brightness + * @param {function} callback + * @returns {Promise} + */ + setColorWithBrightness(red: number, green: number, blue: number, brightness: number, callback?: Function): Promise; + /** + * Sets the controller to display one of the predefined patterns + * @param {String} pattern Name of the pattern + * @param {Number} speed between 0 and 100 + * @param {function} callback + * @returns {Promise} + */ + setPattern(pattern: string, speed: number, callback?: Function): Promise; + /** + * Sets the controller to display one of the predefined patterns + * @param {Number} code Code of the pattern, between 1 and 300 + * @param {Number} speed between 0 and 100 + * @param {function} callback + * @returns {Promise} + */ + setIAPattern(code: number, speed: number, callback?: Function): Promise; + /** + * Sets the controller to display a custom pattern + * @param {CustomMode} pattern + * @param {Number} speed + * @param {function} callback + * @returns {Promise} + */ + setCustomPattern(pattern: CustomMode, speed: number, callback?: Function): Promise; + /** + * (Deprecated) Creates a new EffectInterface, which establishes a persistent connection to the controller + * @param {function} callback + * @returns {Promise} + */ + startEffectMode(callback?: Function): Promise; + getAsyncEffectMode(): AsyncEffectInterface; + /** + * Queries the controller for it's current state + * This method stores the color and ww values for future calls to setColor, setWarmWhite, etc. + * It will also set apply_masks to true for controllers which require it. + * @param {function} callback + * @returns {Promise} + */ + queryState(callback?: Function): Promise; +} +declare namespace Control { + export { QueryResponse }; +} +import CustomMode = require("./CustomMode"); +import EffectInterface = require("./EffectInterface"); +import { AsyncEffectInterface } from "./AsyncEffectInterface"; +type QueryResponse = { + type: number; + on: boolean; + mode: string; + speed: number; + color: { + red: number; + green: number; + blue: number; + }; + warm_white: number; + cold_white: number; +}; diff --git a/types/lib/CustomMode.d.ts b/types/lib/CustomMode.d.ts new file mode 100644 index 0000000..6742394 --- /dev/null +++ b/types/lib/CustomMode.d.ts @@ -0,0 +1,21 @@ +export = CustomMode; +declare class CustomMode { + static get transitionTypes(): string[]; + get transitionType(): string; + get colors(): any[]; + /** + * Add a new color to the effect + * @param {Number} red + * @param {Number} green + * @param {Number} blue + * @returns {CustomMode} This object for chainability + */ + addColor(red: number, green: number, blue: number): CustomMode; + /** + * Add a list of colors all at once + * @param {Array} list Each element should contain and array of the form [ red, green, blue ] + * @returns {CustomMode} This object for chainability + */ + addColorList(list: any[]): CustomMode; + setTransitionType(type: any): CustomMode; +} diff --git a/types/lib/Discovery.d.ts b/types/lib/Discovery.d.ts new file mode 100644 index 0000000..82a2e99 --- /dev/null +++ b/types/lib/Discovery.d.ts @@ -0,0 +1,16 @@ +export = Discovery; +declare class Discovery { + /** + * Convenience method which shortens the discovery operation to a single line + */ + static scan(timeout: any): any; + get clients(): any[]; + get scanned(): boolean; + /** + * Send a scan packet into the network + * @param {Number} timeout number of milliseconds to wait before the clients are returned + * @param {function} callback Called with (err, clients) + * @returns A Promise resolving to the found clients + */ + scan(timeout?: number, callback?: Function): any; +} diff --git a/types/lib/EffectInterface.d.ts b/types/lib/EffectInterface.d.ts new file mode 100644 index 0000000..bc65ae5 --- /dev/null +++ b/types/lib/EffectInterface.d.ts @@ -0,0 +1,9 @@ +export = EffectInterface; +declare class EffectInterface { + constructor(address: any, port: any, options: any, connection_callback: any); + get connected(): boolean; + start(interval_function: any): void; + stop(): void; + delay(time: any): void; + setColor(red: any, green: any, blue: any): void; +}