matterbridge-dyson-robot
Version:
A Matterbridge plugin that connects Dyson robot vacuums and air treatment devices to the Matter smart home ecosystem via their local or cloud MQTT APIs.
58 lines • 2.13 kB
JavaScript
// Matterbridge plugin for Dyson robot vacuum and air treatment devices
// Copyright © 2026 Alexander Thoukydides
import { ThermostatBehavior } from 'matterbridge/matter/behaviors';
import { Behavior } from 'matterbridge/matter';
import { logError } from './log-error.js';
// Command handling behaviour for the endpoint
export class BehaviorDeviceAir {
log;
// Registered command handlers
commands = {};
// Construct new command handling behaviour
constructor(log) {
this.log = log;
}
// Set a command handler
setCommandHandler(command, handler) {
if (this.commands[command])
throw new Error(`Handler already registered for command ${command}`);
this.commands[command] = handler;
}
// Execute a command handler
async executeCommand(command, ...args) {
const handler = this.commands[command];
if (!handler)
throw new Error(`${command} not implemented`);
await handler(...args);
}
}
export class BehaviorAir extends Behavior {
static id = 'dyson-air';
}
// eslint-disable-next-line @typescript-eslint/no-namespace
(function (BehaviorAir) {
class State {
device;
}
BehaviorAir.State = State;
})(BehaviorAir || (BehaviorAir = {}));
// Implement command handlers for the Thermostat cluster
export class ThermostatServerAir extends ThermostatBehavior {
// SetpointRaiseLower command handler
async setpointRaiseLower(request) {
const { device } = this.agent.get(BehaviorAir).state;
const { log } = device;
try {
// Attempt to change the setpoint
const { mode, amount } = request;
log.debug(`Thermostat command: SetpointRaiseLower mode=${mode}, amount=${amount}...`);
await device.executeCommand('SetpointRaiseLower', request);
log.debug(`Thermostat command: SetpointRaiseLower mode=${mode}, amount=${amount} - OK`);
}
catch (err) {
logError(log, 'Thermostat SetpointRaiseLower', err);
throw err;
}
}
}
//# sourceMappingURL=endpoint-air-behaviour.js.map