import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; import { calculateRamp } from "../utils" ; class extends Device export class Light extends Device { constructor ( hub , portId ) { super ( hub , portId , { } , Consts . DeviceType . LIGHT ) ; } method param { number } brightness returns { Promise } public setBrightness ( brightness , interrupt = true ) { if ( interrupt ) { this . cancelEventTimer ( ) ; } return new Promise < void > ( ( resolve ) => { this . writeDirect ( 0x00 , Buffer . from ( [ brightness ] ) ) ; return resolve ( ) ; } ) ; } method param { number } fromBrightness param { number } toBrightness param { number } time returns { Promise } public rampBrightness ( fromBrightness , toBrightness , time ) { this . cancelEventTimer ( ) ; return new Promise ( ( resolve ) => { calculateRamp ( this , fromBrightness , toBrightness , time ) . on ( "changePower" , ( power ) => { this . setBrightness ( power , false ) ; } ) . on ( "finished" , resolve ) ; } ) ; } }