matterbridge-aeg-robot
Version:
A Matterbridge plugin that connects AEG RX 9 / Electrolux Pure i9 robot vacuums to the Matter smart home ecosystem.
70 lines • 2.48 kB
JavaScript
// Matterbridge plugin for AEG RX9 / Electrolux Pure i9 robot vacuum
// Copyright © 2025 Alexander Thoukydides
import { BabelStaticRX9 } from './babel-static-rx9.js';
import { BABEL_DYNAMIC_RX9 } from './babel-dynamic-rx9.js';
import { isDeepStrictEqual } from 'util';
import { logError } from './utils.js';
// Translation of appliance information to Matter attributes
export class BabelRX9 {
log;
config;
appliance;
// Static appliance information
basicInformation;
// Event listeners
listeners = {};
// Emitted dynamic robot status
emittedState = new Map();
// Construct a new translator
constructor(log, config, appliance) {
this.log = log;
this.config = config;
this.appliance = appliance;
// Delegate manipulation of static data
this.basicInformation = new BabelStaticRX9(this.log, this.config, this.appliance);
// Translate and emit events for dynamic data whenever it changes
this.appliance.on('changed', () => {
for (const event of Object.keys(BABEL_DYNAMIC_RX9)) {
void this.emitIfChanged(event);
}
});
}
// Register a status event handler
on(event, listener) {
this.listeners[event] ??= [];
this.listeners[event].push(listener);
return this;
}
// Emit a status event if the value has changed
async emitIfChanged(event) {
// Perform the translation to generate the new value
const newValue = this.getState(event);
if (newValue === undefined)
return;
// No action required if the value is unchanged
if (isDeepStrictEqual(this.emittedState.get(event), newValue))
return;
this.emittedState.set(event, newValue);
// Log the new value
this.log.debug(`Babel ${event}: ${JSON.stringify(newValue)}`);
// Emit an event for this value
for (const listener of (this.listeners[event] ?? [])) {
try {
await listener(newValue);
}
catch (err) {
logError(this.log, `Babel ${event} listener`, err);
}
}
}
// Translate a specific value
getState(event) {
try {
return BABEL_DYNAMIC_RX9[event](this.appliance.state);
}
catch (err) {
logError(this.log, `Babel ${event} translation`, err);
}
}
}
//# sourceMappingURL=babel-rx9.js.map