Skip to content

Commit

Permalink
feat(vendor.roborock): Roborock/Capability Carpet Mode (#661)
Browse files Browse the repository at this point in the history
* UI and API fix for comsumables

* Roborock/Capability Do Not Disturb

* Roborock/Capability Do Not Disturb
#656 - modifications

* Roborock/Capability Do Not Disturb

* CarpetMode-Capability

* Fixed ValetudoCarpetModeConfiguration to be serializableentity

* Roborock/Capability Carpet Mode #661

* Carpet mode capability updates

* Roborock/Capability Carpet Mode #661
  • Loading branch information
bensweet86 authored Feb 8, 2021
1 parent 3c0a644 commit 54ca606
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 57 deletions.
15 changes: 8 additions & 7 deletions client/services/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,22 @@ export class ApiService {
});
}

static async getCarpetMode() {
return await this.fetch("GET", "api/get_carpet_mode");
static async getCarpetModeStatus() {
return await this.fetch("GET", "api/v2/robot/capabilities/CarpetModeControlCapability");
}

static async setCarpetMode(enable, current_low, current_high, current_integral, stall_time) {
await this.fetch("PUT", "api/set_carpet_mode", {
enable, current_low, current_high, current_integral, stall_time
});
static async enableCarpetMode() {
await this.fetch("PUT", "api/v2/robot/capabilities/CarpetModeControlCapability", {action: "enable"});
}

static async disableCarpetMode() {
await this.fetch("PUT", "api/v2/robot/capabilities/CarpetModeControlCapability", {action: "disable"});
}

static async getCapabilities() {
return await this.fetch("GET", "api/v2/robot/capabilities");
}


static async getPersistentMapCapabilityStatus() {
return await this.fetch("GET", "api/v2/robot/capabilities/PersistentMapControlCapability");
}
Expand Down
31 changes: 1 addition & 30 deletions client/settings-carpet-mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,12 @@
<ons-row>
<ons-col></ons-col>
<ons-col width="150px" vertical-align='center'>Enabled</ons-col>
<ons-col width="150px" vertical-align='center'><ons-checkbox input-id="carpet_mode_enabled"></ons-checkbox></ons-col>
<ons-col width="150px" vertical-align='center'><ons-switch input-id="carpet_mode_enabled"></ons-switch></ons-col>
<ons-col></ons-col>
</ons-row>
<ons-row>
<ons-col><br/></ons-col>
</ons-row>
<ons-row>
<ons-col></ons-col>
<ons-col vertical-align='center' style='text-align:center; max-width: 400px;'><b>Only change any of the following parameter if you know what you are doing!</b></ons-col>
<ons-col></ons-col>
</ons-row>
<ons-row>
<ons-col></ons-col>
<ons-col width="150px" vertical-align='center'>Current Low</ons-col>
<ons-col width="150px" vertical-align='center'><ons-input type="number" placeholder="400" min="1" max="1000" name="current_low"></ons-input></ons-col>
<ons-col></ons-col>
</ons-row>
<ons-row>
<ons-col></ons-col>
<ons-col width="150px" vertical-align='center'>Current High</ons-col>
<ons-col width="150px" vertical-align='center'><ons-input type="number" placeholder="500" min="1" max="1000" name="current_high"></ons-input></ons-col>
<ons-col></ons-col>
</ons-row>
<ons-row>
<ons-col></ons-col>
<ons-col width="150px" vertical-align='center'>Current Integral</ons-col>
<ons-col width="150px" vertical-align='center'><ons-input type="number" placeholder="450" min="1" max="1000" name="current_integral"></ons-input></ons-col>
<ons-col></ons-col>
</ons-row>
<ons-row>
<ons-col></ons-col>
<ons-col width="150px" vertical-align='center'>Stall Time</ons-col>
<ons-col width="150px" vertical-align='center'><ons-input type="number" placeholder="100" min="1" max="100" name="stall_time"></ons-input></ons-col>
<ons-col></ons-col>
</ons-row>
<ons-row>
<ons-col></ons-col>
<ons-col width="100px" vertical-align='center'><ons-button modifier="large" class="button-margin" onclick="saveCarpetMode();">Save</ons-button></ons-col>
Expand Down
24 changes: 9 additions & 15 deletions client/settings-carpet-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ async function updateSettingsCarpetModePage() {

loadingBarSettingsCarpetMode.setAttribute("indeterminate", "indeterminate");
try {
let res = await ApiService.getCarpetMode();
var carpetForm = document.getElementById("carpet-mode-form");
var result = res[0];
carpetForm.current_low.value = result.current_low;
carpetForm.current_high.value = result.current_high;
carpetForm.current_integral.value = result.current_integral;
carpetForm.stall_time.value = result.stall_time;
document.getElementById("carpet_mode_enabled").checked = (result.enable === 1);
let res = await ApiService.getCarpetModeStatus();
document.getElementById("carpet_mode_enabled").checked = res.enabled;
} catch (err) {
ons.notification.toast(err.message,
{buttonLabel: "Dismiss", timeout: window.fn.toastErrorTimeout});
Expand All @@ -30,15 +24,15 @@ async function saveCarpetMode() {

if (answer === 1) {
loadingBarSettingsCarpetMode.setAttribute("indeterminate", "indeterminate");
var carpetForm = document.getElementById("carpet-mode-form");
var current_low = carpetForm.current_low.value;
var current_high = carpetForm.current_high.value;
var current_integral = carpetForm.current_integral.value;
var stall_time = carpetForm.stall_time.value;
var enable = (document.getElementById("carpet_mode_enabled").checked === true);
var enabled = document.getElementById("carpet_mode_enabled").checked;

try {
await ApiService.setCarpetMode(enable, current_low, current_high, current_integral, stall_time);
if (enabled) {
await ApiService.enableCarpetMode();
} else {
await ApiService.disableCarpetMode();
}

updateSettingsCarpetModePage();
} catch (err) {
ons.notification.toast(err.message,
Expand Down
3 changes: 1 addition & 2 deletions client/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
<div class="content">Manage timers</div>
</ons-card>

<!--
<ons-card onclick="fn.pushPage({'id': 'settings-carpet-mode.html', 'title': 'Carpet Mode'})">
<div class="title"><ons-icon icon="fa-cart-arrow-down"></ons-icon> Carpet Mode</div>
<div class="content">Configure carpet mode</div>
</ons-card>
-->

<ons-card onclick="fn.pushPage({'id': 'settings-persistent-data.html', 'title': 'Persistent Maps'})">
<div class="title"><ons-icon icon="fa-map"></ons-icon> Persistent Data</div>
<div class="content">Configure the lab mode for enabling virtual walls etc.</div>
Expand Down
38 changes: 38 additions & 0 deletions lib/core/capabilities/CarpetModeControlCapability.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const Capability = require("./Capability");
const NotImplementedError = require("../NotImplementedError");

class CarpetModeControlCapability extends Capability {
/**
* This function polls the current carpet mode state
*
* @abstract
* @returns {Promise<boolean>}
*/
async isEnabled() {
throw new NotImplementedError();
}

/**
* @abstract
* @returns {Promise<void>}
*/
async enable() {
throw new NotImplementedError();
}

/**
* @abstract
* @returns {Promise<void>}
*/
async disable() {
throw new NotImplementedError();
}

getType() {
return CarpetModeControlCapability.TYPE;
}
}

CarpetModeControlCapability.TYPE = "CarpetModeControlCapability";

module.exports = CarpetModeControlCapability;
1 change: 1 addition & 0 deletions lib/core/capabilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ module.exports = {
SpeakerVolumeControlCapability: require("./SpeakerVolumeControlCapability"),
RawCommandCapability: require("./RawCommandCapability"),
DoNotDisturbCapability: require("./DoNotDisturbCapability"),
CarpetModeControlCapability: require("./CarpetModeControlCapability"),
};
3 changes: 3 additions & 0 deletions lib/robots/roborock/RoborockValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class RoborockValetudoRobot extends MiioValetudoRobot {
this.registerCapability(new capabilities.RoborockDoNotDisturbCapability({
robot: this
}));
this.registerCapability(new capabilities.RoborockCarpetModeControlCapability({
robot: this
}));
}

setEmbeddedParameters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const CarpetModeControlCapability = require("../../../core/capabilities/CarpetModeControlCapability");

class RoborockCarpetModeControlCapability extends CarpetModeControlCapability {
/**
* This function polls the current carpet mode state and stores the attributes in our robostate
*
* @abstract
* @returns {Promise<boolean>}
*/
async isEnabled() {
const res = await this.robot.sendCommand("get_carpet_mode", [], {});

return res[0].enable;
}

/**
* @abstract
* @returns {Promise<void>}
*/
async enable() {
const res = await this.robot.sendCommand("get_carpet_mode", [], {});

await this.robot.sendCommand("set_carpet_mode", [{
enable: 1,
stall_time: (res[0].stall_time),
current_low: (res[0].current_low),
current_high: (res[0].current_high),
current_integral: (res[0].current_integral)

}], {});
}

/**
* @abstract
* @returns {Promise<void>}
*/
async disable() {
const res = await this.robot.sendCommand("get_carpet_mode", [], {});

await this.robot.sendCommand("set_carpet_mode", [{
enable: 0,
stall_time: (res[0].stall_time),
current_low: (res[0].current_low),
current_high: (res[0].current_high),
current_integral: (res[0].current_integral)
}], {});
}
}

module.exports = RoborockCarpetModeControlCapability;
3 changes: 2 additions & 1 deletion lib/robots/roborock/capabilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module.exports = {
RoborockPersistentMapControlCapability: require("./RoborockPersistentMapControlCapability"),
RoborockMultiMapPersistentMapControlCapability: require("./RoborockMultiMapPersistentMapControlCapability"),
RoborockMapSegmentationCapability: require("./RoborockMapSegmentationCapability"),
RoborockDoNotDisturbCapability: require("./RoborockDoNotDisturbCapability")
RoborockDoNotDisturbCapability: require("./RoborockDoNotDisturbCapability"),
RoborockCarpetModeControlCapability: require("./RoborockCarpetModeControlCapability")
};
3 changes: 2 additions & 1 deletion lib/webserver/CapabilitiesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const CAPABILITY_TYPE_TO_ROUTER_MAPPING = {
[capabilities.SpeakerVolumeControlCapability.TYPE]: capabilityRouters.SpeakerVolumeControlCapabilityRouter,
[capabilities.RawCommandCapability.TYPE]: capabilityRouters.RawCommandCapabilityRouter,
[capabilities.MapSegmentationCapability.TYPE]: capabilityRouters.MapSegmentationCapabilityRouter,
[capabilities.DoNotDisturbCapability.TYPE]: capabilityRouters.DoNotDisturbCapabilityRouter
[capabilities.DoNotDisturbCapability.TYPE]: capabilityRouters.DoNotDisturbCapabilityRouter,
[capabilities.CarpetModeControlCapability.TYPE]: capabilityRouters.CarpetModeControlCapabilityRouter
};

module.exports = CapabilitiesRouter;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const Logger = require("../../Logger");

const CapabilityRouter = require("./CapabilityRouter");

class CarpetModeControlCapabilityRouter extends CapabilityRouter {

initRoutes() {
this.router.get("/", async (req, res) => {
res.json({
enabled: await this.capability.isEnabled()
});
});

this.router.put("/", async (req, res) => {
if (req.body) {
try {
switch (req.body.action) {
case "enable":
await this.capability.enable(true);
break;
case "disable":
await this.capability.disable(false);
break;
default:
// noinspection ExceptionCaughtLocallyJS
throw new Error("Invalid action");
}

res.sendStatus(200);
} catch (e) {
Logger.warn("Error while configuring carpet mode setting", e);
res.status(500).json(e.message);
}
} else {
res.status(400).send("Missing parameters in request body");
}
});
}
}

module.exports = CarpetModeControlCapabilityRouter;
3 changes: 2 additions & 1 deletion lib/webserver/capabilityRouters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
SpeakerVolumeControlCapabilityRouter: require("./SpeakerVolumeControlCapabilityRouter"),
RawCommandCapabilityRouter: require("./RawCommandCapabilityRouter"),
MapSegmentationCapabilityRouter: require("./MapSegmentationCapabilityRouter"),
DoNotDisturbCapabilityRouter: require("./DoNotDisturbCapabilityRouter")
DoNotDisturbCapabilityRouter: require("./DoNotDisturbCapabilityRouter"),
CarpetModeControlCapabilityRouter: require("./CarpetModeControlCapabilityRouter")
};

0 comments on commit 54ca606

Please sign in to comment.