UNPKG

homebridge-hatch-baby-rest

Version:
21 lines (20 loc) 908 B
import { hap } from "../shared/hap.js"; import { BaseAccessory } from "../shared/base-accessory.js"; import { RestIot } from "./rest-iot.js"; import { logInfo } from "../shared/util.js"; export class RestoreAccessory extends BaseAccessory { constructor(restore, accessory) { super(restore, accessory); const { Service, Characteristic } = hap, onOffService = this.getService(Service.Switch), stepName = restore instanceof RestIot ? 'routine' : 'bedtime step'; this.registerCharacteristic(onOffService.getCharacteristic(Characteristic.On), restore.onSomeContentPlaying, (on) => { logInfo(`Turning ${on ? `on first ${stepName} for` : 'off'} ${restore.name}`); if (on) { restore.turnOnRoutine(); } else { restore.turnOff(); } }); onOffService.setPrimaryService(true); } }