UNPKG

homebridge-homeconnect

Version:

A Homebridge plugin that connects Home Connect appliances to Apple HomeKit

50 lines 2.63 kB
// Homebridge plugin for Home Connect home appliances // Copyright © 2023-2026 Alexander Thoukydides import { assertIsDefined, formatSeconds } from './utils.js'; // Default maximum alarm clock duration (if unable to read from Home Connect API) const MAX_ALARM_DURATION = 38340; // (seconds) // Add an alarm clock to an accessory export function HasAlarmClock(Base) { return class HasAlarmClock extends Base { // Mixin constructor constructor(...args) { super(...args); // Continue initialisation asynchronously this.asyncInitialise('Alarm Clock', this.initHasAlarmClock()); } // Asynchronous initialisation async initHasAlarmClock() { if (!this.powerService) { this.log.info('Feature "Alarm Clock" implicitly disabled with "Power" feature'); return; } // Check whether the appliance supports an alarm clock const allSettings = await this.getCached('settings', () => this.device.getSettings()); if (!allSettings.some(s => s.key === 'BSH.Common.Setting.AlarmClock')) { this.log.info('Does not support an alarm clock'); return; } // Check the maximum supported alarm clock duration const setting = await this.getCached('alarmclock', () => this.device.getSetting('BSH.Common.Setting.AlarmClock')); // Add a set duration characteristic for the alarm clock this.powerService.addOptionalCharacteristic(this.Characteristic.SetDuration); const setDurationCharacteristic = this.powerService.getCharacteristic(this.Characteristic.SetDuration); setDurationCharacteristic.setProps({ maxValue: setting?.constraints?.max ?? MAX_ALARM_DURATION }); // Update from HomeKit to Home Connect this.onSetNumber(setDurationCharacteristic, async (value) => { this.log.info(`SET Alarm clock ${value} seconds`); await this.device.setSetting('BSH.Common.Setting.AlarmClock', value); }); // Update from Home Connect to HomeKit this.device.on('BSH.Common.Setting.AlarmClock', seconds => { assertIsDefined(this.powerService); if (seconds) this.log.info(`Alarm clock ${formatSeconds(seconds)} remaining`); else this.log.info('Alarm clock inactive'); setDurationCharacteristic.updateValue(seconds); }); } }; } //# sourceMappingURL=has-alarmclock.js.map