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

50 lines
1.3 KiB
JavaScript

const CarpetModeControlCapability = require("../../../core/capabilities/CarpetModeControlCapability");
const DreameMiotHelper = require("../DreameMiotHelper");
const DreameMiotServices = require("../DreameMiotServices");
/**
* @extends CarpetModeControlCapability<import("../DreameValetudoRobot")>
*/
class DreameCarpetModeControlCapability extends CarpetModeControlCapability {
/**
* @param {object} options
* @param {import("../DreameValetudoRobot")} options.robot
*/
constructor(options) {
super(options);
this.siid = DreameMiotServices["GEN2"].VACUUM_2.SIID;
this.piid = DreameMiotServices["GEN2"].VACUUM_2.PROPERTIES.CARPET_MODE.PIID;
this.helper = new DreameMiotHelper({robot: this.robot});
}
/**
* This function polls the current carpet mode state
*
* @returns {Promise<boolean>}
*/
async isEnabled() {
const res = await this.helper.readProperty(this.siid, this.piid);
return res === 1;
}
/**
* @returns {Promise<void>}
*/
async enable() {
await this.helper.writeProperty(this.siid, this.piid, 1);
}
/**
* @returns {Promise<void>}
*/
async disable() {
await this.helper.writeProperty(this.siid, this.piid, 0);
}
}
module.exports = DreameCarpetModeControlCapability;