Skip to content

Commit

Permalink
fix: Resetting the map should also clear the Map cached by Valetudo
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Jul 25, 2021
1 parent 2bbd86f commit e70041f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/lib/core/ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ class ValetudoRobot {
this.capabilities = {};

this.state = new entities.state.RobotState({
map: require("../res/default_map")
map: ValetudoRobot.DEFAULT_MAP
});
}

/**
* @public
*/
clearValetudoMap() {
this.state.map = ValetudoRobot.DEFAULT_MAP;

this.emitMapUpdated();
}

/**
*
* @param {import("./capabilities/Capability")} capability
Expand Down Expand Up @@ -148,4 +157,6 @@ ValetudoRobot.EVENTS = {
MapUpdated: "MapUpdated"
};

ValetudoRobot.DEFAULT_MAP = require("../res/default_map");

module.exports = ValetudoRobot;
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class DreameMapResetCapability extends MapResetCapability {
) {
switch (res.out[0].value) {
case 0:
this.robot.clearValetudoMap();
return;
default:
throw new Error("Got error " + res.out[0].value + " while resetting map.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RoborockMapResetCapability extends MapResetCapability {
if (!(Array.isArray(res) && res[0] === "ok")) {
throw new Error("Failed to reset map: " + res);
}

this.robot.clearValetudoMap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RoborockMultiMapMapResetCapability extends MapResetCapability {
if (!(Array.isArray(res) && res[0] === "ok")) {
throw new Error("Failed to reset map: " + res);
}

this.robot.clearValetudoMap();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ViomiMapResetCapability extends MapResetCapability {
*/
async reset() {
await this.robot.sendCommand("set_resetmap", [], {});

this.robot.clearValetudoMap();
}
}

Expand Down

0 comments on commit e70041f

Please sign in to comment.