Skip to content

Commit

Permalink
feat(vendor.roborock): G10S support
Browse files Browse the repository at this point in the history
Signed-off-by: Xuefer H <[email protected]>
  • Loading branch information
Xuefer H committed Aug 19, 2023
1 parent 80a15fe commit 1c0f724
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
129 changes: 129 additions & 0 deletions backend/lib/robots/roborock/RoborockG10SValetudoRobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const capabilities = require("./capabilities");
const entities = require("../../entities");
const fs = require("fs");
const Logger = require("../../Logger");
const MiioValetudoRobot = require("../MiioValetudoRobot");
const QuirksCapability = require("../../core/capabilities/QuirksCapability");
const RoborockGen4ValetudoRobot = require("./RoborockGen4ValetudoRobot");
const RoborockQuirkFactory = require("./RoborockQuirkFactory");
const RoborockValetudoRobot = require("./RoborockValetudoRobot");
const ValetudoRestrictedZone = require("../../entities/core/ValetudoRestrictedZone");

class RoborockG10SValetudoRobot extends RoborockGen4ValetudoRobot {
/**
*
* @param {object} options
* @param {import("../../Configuration")} options.config
* @param {import("../../ValetudoEventStore")} options.valetudoEventStore
*/
constructor(options) {
super(
Object.assign(
{},
options,
{
waterGrades: WATER_GRADES,
supportedAttachments: SUPPORTED_ATTACHMENTS,
hasUltraDock: true
}
)
);


this.registerCapability(new capabilities.RoborockCombinedVirtualRestrictionsCapability({
robot: this,
supportedRestrictedZoneTypes: [
ValetudoRestrictedZone.TYPE.REGULAR,
ValetudoRestrictedZone.TYPE.MOP
]
}));

this.registerCapability(new capabilities.RoborockWaterUsageControlCapability({
robot: this,
presets: Object.keys(this.waterGrades).map(k => {
return new entities.core.ValetudoSelectionPreset({name: k, value: this.waterGrades[k]});
})
}));

this.registerCapability(new capabilities.RoborockConsumableMonitoringCapability({
robot: this,
hasUltraDock: true
}));

this.registerCapability(new capabilities.RoborockCarpetSensorModeControlCapability({
robot: this,
liftModeId: 1
}));

[
capabilities.RoborockAutoEmptyDockAutoEmptyControlCapability,
capabilities.RoborockAutoEmptyDockManualTriggerCapability,
capabilities.RoborockMopDockCleanManualTriggerCapability,
capabilities.RoborockKeyLockCapability,
capabilities.RoborockMappingPassCapability,
capabilities.RoborockObstacleAvoidanceControlCapability,
capabilities.RoborockPetObstacleAvoidanceControlCapability,
capabilities.RoborockCollisionAvoidantNavigationControlCapability
].forEach(capability => {
this.registerCapability(new capability({robot: this}));
});

const quirkFactory = new RoborockQuirkFactory({
robot: this
});
this.registerCapability(new QuirksCapability({
robot: this,
quirks: [
quirkFactory.getQuirk(RoborockQuirkFactory.KNOWN_QUIRKS.AUTO_EMPTY_DURATION),
quirkFactory.getQuirk(RoborockQuirkFactory.KNOWN_QUIRKS.MOP_DOCK_MOP_CLEANING_MODE),
quirkFactory.getQuirk(RoborockQuirkFactory.KNOWN_QUIRKS.MOP_DOCK_MOP_CLEANING_FREQUENCY),
quirkFactory.getQuirk(RoborockQuirkFactory.KNOWN_QUIRKS.BUTTON_LEDS),
quirkFactory.getQuirk(RoborockQuirkFactory.KNOWN_QUIRKS.MOP_PATTERN),
]
}));
}

getModelName() {
return "G10S";
}

getFirmwareVersion() {
try {
const rr_info = fs.readFileSync("/etc/rr-info").toString();
const parsedFile = /^Version:(?<version>[\d._]*)$/m.exec(rr_info);

if (parsedFile !== null && parsedFile.groups && parsedFile.groups.version) {
return parsedFile.groups.version;
} else {
Logger.warn("Unable to determine the Firmware Version");

return null;
}
} catch (e) {
Logger.warn("Unable to determine the Firmware Version", e);

return null;
}
}

static IMPLEMENTATION_AUTO_DETECTION_HANDLER() {
const deviceConf = MiioValetudoRobot.READ_DEVICE_CONF(RoborockValetudoRobot.DEVICE_CONF_PATH);

return !!(deviceConf && deviceConf.model === "roborock.vacuum.a46");
}
}

const WATER_GRADES = {
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.OFF] : 200,
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.LOW]: 201,
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.MEDIUM]: 202,
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.HIGH]: 203
};

const SUPPORTED_ATTACHMENTS = [
entities.state.attributes.AttachmentStateAttribute.TYPE.WATERTANK,
entities.state.attributes.AttachmentStateAttribute.TYPE.MOP,
];


module.exports = RoborockG10SValetudoRobot;
1 change: 1 addition & 0 deletions backend/lib/robots/roborock/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
"RoborockG10SValetudoRobot": require("./RoborockG10SValetudoRobot"),
"RoborockM1SValetudoRobot": require("./RoborockM1SValetudoRobot"),
"RoborockQ7MaxValetudoRobot": require("./RoborockQ7MaxValetudoRobot"),
"RoborockS4MaxValetudoRobot": require("./RoborockS4MaxValetudoRobot"),
Expand Down

0 comments on commit 1c0f724

Please sign in to comment.