UNPKG

@homebridge-plugins/homebridge-smarthq

Version:

The SmartHQ plugin allows you to interact with SmartHQ Devices in HomeKit and with Siri.

38 lines 2.02 kB
import { OpalDeviceBase } from "../OpalDeviceBase.js"; export class OpalSchedulingManager extends OpalDeviceBase { platform; accessory; device; opalIceMaker; advancedOptionQueryStrs = ['device=opal&label=Opal_Ice_Production_Scheduler&indicator=oplIceProductionSchedule&type=scheduler']; // Below 60,000 and there are two edges cases where either the machine does not start within the given minute // Or the machine starts, the user turns it off and then it starts again before the minute expires schedulerInterval = 60 * 1000; constructor(opalIceMaker, platform, accessory, device) { super(platform, accessory, device); this.platform = platform; this.accessory = accessory; this.device = device; this.opalIceMaker = opalIceMaker; } initializeIfIceMakerOnSchedule() { const opalIceProductionSchedule = this.platform.config.deviceOptions?.opal?.oplIceProductionSchedule; const today = new Date().toLocaleDateString('en-US', { weekday: 'long' }); if (opalIceProductionSchedule?.[today] && opalIceProductionSchedule?.[today].enabled) { const opalCurrentPowerState = this.opalIceMaker.powerManager.getOpalPowerState(); if (opalCurrentPowerState === false) { const scheduledTimeStr = opalIceProductionSchedule[today].time; const [hours, minutes] = scheduledTimeStr.split(':'); const scheduledTime = new Date(); scheduledTime.setHours(hours, minutes, 0, 0); const now = new Date(); const triggerWindowEnd = new Date(scheduledTime.getTime() + this.schedulerInterval); if (now >= scheduledTime && now <= triggerWindowEnd) { this.platform.debugSuccessLog('Turning on Ice Machine on Schedule'); this.opalIceMaker.powerManager.setOpalPowerState(true); } } } } } //# sourceMappingURL=OpalSchedulingManager.js.map