Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Yeelight

The client to connect and control the light

Hierarchy

  • EventEmitter
    • Yeelight

Index

Constructors

constructor

  • Parameters

    • options: IConfig

      : The client config initial the client

    • Optional logger: ILogger

    Returns Yeelight

Properties

Private Readonly EVENT_NAME

EVENT_NAME: "command_result" = "command_result"

autoReconnect

autoReconnect: boolean = false

autoReconnectTime

autoReconnectTime: number = 1000

Private client

client: Socket

Private commandId

commandId: number = 1

connectTimeout

connectTimeout: number = 1000

connected

connected: boolean

disablePing

disablePing: boolean = false

Private isClosing

isClosing: boolean = false

Private isConnecting

isConnecting: boolean = false

Private isReconnecting

isReconnecting: boolean = false

Private pingTimeout

pingTimeout: Timer = null

Private reconnectTimeout

reconnectTimeout: Timer = null

Private resultCommands

resultCommands: ICommandResult[]

Private sentCommands

sentCommands: {} = {}

Type declaration

Static Readonly captureRejectionSymbol

captureRejectionSymbol: typeof captureRejectionSymbol

Static captureRejections

captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

Private _recoverNetworkError

  • _recoverNetworkError(): void

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

adjust

  • This method is used to adjust the brightness by specified percentage within specified duration.

    Parameters

    • type: ADJUST_BRIGHT | ADJUST_CT | ADJUST_COLOR
    • percentage: number = 0

      the percentage to be adjusted. The range is: -100 ~ 100

    • duration: number = 500

      the milisecond of animation

    Returns Promise<IEventResult>

    return a promise of IEventResult

Private closeConnection

  • closeConnection(): void

connect

Private connectToIp

  • connectToIp(host: string, port: number): Promise<Yeelight>

cronAdd

  • cronAdd(type: number, time: number): Promise<IEventResult>
  • This method is used to start a timer job on the smart LED. Only accepted if the smart LED is currently in "on" state

    Parameters

    • type: number

      currently can only be 0. (means power off)

    • time: number

      the length of the timer (in minutes). Request

    Returns Promise<IEventResult>

    return a promise of IEventResult

cronDelete

  • This method is used to retrieve the setting of the current cron job of the specified type.

    Parameters

    • type: number

      currently can only be 0. (means power off)

    Returns Promise<IEventResult>

    return a promise of IEventResult

cronGet

  • This method is used to retrieve the setting of the current cron job of the specified type.

    Parameters

    • type: number

      currently can only be 0. (means power off)

    Returns Promise<IEventResult>

    return a promise of IEventResult

disconnect

  • disconnect(): Promise<void>
  • Drop connection/listerners and clean up resources.

    Returns Promise<void>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getProperty

  • This method is used to retrieve current property of smart LED.

    Parameters

    • params: DevicePropery[]

      The parameter is a list of property names and the response contains a list of corresponding property values. the requested property name is not recognized by smart LED, then a empty string value ("") will be returned. Request Example: {"id":1,"method":"get_prop","params":["power", "not_exist", "bright"]} Example: {"id":1, "result":["on", "", "100"]}

    Returns Promise<IEventResult>

    return a promise of IEventResult

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

on

  • on(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

onData

  • onData(data: Buffer): void

onMessage

once

  • once(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

ping

  • ping(): Promise<null>
  • This method is used to just check if the connection is alive

    Returns Promise<null>

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): Yeelight
  • Parameters

    • Optional event: string | symbol

    Returns Yeelight

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): Yeelight
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Yeelight

sendCommand

  • Use this function to send any command to the light, please refer to specification to know the structure of command data

    Parameters

    • command: Command

      The command to send to light via socket write

    Returns Promise<IEventResult>

    return a promise of IEventResult

setAdjust

  • Parameters

    • adjustType: AdjustType

      the direction of the adjustment. The valid value can be: increase: increase the specified property decrease: decrease the specified property circle: increase the specified property, after it reaches the max value back to minimum value

    • prop: "bright" | "color" | "ct"

      the property to adjust. The valid value can be: “bright": adjust brightness. “ct": adjust color temperature. “color": adjust color. (When “prop" is “color", the “action" can only be “circle", otherwise, it will be deemed as invalid request.)

    Returns Promise<IEventResult>

    return a promise of IEventResult

