import type { AnyDevice , SendOptions } from '../client' ; export type TimerRule = { name ? : string ; enable ? : number ; act ? : number ; delay ? : number ; } ; export type TimerRuleInput = { name ? : string ; enable : boolean ; powerState : boolean | 0 | 1 ; delay : number ; } ; export default class Timer { constructor ( readonly device , readonly apiModuleName , readonly childId = undefined ) { } param { string [ ] | string | number [ ] | number } childIds param { SendOptions } sendOptions throws ResponseError async getRules ( sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { get_rules : { } } , } , this . childId , sendOptions ) ; } param options param { number } options . delay param { boolean } options . powerState param { string } options . name param { boolean } options . enable param { boolean } options . deleteExisting returns throws ResponseError async addRule ( { delay , powerState , name = 'timer' , enable = true , deleteExisting = true , } , sendOptions ? ) { if ( deleteExisting ) await this . deleteAllRules ( sendOptions ) ; return this . device . sendCommand ( { [ this . apiModuleName ] : { add_rule : { enable : enable ? 1 : 0 , delay , act : powerState ? 1 : 0 , name , } , } , } , this . childId , sendOptions ) ; } param options param { string } options . id param { number } options . delay param { number } options . powerState param { string } options . name param { Boolean } options . enable returns throws ResponseError async editRule ( { id , delay , powerState , name = 'timer' , enable = true , } , sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { edit_rule : { id , enable : enable ? 1 : 0 , delay , act : powerState ? 1 : 0 , name , } , } , } , this . childId , sendOptions ) ; } param { SendOptions } sendOptions returns { Promise < Object , ResponseError > } async deleteAllRules ( sendOptions ? ) { return this . device . sendCommand ( { [ this . apiModuleName ] : { delete_all_rules : { } } , } , this . childId , sendOptions ) ; } }