-
-
Notifications
You must be signed in to change notification settings - Fork 408
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): Do not disturb capability (#659)
* Roborock/Capability Do Not Disturb Co-authored-by: bensweet86 <bensweet@outlook.com.au>
- Loading branch information
1 parent
fde2ffd
commit 4b3ed97
Showing
13 changed files
with
197 additions
and
42 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,30 @@ | ||
const Capability = require("./Capability"); | ||
const NotImplementedError = require("../NotImplementedError"); | ||
|
||
class DoNotDisturbCapability extends Capability { | ||
/** | ||
* | ||
* @abstract | ||
* @returns {Promise<import("../../entities/core/ValetudoDNDConfiguration")>} | ||
*/ | ||
async getDndConfiguration() { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
/** | ||
* @abstract | ||
* @param {import("../../entities/core/ValetudoDNDConfiguration")} dndConfig | ||
* @returns {Promise<void>} | ||
*/ | ||
async setDndConfiguration(dndConfig) { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
getType() { | ||
return DoNotDisturbCapability.TYPE; | ||
} | ||
} | ||
|
||
DoNotDisturbCapability.TYPE = "DoNotDisturbCapability"; | ||
|
||
module.exports = DoNotDisturbCapability; |
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,31 @@ | ||
const SerializableEntity = require("../SerializableEntity"); | ||
|
||
|
||
// noinspection JSCheckFunctionSignatures | ||
class ValetudoDNDConfiguration extends SerializableEntity { | ||
/** | ||
* @param {object} options | ||
* @param {boolean} options.enabled | ||
* | ||
* @param {object} options.start | ||
* @param {number} options.start.hour | ||
* @param {number} options.start.minute | ||
* | ||
* @param {object} options.end | ||
* @param {number} options.end.hour | ||
* @param {number} options.end.minute | ||
* | ||
* @param {object} [options.metaData] | ||
* | ||
* @class | ||
*/ | ||
constructor(options) { | ||
super(options); | ||
|
||
this.enabled = options.enabled; | ||
this.start = options.start; | ||
this.end = options.end; | ||
} | ||
} | ||
|
||
module.exports = ValetudoDNDConfiguration; |
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
45 changes: 45 additions & 0 deletions
45
lib/robots/roborock/capabilities/RoborockDoNotDisturbCapability.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,45 @@ | ||
const DoNotDisturbCapability = require("../../../core/capabilities/DoNotDisturbCapability"); | ||
const ValetudoDNDConfiguration = require("../../../entities/core/ValetudoDNDConfiguration"); | ||
|
||
class RoborockDoNotDisturbCapability extends DoNotDisturbCapability { | ||
/** | ||
* | ||
* @abstract | ||
* @returns {Promise<ValetudoDNDConfiguration>} | ||
*/ | ||
async getDndConfiguration() { | ||
const res = await this.robot.sendCommand("get_dnd_timer", [], {}); | ||
|
||
return new ValetudoDNDConfiguration({ | ||
enabled: (res[0].enabled === 1), | ||
start: { | ||
hour: res[0].start_hour, | ||
minute: res[0].start_minute | ||
}, | ||
end: { | ||
hour: res[0].end_hour, | ||
minute: res[0].end_minute | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @abstract | ||
* @param {ValetudoDNDConfiguration} dndConfig | ||
* @returns {Promise<void>} | ||
*/ | ||
async setDndConfiguration(dndConfig) { | ||
if (dndConfig.enabled === true) { | ||
return this.robot.sendCommand("set_dnd_timer", [ | ||
dndConfig.start.hour, | ||
dndConfig.start.minute, | ||
dndConfig.end.hour, | ||
dndConfig.end.minute | ||
], {}); | ||
} else { | ||
return this.robot.sendCommand("close_dnd_timer", [], {}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = RoborockDoNotDisturbCapability; |
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
30 changes: 30 additions & 0 deletions
30
lib/webserver/capabilityRouters/DoNotDisturbCapabilityRouter.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,30 @@ | ||
const Logger = require("../../Logger"); | ||
|
||
const CapabilityRouter = require("./CapabilityRouter"); | ||
const ValetudoDNDConfiguration = require("../../entities/core/ValetudoDNDConfiguration"); | ||
|
||
class DoNotDisturbCapabilityRouter extends CapabilityRouter { | ||
|
||
initRoutes() { | ||
this.router.get("/", async (req, res) => { | ||
res.json(await this.capability.getDndConfiguration()); | ||
}); | ||
|
||
this.router.put("/", async (req, res) => { | ||
if (req.body && req.body.start && req.body.end) { | ||
try { | ||
await this.capability.setDndConfiguration(new ValetudoDNDConfiguration(req.body)); | ||
|
||
res.sendStatus(200); | ||
} catch (e) { | ||
Logger.warn("Error while configuring do not disturb setting", e); | ||
res.status(500).json(e.message); | ||
} | ||
} else { | ||
res.status(400).send("Missing parameters in request body"); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = DoNotDisturbCapabilityRouter; |
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