Skip to content

Commit

Permalink
feat: Viomi capabilities port
Browse files Browse the repository at this point in the history
  • Loading branch information
depau authored and Hypfer committed Dec 30, 2020
1 parent 76a9c52 commit 8486f04
Show file tree
Hide file tree
Showing 21 changed files with 1,234 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/core/ValetudoRobotFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const Robots = {
"RoborockS6ValetudoRobot": require("../robots/roborock/RoborockS6ValetudoRobot"),
"RoborockS4ValetudoRobot": require("../robots/roborock/RoborockS4VacuumRobot"),
"RoborockS5MaxValetudoRobot": require("../robots/roborock/RoborockS5MaxValetudoRobot"),
"DreameMc1808ValetudoRobot": require("../robots/dreame/DreameMc1808ValetudoRobot")
"DreameMc1808ValetudoRobot": require("../robots/dreame/DreameMc1808ValetudoRobot"),
"ViomiV7ValetudoRobot": require("../robots/viomi/ViomiV7ValetudoRobot"),
"ViomiV8ValetudoRobot": require("../robots/viomi/ViomiV8ValetudoRobot")
};

module.exports = ValetudoRobotFactory;
21 changes: 21 additions & 0 deletions lib/entities/core/ValetudoWaterUsagePreset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const SerializableEntity = require("../SerializableEntity");


// noinspection JSCheckFunctionSignatures
class ValetudoWaterUsagePreset extends SerializableEntity {
/**
* @param {object} options
* @param {string} options.name
* @param {any} options.value
* @param {object} [options.metaData]
* @class
*/
constructor(options) {
super(options);

this.name = options.name;
this.value = options.value;
}
}

module.exports = ValetudoWaterUsagePreset;
5 changes: 3 additions & 2 deletions lib/entities/state/attributes/ConsumableStateAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ConsumableStateAttribute extends StateAttribute {
ConsumableStateAttribute.TYPE = Object.freeze({
FILTER: "filter",
BRUSH: "brush",
SENSOR: "sensor"
SENSOR: "sensor",
MOP: "mop"
});

/**
Expand All @@ -55,4 +56,4 @@ ConsumableStateAttribute.UNITS = Object.freeze({
});


module.exports = ConsumableStateAttribute;
module.exports = ConsumableStateAttribute;
44 changes: 44 additions & 0 deletions lib/entities/state/attributes/WaterUsageStateAttribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const StateAttribute = require("./StateAttribute");

class WaterUsageStateAttribute extends StateAttribute {
/**
* @param {object} options
* @param {WaterUsageStateAttributeValue} options.value
* @param {number} [options.customValue]
* @param {object} [options.metaData]
*/
constructor(options) {
super(options);

this.value = options.value;

if (options.customValue) {
if (this.value === WaterUsageStateAttribute.VALUE.CUSTOM) {
this.customValue = options.customValue;
} else {
throw new Error("Custom water usage value requires water usage Value CUSTOM");
}
} else if (this.value === WaterUsageStateAttribute.VALUE.CUSTOM) {
throw new Error("Missing custom value for CUSTOM water usage");
}
}
}

/**
* @typedef {string} WaterUsageStateAttributeValue
* @enum {string}
*
*/
WaterUsageStateAttribute.VALUE = Object.freeze({
OFF: "off",
MIN: "min",
LOW: "low",
MEDIUM: "medium",
HIGH: "high",
MAX: "max",
CUSTOM: "custom"
});



module.exports = WaterUsageStateAttribute;
8 changes: 8 additions & 0 deletions lib/miio/MiioInvalidStampError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class MiioInvalidStampError extends Error {
constructor() {
super("Invalid MiioSocket stamp");
this.name = "MiioInvalidStampError";
}
}

module.exports = MiioInvalidStampError;
17 changes: 9 additions & 8 deletions lib/miio/RetryWrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const createMiioHeader = require("./MiioHeader");
const Logger = require("../Logger");
const MiioTimeoutError = require("./MiioTimeoutError");
const MiioInvalidStampError = require("./MiioInvalidStampError");

