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.

71 lines 3.24 kB
// Matterbridge plugin for Dyson robot vacuum and air treatment devices // Copyright © 2025 Alexander Thoukydides import { Thermostat } from 'matterbridge/matter/clusters'; import { assertIsDefined } from './utils.js'; import { DysonAirFanState, DysonAirHeatingMode, DysonAirHeatingStatus } from './dyson-air-types.js'; import { numeric } from './dyson-device-air-quality.js'; // Mixin to add heating to a Dyson air treatment device export function DysonDeviceAirWithHeat(Base) { class DysonDeviceAirWithHeat extends Base { // Mixin constructor constructor(...args) { super(...args); } // Install handlers async installHandlers(endpoints) { await super.installHandlers(endpoints); await endpoints.setThermostatHandlers({ occupiedHeatingSetpoint: setpoint => this.setTargetTemperature(setpoint / 100), systemMode: mode => { switch (mode) { case Thermostat.SystemMode.Heat: case Thermostat.SystemMode.EmergencyHeat: return this.setHeating(true); case Thermostat.SystemMode.Off: default: return this.setHeating(false); } } }); } // Set the heating target temperature async setTargetTemperature(celsius) { this.log.info(`Enabling heating with target temperature ${celsius} °C`); const hmod = DysonAirHeatingMode.Heat; await this.setState({ hmax: celsius, hmod }); } // Enable or disable heating async setHeating(heat) { this.log.info(`${heat ? 'Enabling' : 'Disabling'} heating`); // Turn power on when enabling heating, but not when disabling await this.setState({ hmod: DysonAirHeatingMode[heat ? 'Heat' : 'Cool'] }); } // List of endpoint function names and descriptions to validate getEntities() { return [...super.getEntities(), { name: 'Thermostat', description: 'Heating control' }]; } // Update cluster attributes when the MQTT status is updated async updateClusterAttributes(status) { await super.updateClusterAttributes(status); const { fnst, hmax, hmod, hsta, tact } = status; assertIsDefined(hmax); assertIsDefined(tact); const heatingMode = hmod === DysonAirHeatingMode.Heat; const heat = hsta === DysonAirHeatingStatus.Heating; const fan = fnst === DysonAirFanState.Running; await this.endpoints?.updateThermostat({ localTemperature: numeric(tact, 100), // centi-°C occupiedHeatingSetpoint: hmax * 100, // centi-°C piHeatingDemand: heat ? 100 : 0, // % systemMode: Thermostat.SystemMode[heatingMode ? 'Heat' : 'Off'], thermostatRunningState: { heat, fan } }); } } ; return DysonDeviceAirWithHeat; } //# sourceMappingURL=dyson-device-air-heat.js.map