import type Plug from '.' ; import Schedule , { createScheduleRule } from '../shared/schedule' ; import type { ScheduleRule , ScheduleRuleInputTime } from '../shared/schedule' ; import type { SendOptions } from '../client' ; import { isDefinedAndNotNull } from '../utils' ; export type PlugScheduleRule = Omit < ScheduleRule , 'emin' > & { sact ? : number ; s_dimmer ? : Record < string , unknown > ; emin : 0 ; } ; export interface PlugScheduleRuleInput { powerState : boolean ; /**
     * dimmer data (dimmable plugs only)
     */ dimmer ? : Record < string , unknown > ; /**
     * Date or number of minutes
     */ start : ScheduleRuleInputTime ; /**
     * [0,6] = weekend, [1,2,3,4,5] = weekdays
     */ daysOfWeek ? : number [ ] ; name ? : string ; defaultValue enable : boolean ; } export default class PlugSchedule extends Schedule { constructor ( readonly device , readonly apiModuleName , readonly childId ? ) { super ( device , apiModuleName , childId ) ; } returns throws ResponseError async addRule ( rule , sendOptions ? ) { const { powerState , dimmer , start , daysOfWeek , name = '' , enable = true , } = rule ; const scheduleRule = { sact : powerState ? 1 : 0 , name , enable : enable ? 1 : 0 , emin : 0 , etime_opt : - 1 , ... createScheduleRule ( { start , daysOfWeek } ) , } ; if ( isDefinedAndNotNull ( dimmer ) ) { scheduleRule . sact = 3 ; scheduleRule . s_dimmer = dimmer ; } return super . addRule ( scheduleRule , sendOptions ) ; } returns throws ResponseError async editRule ( rule , sendOptions ? ) { const { id , powerState , dimmer , start , daysOfWeek , name = '' , enable = true , } = rule ; const scheduleRule = { id , sact : powerState ? 1 : 0 , name , enable : enable ? 1 : 0 , emin : 0 , etime_opt : - 1 , ... createScheduleRule ( { start , daysOfWeek } ) , } ; if ( isDefinedAndNotNull ( dimmer ) ) { scheduleRule . sact = 3 ; scheduleRule . s_dimmer = dimmer ; } return super . editRule ( scheduleRule , sendOptions ) ; } }