Skip to content

Commit

Permalink
feat: Timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed May 16, 2021
1 parent fd79163 commit 7b8c37a
Show file tree
Hide file tree
Showing 25 changed files with 432 additions and 222 deletions.
6 changes: 3 additions & 3 deletions client/settings-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ async function updateDndTimerPage() {
const dndTime = {
start: convertTime(res.start.hour, res.start.minute, offset),
end: convertTime(res.end.hour, res.end.minute, offset)
}
};

dndTimerList.appendChild(ons.createElement(
"<ons-list-item>\n" +
" <div class='left'>DND will start at " + dndTime.start.hour + ":" +
Expand Down Expand Up @@ -188,7 +188,7 @@ async function saveDndTimer() {
const dndTime = {
start: convertTime(parseInt(start_hour), parseInt(start_minute), offset),
end: convertTime(parseInt(end_hour), parseInt(end_minute), offset)
}
};

try {
await ApiService.setDndConfiguration(
Expand Down
1 change: 0 additions & 1 deletion lib/NTPClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class NTPClient {
* @param {object} options
* @param {import("./Configuration")} options.config
*/

constructor(options) {
this.config = options.config;

Expand Down
8 changes: 8 additions & 0 deletions lib/Valetudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Tools = require("./Tools");
const v8 = require("v8");
const Webserver = require("./webserver/WebServer");

const Scheduler = require("./scheduler/Scheduler");
const ValetudoRobotFactory = require("./core/ValetudoRobotFactory");

class Valetudo {
Expand Down Expand Up @@ -63,6 +64,12 @@ class Valetudo {
robot: this.robot
});

this.scheduler = new Scheduler({
config: this.config,
robot: this.robot,
ntpClient: this.ntpClient
});


//This might get refactored if there are more of these options
if (this.config.get("debug") && typeof this.config.get("debug").memoryStatInterval === "number") {
Expand Down Expand Up @@ -129,6 +136,7 @@ class Valetudo {
}, 5000);

// shuts down valetudo (reverse startup sequence):
await this.scheduler.shutdown();
if (this.mqttClient) {
await this.mqttClient.shutdown();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/core/ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ValetudoRobot {
}
}

/**
* @public
* @param {string} capabilityType
* @returns {boolean}
*/
hasCapability(capabilityType) {
return this.capabilities[capabilityType] !== undefined;
}
Expand Down
49 changes: 49 additions & 0 deletions lib/entities/core/ValetudoTimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const SerializableEntity = require("../SerializableEntity");
const uuid = require("uuid");


class ValetudoTimer extends SerializableEntity {
/**
* Timers are always in UTC
*
* @param {object} options
* @param {string} [options.id] uuidv4
* @param {boolean} options.enabled
* @param {Array<number>} options.dow Sunday = 0 because js
* @param {number} options.hour 0-23
* @param {number} options.minute 0-59
* @param {object} options.action
* @param {ValetudoTimerActionType} options.action.type
* @param {object} options.action.params
* @param {string} [options.action.params.zone_id]
* @param {Array<number>} [options.action.params.segment_ids]
* @param {number} [options.action.params.iterations]
* @param {boolean} [options.action.params.custom_order]
* @param {object} [options.metaData]
* @class
*/
constructor(options) {
super(options);

this.id = options.id ?? uuid.v4();
this.enabled = options.enabled;
this.dow = options.dow;
this.hour = options.hour;
this.minute = options.minute;
this.action = options.action;
}
}

/**
* @typedef {string} ValetudoTimerActionType
* @enum {string}
*
*/
ValetudoTimer.ACTION_TYPE = Object.freeze({
FULL_CLEANUP: "full_cleanup",
ZONE_CLEANUP: "zone_cleanup",
SEGMENT_CLEANUP: "segment_cleanup"
});


module.exports = ValetudoTimer;
1 change: 1 addition & 0 deletions lib/entities/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
ValetudoRestrictedZone: require("./ValetudoRestrictedZone"),
ValetudoSelectionPreset: require("./ValetudoSelectionPreset"),
ValetudoSensor: require("./ValetudoSensor"),
ValetudoTimer: require("./ValetudoTimer"),
ValetudoVirtualRestrictions: require("./ValetudoVirtualRestrictions"),
ValetudoVirtualWall: require("./ValetudoVirtualWall"),
ValetudoVoicePackOperationStatus: require("./ValetudoVoicePackOperationStatus"),
Expand Down
1 change: 0 additions & 1 deletion lib/entities/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
SerializableEntity: require("./SerializableEntity"),
core: require("./core"),
job: require("./job"),
map: require("./map"),
state: require("./state")
};
68 changes: 0 additions & 68 deletions lib/entities/job/Job.js

This file was deleted.

26 changes: 0 additions & 26 deletions lib/entities/job/attributes/CronTimerJobAttribute.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/entities/job/attributes/ErrorJobAttribute.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/entities/job/attributes/HistoryJobAttribute.js

This file was deleted.

8 changes: 0 additions & 8 deletions lib/entities/job/attributes/JobAttribute.js

This file was deleted.

29 changes: 0 additions & 29 deletions lib/entities/job/attributes/StatisticsJobAttribute.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/entities/job/attributes/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions lib/entities/job/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/miio/MiioSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class MiioSocket {
clearTimeout(pending.timeout_id);

if (msg["error"]) {
Logger.info("error response", msg);
Logger.info("Miio error response", msg);
pending.reject(msg["error"]);
} else {
pending.resolve(msg["result"]);
Expand Down
1 change: 1 addition & 0 deletions lib/res/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"interval": 28800000,
"timeout": 10000
},
"timers": {},
"allowSSHKeyUpload": true,
"logLevel": "info",
"debug": {
Expand Down
Loading

0 comments on commit 7b8c37a

Please sign in to comment.