Skip to content

Commit

Permalink
fix(miio): Only report a new token from handshake if it is actually new
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Jan 27, 2021
1 parent 4b3ed97 commit b373703
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/core/ValetudoRobotFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Robots = {
"RoborockS4ValetudoRobot": require("../robots/roborock/RoborockS4ValetudoRobot"),
"RoborockS6PureValetudoRobot": require("../robots/roborock/RoborockS6PureValetudoRobot"),
"RoborockS5MaxValetudoRobot": require("../robots/roborock/RoborockS5MaxValetudoRobot"),
"RoborockS6MaxVValetudoRobot": require("../robots/roborock/RoborockS6MaxVValetudoRobot"),
"Dreame1CValetudoRobot": require("../robots/dreame/Dreame1CValetudoRobot"),
"DreameD9ValetudoRobot": require("../robots/dreame/DreameD9ValetudoRobot"),
"ViomiV7ValetudoRobot": require("../robots/viomi/ViomiV7ValetudoRobot"),
Expand Down
6 changes: 4 additions & 2 deletions lib/miio/MiioSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class MiioSocket {
const decodedResponse = this.codec.handleResponse(incomingMsg);
const token = decodedResponse.token;
if (token && token.toString("hex") !== "ffffffffffffffffffffffffffffffff" &&
token.toString("hex") !== "00000000000000000000000000000000") {
token.toString("hex") !== "00000000000000000000000000000000" &&
!(this.codec.token.equals(token))
) {
Logger.info("Got token from handshake:", decodedResponse.token.toString("hex"));
this.token = token;
this.codec.setToken(token);
Expand Down Expand Up @@ -227,4 +229,4 @@ class MiioSocket {
/** The default remote port. @const {int} */
MiioSocket.PORT = 54321;

module.exports = MiioSocket;
module.exports = MiioSocket;
55 changes: 55 additions & 0 deletions lib/robots/roborock/RoborockS6MaxVValetudoRobot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const RoborockValetudoRobot = require("./RoborockValetudoRobot");
const MiioValetudoRobot = require("../MiioValetudoRobot");
const capabilities = require("./capabilities");
const entities = require("../../entities");

/**
* Do NOT buy this robot.
* Roborock purposefully made this hard to repair which is a consumer-hostile practice
* that is not supported by Valetudo
*
* This class only exists for the unfortunate souls who already own one
*/
class RoborockS6MaxVValetudoRobot extends RoborockValetudoRobot {
/**
*
* @param {object} options
* @param {import("../../Configuration")} options.config
*/
constructor(options) {
super(Object.assign({}, options, {fanSpeeds: FAN_SPEEDS}));

this.registerCapability(new capabilities.RoborockMapSnapshotCapability({
robot: this
}));
this.registerCapability(new capabilities.RoborockCombinedVirtualRestrictionsCapability({
robot: this
}));
this.registerCapability(new capabilities.RoborockMultiMapPersistentMapControlCapability({
robot: this
}));
this.registerCapability(new capabilities.RoborockMapSegmentationCapability({
robot: this
}));
}

getModelName() {
return "S6 MaxV";
}

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

return !!(deviceConf && (deviceConf.model === "roborock.vacuum.a10" || deviceConf.model === "roborock.vacuum.a09"));
}
}

const FAN_SPEEDS = {
[entities.state.attributes.IntensityStateAttribute.VALUE.LOW]: 101,
[entities.state.attributes.IntensityStateAttribute.VALUE.MEDIUM]: 102,
[entities.state.attributes.IntensityStateAttribute.VALUE.HIGH]: 103,
[entities.state.attributes.IntensityStateAttribute.VALUE.MAX]: 104,
[entities.state.attributes.IntensityStateAttribute.VALUE.OFF] : 105 //also known as mop mode
};

module.exports = RoborockS6MaxVValetudoRobot;

0 comments on commit b373703

Please sign in to comment.