Skip to content

Commit

Permalink
fix(miio): Various fixes related to Valetudo crashing in some situations
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Mar 13, 2021
1 parent fa8f909 commit a62d7e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/miio/Dummycloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ class Dummycloud {
Logger.info("Dummycloud is spoofing " + this.spoofedIP + ":8053 on " + this.bindIP + ":" + Dummycloud.PORT);
});

this.socket.on("error", (e) => {
Logger.error("DummyCloud Error: ", e);
});

this.socket.bind(Dummycloud.PORT, this.bindIP);


this.miioSocket = new MiioSocket({
socket: this.socket,
token: options.cloudSecret,
Expand Down Expand Up @@ -78,4 +83,4 @@ class Dummycloud {
*/
Dummycloud.PORT = 8053;

module.exports = Dummycloud;
module.exports = Dummycloud;
12 changes: 8 additions & 4 deletions lib/robots/MiioValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class MiioValetudoRobot extends ValetudoRobot {
}
});

this.mapUploadServer.on("error", (e) => {
Logger.error("MapUploadServer Error: ",e);
});

this.mapUploadServer.listen(8079, this.dummycloudBindIp, function() {
Logger.info("Map Upload Server running on port " + 8079);
});
Expand All @@ -111,7 +115,7 @@ class MiioValetudoRobot extends ValetudoRobot {
get deviceId() {
let deviceId = this.implConfig.deviceId;

if (!deviceId) {
if (!deviceId && this.config.get("embedded") === true) {
deviceId = MiioValetudoRobot.READ_DEVICE_CONF(this.deviceConfPath)["did"];
}

Expand All @@ -121,7 +125,7 @@ class MiioValetudoRobot extends ValetudoRobot {
get localSecret() {
let localSecret = this.implConfig.localSecret;

if (!localSecret) {
if (!localSecret && this.config.get("embedded") === true) {
Logger.trace("Trying to read token file at " + this.tokenFilePath);
try {
localSecret = fs.readFileSync(this.tokenFilePath);
Expand All @@ -143,14 +147,14 @@ class MiioValetudoRobot extends ValetudoRobot {
return Buffer.from(localSecret.toString().slice(0, 16));
}

Logger.debug("Invalid localSecret with length " + localSecret.length);
Logger.debug("Invalid localSecret with length " + (localSecret && localSecret.length ? localSecret.length : 0));
return Buffer.alloc(16);
}

get cloudSecret() {
let cloudSecret = this.implConfig.cloudSecret;

if (!cloudSecret) {
if (!cloudSecret && this.config.get("embedded") === true) {
cloudSecret = MiioValetudoRobot.READ_DEVICE_CONF(this.deviceConfPath)["key"];
}

Expand Down

0 comments on commit a62d7e3

Please sign in to comment.