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.
65 lines • 2.68 kB
JavaScript
// Matterbridge plugin for Dyson robot vacuum and air treatment devices
// Copyright © 2025-2026 Alexander Thoukydides
import { Changed } from './decorator-changed.js';
import { createHash } from 'crypto';
import { DysonDeviceCompatibility } from './dyson-device-compatibility.js';
// A Dyson robot vacuum or air treatment device
export class DysonDevice {
log;
config;
device;
mqtt;
api;
// Details of the device model
static model;
static filters;
// MQTT client constructor
static mqttConstructor;
// Compatibility log message generator
compatibility;
// Decorator support
changed;
// Construct a new Dyson device instance
constructor(log, config, device, mqtt, api) {
this.log = log;
this.config = config;
this.device = device;
this.mqtt = mqtt;
this.api = api;
// Prepare the decorator support
this.changed = new Changed(log);
// Warn of any expected compatibility issues
const productName = `${this.modelName} (${this.modelNumber})`;
this.compatibility = new DysonDeviceCompatibility(log, config, productName, this.modelType, this.firmwareVersion);
this.compatibility.logCompatibility(this.compatibilityWarning);
}
// Stop the device when Matterbridge is shutting down
async stop() {
await this.mqtt.stop();
}
// Use the serial number to generate a 32-character opaque unique ID
get uniqueId() {
const hash = createHash('sha256').update(this.serialNumber).digest('hex');
const model = this.modelNumber.replace(/.*\//, '').toLowerCase();
return `dyson-${model}-${hash}`.substring(0, 32);
}
// Retrieve the static data for an instance
get classStatic() { return this.constructor; }
get modelName() { return this.api?.modelName ?? this.classStatic.model.name; }
get modelNumber() { return this.api?.modelNumber ?? this.classStatic.model.number; }
get modelType() { return this.classStatic.model.type; }
// Retrieve common per-device data
get deviceName() { return this.device.name; }
get serialNumber() { return this.device.serialNumber; }
get firmwareVersion() { return this.api?.firmwareVersion; }
// Retrieve any compatibility warning for this device
get compatibilityWarning() { return this.compatibility.warning; }
// Convert the MQTT root topic to a ProductID
get productId() {
const hex = this.modelType.replace(/[^A-F0-9]/ig, '');
const parsed = parseInt(hex.substring(0, 4), 16);
return isNaN(parsed) ? 0x0000 : parsed;
}
}
;
//# sourceMappingURL=dyson-device-base.js.map