homebridge-homeconnect
Version:
A Homebridge plugin that connects Home Connect appliances to Apple HomeKit
60 lines • 3.28 kB
JavaScript
// Homebridge plugin for Home Connect home appliances
// Copyright © 2019-2025 Alexander Thoukydides
import { formatList } from './utils.js';
// Add local and remote control state to an accessory
export function HasRemoteControl(Base) {
return class HasRemoteControl extends Base {
// Mixin constructor
constructor(...args) {
super(...args);
// Use ProgramMode characteristic to indicate local and remote control
this.powerService.addOptionalCharacteristic(this.Characteristic.ProgramMode);
this.powerService.getCharacteristic(this.Characteristic.ProgramMode);
// Update the status
const updateHK = this.makeSerialised(() => { this.updateRemoteControlHK(); });
this.device.on('BSH.Common.Status.RemoteControlActive', updateHK);
this.device.on('BSH.Common.Status.RemoteControlStartAllowed', updateHK);
this.device.on('BSH.Common.Status.LocalControlActive', updateHK);
}
// Deferred update of HomeKit state from Home Connect events
updateRemoteControlHK() {
// Read the most recent state and generate a description
const detailBits = [];
const read = (key, values, prefix) => {
const state = this.device.getItem(key);
let detail = values[`${state}`];
if (detail) {
if (prefix)
detail = `${prefix} ${detail}`;
detailBits.push(detail);
}
return state;
};
const remoteControl = read('BSH.Common.Status.RemoteControlActive', { true: 'activated', false: 'not activated' }, 'remote control');
const remoteStart = read('BSH.Common.Status.RemoteControlStartAllowed', { true: 'allowed', false: 'disallowed' }, 'remote start');
const localControl = read('BSH.Common.Status.LocalControlActive', { true: 'being operated locally' });
const detail = `(${formatList(detailBits)})`;
// Map the state to the most appropriate Program Mode characteristic
const { NO_PROGRAM_SCHEDULED, PROGRAM_SCHEDULED } = this.Characteristic.ProgramMode;
// this.Characteristic.ProgramMode.PROGRAM_SCHEDULED_MANUAL_MODE_ in Homebridge 1.x
// this.Characteristic.ProgramMode.PROGRAM_SCHEDULED_MANUAL_MODE in Homebridge 2.x
const PROGRAM_SCHEDULED_MANUAL_MODE = 2;
let programMode;
if (localControl) {
// Local control takes priority (reverts after a few seconds)
this.log.info(`Manual mode ${detail}`);
programMode = PROGRAM_SCHEDULED_MANUAL_MODE;
}
else if (remoteControl === false || remoteStart === false) {
this.log.info(`Remote operation NOT enabled ${detail}`);
programMode = NO_PROGRAM_SCHEDULED;
}
else {
this.log.info(`Remote operation enabled ${detail}`);
programMode = PROGRAM_SCHEDULED;
}
this.powerService.updateCharacteristic(this.Characteristic.ProgramMode, programMode);
}
};
}
//# sourceMappingURL=has-remotecontrol.js.map