yeelight-awesome
Version:
The node.js client api to control yeelight device over WIFI
71 lines (70 loc) • 2.74 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from "events";
import { IDevice } from "./models/device";
import { IDiscoverConfig } from "./models/discover-config";
import { ILogger } from "./models/logger";
/**
* The class to discover yeelight device on wifi network using UDP package
* @constructor
* @param {string} title - Yeelight Discover
* @param {string} author - samuraitruong@hotmail.com
*/
export declare class Discover extends EventEmitter {
private logger?;
private devices;
private timer;
private options;
private client;
private clientBound;
private isDestroyed;
/**
* @constructor
* @param {IDiscoverConfig } options discover object include the port and multicast host.
* see {@link IDiscoverConfig} for more detail
* @param {ILogger} logger the application logger which implement of log, info, debug and error function
*/
constructor(options: IDiscoverConfig, logger?: ILogger);
/**
* Try to verify if the light on and listening on the know ip address
* @param ipAddress : know IP Address of the light.
*/
detectLightIP(ipAddress: string): Promise<IDevice>;
/**
* Perfrom IP port scan to find an IP with port 55443 open rather than using SSDP discovery method
* @requires {Promise<IDevice[]>} promise of list of device found
*/
scanByIp(): Promise<IDevice[]>;
/**
* The class to discover yeelight device on wifi network using UDP package
* You need to turn on "LAN Control" on phone app to get SSDP discover function work
* @returns {Promise<IDevice[]>} a promise that could resolve to 1 or many devices on the network
*/
start(): Promise<IDevice[]>;
/**
* Clean up resource and close all open connection,
* call this function after you finish your action to avoid memory leak
* @returns {Promise} return a promise, fullfil will call after internal socket connection dropped
*/
destroy(): Promise<void>;
/**
* Internal function to handle socket error
* @param error Error details
*/
private onError;
/**
* Generate the UDP message to discover device on local network.
*/
private getMessage;
/**
* The event run when recieved the message devices
* @param {Buffer} buffer the buffer revieved from the socket
* @param {AddressInfo} address the TCP info of the devices who send the message
*/
private onSocketMessage;
/**
* Add the new discovered device into the internal list
* @param {IDevice} device - the new device found from network
* @returns {0 |1 } return 0 if device already existing, 1 if new device added to the list
*/
private addDevice;
}