Skip to content

Commit

Permalink
feat(timers): add ValetudoGoToTimerAction (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
DennaGherlyn committed May 27, 2021
1 parent 6b35e4d commit d8a523e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backend/lib/entities/core/ValetudoTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ValetudoTimer extends SerializableEntity {
* @param {object} options.action.params
* @param {string} [options.action.params.zone_id]
* @param {Array<number>} [options.action.params.segment_ids]
* @param {string} [options.action.params.goto_id]
* @param {number} [options.action.params.iterations]
* @param {boolean} [options.action.params.custom_order]
* @param {object} [options.metaData]
Expand All @@ -42,7 +43,8 @@ class ValetudoTimer extends SerializableEntity {
ValetudoTimer.ACTION_TYPE = Object.freeze({
FULL_CLEANUP: "full_cleanup",
ZONE_CLEANUP: "zone_cleanup",
SEGMENT_CLEANUP: "segment_cleanup"
SEGMENT_CLEANUP: "segment_cleanup",
GOTO_LOCATION: "goto_location"
});


Expand Down
7 changes: 7 additions & 0 deletions backend/lib/scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ValetudoNTPClientSyncedState = require("../entities/core/ntpClient/Valetud
const ValetudoSegmentCleanupTimerAction = require("./actions/ValetudoSegmentCleanupTimerAction");
const ValetudoTimer = require("../entities/core/ValetudoTimer");
const ValetudoZoneCleanupTimerAction = require("./actions/ValetudoZoneCleanupTimerAction");
const ValetudoGoToTimerAction = require("./actions/ValetudoGoToTimerAction");

class Scheduler {
/**
Expand Down Expand Up @@ -84,6 +85,12 @@ class Scheduler {
customOrder: timerDefinition.action?.params?.custom_order
});
break;
case ValetudoTimer.ACTION_TYPE.GOTO_LOCATION:
action = new ValetudoGoToTimerAction({
robot: this.robot,
goToId: timerDefinition.action?.params?.goto_id
});
break;
}

if (action) {
Expand Down
36 changes: 36 additions & 0 deletions backend/lib/scheduler/actions/ValetudoGoToTimerAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const ValetudoTimerAction = require("./ValetudoTimerAction");
const GoToLocationCapability = require("../../core/capabilities/GoToLocationCapability");

class ValetudoGoToTimerAction extends ValetudoTimerAction {
/**
* @param {object} options
* @param {import("../../core/ValetudoRobot")} options.robot
* @param {string} options.goToId
*/
constructor(options) {
super(options);

this.goToId = options.goToId;
}

async run() {
if (!this.goToId) {
throw new Error("Missing goToId");
}

if (!this.robot.hasCapability(GoToLocationCapability.TYPE)) {
throw new Error("Robot is missing the GoToLocationCapability");
} else {
const capability = this.robot.capabilities[GoToLocationCapability.TYPE];
const goToLocationPreset = this.robot.config.get("goToLocationPresets")[this.goToId];

if (goToLocationPreset) {
return capability.goTo(goToLocationPreset);
} else {
throw new Error("There is no go to location preset with id " + this.goToId);
}
}
}
}

module.exports = ValetudoGoToTimerAction;

0 comments on commit d8a523e

Please sign in to comment.