import type { SendOptions } from '../client' ; import type Plug from '.' ; export interface DimmerTransitionInput { /**
     * 0-100
     */ brightness ? : number ; /**
     * "gentle_on_off", etc.
     */ mode ? : string ; /**
     * duration in seconds
     */ duration ? : number ; } export interface DimmerActionInput { mode ? : string ; index ? : number ; } /**
 * Dimmer
 *
 * TP-Link models: HS220.
 */ export default class Dimmer { internal lastState = { brightness : - 1 } ; internal #brightness = 0 ; constructor ( readonly device , readonly apiModuleName ) { } /**
     * Cached value of `sysinfo.brightness`.
     */ get brightness ( ) : number { return this . #brightness ; } internal setBrightnessValue ( brightness ) { this . #brightness = brightness ; this . device . log . debug ( '[%s] plug.dimmer brightness set' , this . device . alias ) ; this . emitEvents ( ) ; } param brightness returns throws ResponseError async setBrightness ( brightness , sendOptions ? ) { const results = this . device . sendCommand ( { [ this . apiModuleName ] : { set_brightness : { brightness } , } , } , undefined , sendOptions ) ; this . setBrightnessValue ( brightness ) ; return results ; } returns throws ResponseError async getDefaultBehavior ( sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { get_default_behavior : { } , } , } , undefined , sendOptions ) ; } returns throws ResponseError async getDimmerParameters ( sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { get_dimmer_parameters : { } , } , } , undefined , sendOptions ) ; } returns throws ResponseError async setDimmerTransition ( dimmerTransition , sendOptions ? ) { const { brightness , mode , duration } = dimmerTransition ; const results = this . device . sendCommand ( { [ this . apiModuleName ] : { set_dimmer_transition : { brightness , mode , duration , } , } , } , undefined , sendOptions ) ; if ( brightness !== undefined ) this . setBrightnessValue ( brightness ) ; return results ; } returns throws ResponseError async setDoubleClickAction ( { mode , index } , sendOptions ? ) { return this . setAction ( { actionName : 'set_double_click_action' , mode , index , } , sendOptions ) ; } private async setAction ( { actionName , mode , index , } , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { [ actionName ] : { mode , index } , } , } , undefined , sendOptions ) ; } param fadeTime param sendOptions returns throws ResponseError async setFadeOffTime ( fadeTime , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { set_fade_off_time : { fadeTime } , } , } , undefined , sendOptions ) ; } param fadeTime param sendOptions returns throws ResponseError async setFadeOnTime ( fadeTime , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { set_fade_on_time : { fadeTime } , } , } , undefined , sendOptions ) ; } param fadeTime param sendOptions returns throws ResponseError async setGentleOffTime ( fadeTime , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { set_gentle_off_time : { fadeTime } , } , } , undefined , sendOptions ) ; } param fadeTime param sendOptions returns throws ResponseError async setGentleOnTime ( fadeTime , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { set_gentle_on_time : { fadeTime } , } , } , undefined , sendOptions ) ; } param options param options . mode param options . index param sendOptions returns throws ResponseError async setLongPressAction ( { mode , index } , sendOptions ? ) { return this . setAction ( { actionName : 'set_long_press_action' , mode , index } , sendOptions ) ; } param { Boolean } state param { SendOptions } sendOptions returns throws ResponseError async setSwitchState ( state , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { set_switch_state : { state : state ? 1 : 0 } , } , } , undefined , sendOptions ) ; } internal public emitEvents ( ) { const brightness = this . #brightness ; this . device . log . debug ( '[%s] plug.dimmer.emitEvents() brightness: %s lastState: %j' , this . device . alias , brightness , this . lastState ) ; if ( brightness !== undefined ) { if ( this . lastState . brightness !== brightness ) { this . lastState . brightness = brightness ; this . device . emit ( 'brightness-change' , brightness ) ; } this . device . emit ( 'brightness-update' , brightness ) ; } } }