const STATES = Object.freeze({
HANDSHAKING: "handshaking",
Expand Down Expand Up @@ -93,23 +94,23 @@ class RetryWrapper {
* @returns {Promise<object>}
*/
async sendMessage(method, args = [], options = {}) {
if (!this.miioSocket.stamp.isValid()) {
await this.handshake(false);

return await this.sendMessage(method, args, options);
}

const msg = {method: method, params: args};

try {
if (!this.miioSocket.stamp.isValid()) {
// Trigger retry after performing new handshake
// noinspection ExceptionCaughtLocallyJS
throw new MiioInvalidStampError();
}

return await this.miioSocket.sendMessage(
msg,
{
timeout: options.timeout
}
);
} catch (e) {
if (!(e instanceof MiioTimeoutError)) {
if (!(e instanceof MiioTimeoutError) && !(e instanceof MiioInvalidStampError)) {
throw e; //Throw this further up if it's not expected
}

Expand Down Expand Up @@ -159,4 +160,4 @@ class RetryWrapper {
}
}

module.exports = RetryWrapper;
module.exports = RetryWrapper;
55 changes: 55 additions & 0 deletions lib/robots/viomi/ViomiCommonAttributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const stateAttrs = require("../../entities/state/attributes");

// Common Viomi enums

/** @enum {number} */
const ViomiOperationMode = Object.freeze({
VACUUM: 0,
MIXED: 1,
MOP: 2,
});

/** @enum {number} */
const ViomiBoxType = Object.freeze({
NONE: 0,
VACUUM: 1,
WATER: 2,
VACUUM_AND_WATER: 3
});

/** @enum {number} */
const ViomiOperation = Object.freeze({
STOP: 0,
START: 1,
PAUSE: 2
});

/** @enum {number} */
const ViomiMovementMode = Object.freeze({
NORMAL_CLEANING: 0,
MOP_MOVES: 1, // back and forth mopping movement (unsure if this has an effect without mop-mode)
OUTLINE: 2, // Only clean the rooms outline.
ZONED_CLEAN_OR_MOPPING: 3,
});

const FAN_SPEEDS = Object.freeze({
[stateAttrs.IntensityStateAttribute.VALUE.LOW]: 0,
[stateAttrs.IntensityStateAttribute.VALUE.MEDIUM]: 1,
[stateAttrs.IntensityStateAttribute.VALUE.HIGH]: 2,
[stateAttrs.IntensityStateAttribute.VALUE.MAX]: 3
});

const WATER_GRADES = Object.freeze({
[stateAttrs.IntensityStateAttribute.VALUE.LOW]: 11,
[stateAttrs.IntensityStateAttribute.VALUE.MEDIUM]: 12,
[stateAttrs.IntensityStateAttribute.VALUE.HIGH]: 13,
});

module.exports = {
ViomiBoxType: ViomiBoxType,
ViomiOperationMode: ViomiOperationMode,
ViomiOperation: ViomiOperation,
ViomiMovementMode: ViomiMovementMode,
FAN_SPEEDS: FAN_SPEEDS,
WATER_GRADES: WATER_GRADES
};
27 changes: 27 additions & 0 deletions lib/robots/viomi/ViomiV7ValetudoRobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const ViomiValetudoRobot = require("./ViomiValetudoRobot");
const MiioValetudoRobot = require("../MiioValetudoRobot");


class ViomiV7ValetudoRobot extends ViomiValetudoRobot {
/**
* @param {object} options
* @param {import("../../Configuration")} options.config
* @param {object} [options.fanSpeeds]
* @param {object} [options.waterGrades]
*/
constructor(options) {
super(options);
// TODO: register model-specific capabilities
}

getModelName() {
return "Xiaomi Mijia STYJ02YM";
}

static IMPLEMENTATION_AUTO_DETECTION_HANDLER() {
const deviceConf = MiioValetudoRobot.READ_DEVICE_CONF(ViomiValetudoRobot.DEVICE_CONF_PATH);
return !!(deviceConf && deviceConf.model === "viomi.vacuum.v7");
}
}

module.exports = ViomiV7ValetudoRobot;
27 changes: 27 additions & 0 deletions lib/robots/viomi/ViomiV8ValetudoRobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const ViomiValetudoRobot = require("./ViomiValetudoRobot");
const MiioValetudoRobot = require("../MiioValetudoRobot");


class ViomiV8ValetudoRobot extends ViomiValetudoRobot {
/**
* @param {object} options
* @param {import("../../Configuration")} options.config
* @param {object} [options.fanSpeeds]
* @param {object} [options.waterGrades]
*/
constructor(options) {
super(options);
// TODO: register model-specific capabilities
}

getModelName() {
return "Xiaomi Mijia STYTJ02YM";
}

static IMPLEMENTATION_AUTO_DETECTION_HANDLER() {
const deviceConf = MiioValetudoRobot.READ_DEVICE_CONF(ViomiValetudoRobot.DEVICE_CONF_PATH);
return !!(deviceConf && deviceConf.model === "viomi.vacuum.v8");
}
}

module.exports = ViomiV8ValetudoRobot;

0 comments on commit 8486f04

Please sign in to comment.