UNPKG

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.

83 lines 3.37 kB
// Matterbridge plugin for Dyson robot vacuum and air treatment devices // Copyright © 2025 Alexander Thoukydides import { DysonMqtt } from './dyson-mqtt.js'; import { checkers as dysonMsgCheckers360 } from './ti/dyson-360-msg-types.js'; import { tryListener } from './utils.js'; import { Dyson360CleaningMode, Dyson360CleaningType } from './dyson-360-types.js'; import { DysonModeReason } from './dyson-types.js'; // Configuration of a Dyson MQTT client for robot vacuums const DYSON_MQTT_CONFIG_360 = { topics: { command: '@/@/command', subscribe: ['@/@/status'], other: ['@/initialconnection/credentials', '@/initialconnection/status'] }, messages: { prefix: 'Dyson360Msg', checkers: dysonMsgCheckers360 } }; // Dyson MQTT client for robot vacuums export class DysonMqtt360 extends DysonMqtt { // Construct a new MQTT client constructor(log, config, device) { super(log, config, device, DYSON_MQTT_CONFIG_360); // Handle MQTT events this.on('subscribed', tryListener(this, async () => // Request the current status when (re)connected this.publish('REQUEST-CURRENT-STATE', {}))).on('message', tryListener(this, msg => { // Update the robot vacuum state from the received messages switch (msg.msg) { case 'STATE-CHANGE': msg = this.convertStateChange(msg); // (fallthrough) case 'CURRENT-STATE': this.updateState(msg); break; } })); } // Convert a STATE-CHANGE message to CURRENT-STATE format convertStateChange(msg) { const { msg: _, newstate: state, oldstate, endOfClean, ...otherFields } = msg; return { msg: 'CURRENT-STATE', state, ...otherFields }; } // Update the robot vacuum state from a received message updateState(msg) { // Copy most fields from the message to the state const { msg: _msg, time, ...status } = msg; this.status.faults = undefined; // (ensure faults get cleared) Object.assign(this.status, status); // State is fully initialised after the first message has been received if (!this.status.initialised) { this.status.initialised = true; this.log.info('MQTT client initialisation complete'); } } // Publish a robot vacuum command to perform an action commandAction(msg) { switch (msg) { case 'START': return this.publish('START', { 'mode-reason': DysonModeReason.LocalApp, fullCleanType: Dyson360CleaningType.Immediate, cleaningMode: this.status.defaultCleaningMode && Dyson360CleaningMode.Global }); case 'PAUSE': case 'RESUME': case 'ABORT': return this.publish(msg, { 'mode-reason': DysonModeReason.LocalApp }); } } // Publish a robot vacuum command to set the default power level commandPower(defaultVacuumPowerMode) { return this.publish('STATE-SET', { 'mode-reason': DysonModeReason.LocalApp, data: { defaultVacuumPowerMode } }); } } //# sourceMappingURL=dyson-mqtt-360.js.map