-
-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vendor.roborock): Roborock/Capability Carpet Mode (#661)
* 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
1 parent
3c0a644
commit 54ca606
Showing
12 changed files
with
158 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
lib/robots/roborock/capabilities/RoborockCarpetModeControlCapability.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/webserver/capabilityRouters/CarpetModeControlCapabilityRouter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters