homebridge-homeconnect
Version:
A Homebridge plugin that connects Home Connect appliances to Apple HomeKit
44 lines • 2.34 kB
JavaScript
// Homebridge plugin for Home Connect home appliances
// Copyright © 2021-2026 Alexander Thoukydides
import { assertIsDefined } from './utils.js';
// Add a child lock to an accessory
export function HasChildLock(Base) {
return class HasChildLock extends Base {
// Mixin constructor
constructor(...args) {
super(...args);
// Continue initialisation asynchronously
this.asyncInitialise('Child Lock', this.initHasChildLock());
}
// Asynchronous initialisation
async initHasChildLock() {
if (!this.powerService) {
this.log.info('Feature "Child Lock" implicitly disabled with "Power" feature');
return;
}
// Check whether the appliance supports a child lock
const allSettings = await this.getCached('settings', () => this.device.getSettings());
if (!allSettings.some(s => s.key === 'BSH.Common.Setting.ChildLock')) {
this.log.info('Does not support a child lock');
return;
}
// Add the lock physical controls characteristic
const { CONTROL_LOCK_DISABLED, CONTROL_LOCK_ENABLED } = this.Characteristic.LockPhysicalControls;
this.powerService.addOptionalCharacteristic(this.Characteristic.LockPhysicalControls);
const lockPhysicalControlsCharacteristic = this.powerService.getCharacteristic(this.Characteristic.LockPhysicalControls);
// Update from HomeKit to Home Connect
this.onSetNumber(lockPhysicalControlsCharacteristic, async (value) => {
const isEnabled = value === CONTROL_LOCK_ENABLED;
this.log.info(`SET Child lock ${isEnabled ? 'enabled' : 'disabled'}`);
await this.device.setSetting('BSH.Common.Setting.ChildLock', isEnabled);
});
// Update from Home Connect to HomeKit
this.device.on('BSH.Common.Setting.ChildLock', childLock => {
assertIsDefined(this.powerService);
this.log.info(`Child lock ${childLock ? 'enabled' : 'disabled'}`);
lockPhysicalControlsCharacteristic.updateValue(childLock ? CONTROL_LOCK_ENABLED : CONTROL_LOCK_DISABLED);
});
}
};
}
//# sourceMappingURL=has-childlock.js.map