Valetudo/backend/lib/robots/dreame/capabilities/DreameWaterUsageControlCapa...

44 lines
1.3 KiB
JavaScript

const DreameMiotHelper = require("../DreameMiotHelper");
const WaterUsageControlCapability = require("../../../core/capabilities/WaterUsageControlCapability");
/**
* @extends WaterUsageControlCapability<import("../DreameValetudoRobot")>
*/
class DreameWaterUsageControlCapability extends WaterUsageControlCapability {
/**
* @param {object} options
* @param {import("../DreameValetudoRobot")} options.robot
* @param {Array<import("../../../entities/core/ValetudoSelectionPreset")>} options.presets
*
* @param {number} options.siid MIOT Service ID
* @param {number} options.piid MIOT Property ID
*/
constructor(options) {
super(options);
this.siid = options.siid;
this.piid = options.piid;
this.helper = new DreameMiotHelper({robot: this.robot});
}
/**
* @param {string} preset
* @returns {Promise<void>}
*/
async selectPreset(preset) {
const matchedPreset = this.presets.find(p => {
return p.name === preset;
});
if (matchedPreset) {
return this.helper.writeProperty(this.siid, this.piid, matchedPreset.value);
} else {
throw new Error("Invalid Preset");
}
}
}
module.exports = DreameWaterUsageControlCapability;