setBright

  • setBright(brightness: number, effect?: "smooth" | "sudden", duration?: number): Promise<IEventResult>
  • This method is used to change the color of a smart LED. Only accepted if the smart LED is currently in "on" state.

    Parameters

    • brightness: number

      is the target brightness. The type is integer and ranges from 1 to 100. The brightness is a percentage instead of a absolute value. 100 means maximum brightness while 1 means the minimum brightness.

    • effect: "smooth" | "sudden" = "sudden"

      support two values: "sudden" and "smooth". If effect is "sudden", then the color temperature will be changed directly to target value, under this case, the third parameter "duration" is ignored. If effect is "smooth", then the color temperature will be changed to target value in a gradual fashion, under this case, the total time of gradual change is specified in third parameter "duration".

    • duration: number = 500

      specifies the total time of the gradual changing. The unit is milliseconds. The minimum support duration is 30 milliseconds.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setCtAbx

  • setCtAbx(ct: number, effect?: "smooth" | "sudden", duration?: number): Promise<IEventResult>
  • This method is used to change the color temperature of a smart LED.

    Parameters

    • ct: number

      the target color temperature. The type is integer and range is 1700 ~ 6500 (k).

    • effect: "smooth" | "sudden" = "sudden"

      support two values: "sudden" and "smooth". If effect is "sudden", then the color temperature will be changed directly to target value, under this case, the third parameter "duration" is ignored. If effect is "smooth", then the color temperature will be changed to target value in a gradual fashion, under this case, the total time of gradual change is specified in third parameter "duration".

    • duration: number = 500

      specifies the total time of the gradual changing. The unit is milliseconds. The minimum support duration is 30 milliseconds.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setDefault

  • This method is used to save current state of smart LED in persistent memory. So if user powers off and then powers on the smart LED again (hard power reset), the smart LED will show last saved state. For example, if user likes the current color (red) and brightness (50%) and want to make this state as a default initial state (every time the smart LED is powered), then he can use set_default to do a snapshot.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setHSV

  • setHSV(hue: number, sat: number, effect?: "smooth" | "sudden", duration?: number): Promise<IEventResult>
  • This method is used to change the color of a smart LED. Only accepted if the smart LED is currently in "on" state.

    Parameters

    • hue: number

      the target hue, whose type is integer. It should be expressed in decimal integer ranges from 0 to 359.

    • sat: number

      the target saturation, whose type is integer. It should be expressed in decimal integer ranges from 0 to 100.

    • effect: "smooth" | "sudden" = "sudden"

      support two values: "sudden" and "smooth". If effect is "sudden", then the color temperature will be changed directly to target value, under this case, the third parameter "duration" is ignored. If effect is "smooth", then the color temperature will be changed to target value in a gradual fashion, under this case, the total time of gradual change is specified in third parameter "duration".

    • duration: number = 500

      specifies the total time of the gradual changing. The unit is milliseconds. The minimum support duration is 30 milliseconds.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setMaxListeners

  • Parameters

    • n: number

    Returns Yeelight

setMusic

  • setMusic(action: 0 | 1, host: string, port: number): Promise<IEventResult>
  • This method is used to start or stop music mode on a device. Under music mode, no property will be reported and no message quota is checked.

    Parameters

    • action: 0 | 1

      the action of set_music command. The valid value can be: 0: turn off music mode. 1: turn on music mode.

    • host: string

      the IP address of the music server.

    • port: number

      the TCP port music application is listening on. When control device wants to start music mode, it needs start a TCP server firstly and then call “set_music” command to let the device know the IP and Port of the TCP listen socket. After received the command, LED device will try to connect the specified peer address. If the TCP connection can be established successfully, then control device could send all supported commands through this channel without limit to simulate any music effect. The control device can stop music mode by explicitly send a stop command or just by closing the socket.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setName

  • This method is used to name the device. The name will be stored on the device and reported in discovering response. User can also read the name through “get_prop” method

    Parameters

    • name: string

      the name of the device. When using Yeelight official App, the device name is stored on cloud. This method instead store the name on persistent memory of the device, so the two names could be different.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setPower

  • setPower(turnOn?: boolean, effect?: "smooth" | "sudden", duration?: number): Promise<IEventResult>
  • Parameters

    • turnOn: boolean = true
    • effect: "smooth" | "sudden" = "sudden"
    • duration: number = 500

    Returns Promise<IEventResult>

setRGB

  • setRGB(color: Color, effect: "smooth" | "sudden", duration?: number): Promise<IEventResult>
  • This method is used to change the color of a smart LED. Only accepted if the smart LED is currently in "on" state.

    Parameters

    • color: Color

      the target color, whose type is integer. It should be expressed in decimal integer ranges from 0 to 16777215 (hex: 0xFFFFFF). can be initial by new Color(233,255,244)

    • effect: "smooth" | "sudden"

      support two values: "sudden" and "smooth". If effect is "sudden", then the color temperature will be changed directly to target value, under this case, the third parameter "duration" is ignored. If effect is "smooth", then the color temperature will be changed to target value in a gradual fashion, under this case, the total time of gradual change is specified in third parameter "duration".

    • duration: number = 500

      specifies the total time of the gradual changing. The unit is milliseconds. The minimum support duration is 30 milliseconds.

    Returns Promise<IEventResult>

    return a promise of IEventResult

setScene

  • This method is used to set the smart LED directly to specified state. If the smart LED is off, then it will turn on the smart LED firstly and then apply the specified command

    Type parameters

    Parameters

    • scene: T

      type of scene to update

    Returns Promise<IEventResult>

    return a promise of IEventResult

startColorFlow

  • This method is used to start a color flow. Color flow is a series of smart LED visible state changing. It can be brightness changing, color changing or color temperature changing. This is the most powerful command. All our recommended scenes, e.g. Sunrise/Sunset effect is implemented using this method. With the flow expression, user can actually “program” the light effect.

    Parameters

    • states: FlowState[]
    • action: StartFlowAction = ...
    • repeat: number = 0

      is the total number of visible state changing before color flow stopped. 0 means infinite loop on the state changing. @default infinity

    Returns Promise<IEventResult>

    return a promise of IEventResult

stopColorFlow

toggle

  • This method is used to toggle the smart LED. This method is used to switch on or off the smart LED (software managed on/off)

    Returns Promise<IEventResult>

    Return the promise indicate the command success or reject

Private triggerPing

  • triggerPing(): void

Private wasConnected

  • wasConnected(): void

Private wasDisconnected

  • wasDisconnected(): void

Static getEventListener

  • getEventListener(emitter: DOMEventTarget | EventEmitter, name: string | symbol): Function[]
  • Returns a list listener for a specific emitter event name.

    Parameters

    • emitter: DOMEventTarget | EventEmitter
    • name: string | symbol

    Returns Function[]

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static on

  • on(emitter: EventEmitter, event: string, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns AsyncIterableIterator<any>

Static once

  • once(emitter: NodeEventTarget, event: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string, options?: StaticEventEmitterOptions): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

Generated using TypeDoc