-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblinds_scheduler.js
More file actions
29 lines (23 loc) · 899 Bytes
/
Copy pathblinds_scheduler.js
File metadata and controls
29 lines (23 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const cron = require('node-cron');
class BlindsScheduler {
constructor(blinds) {
this.blinds = blinds;
}
scheduleBlindsOpen(hour, minute) {
console.log(`Scheduling blinds to open at
${this.getTimeFormattedString(hour)}:${this.getTimeFormattedString(minute)}`);
this.scheduleCallback(hour, minute, () => this.blinds.moveUpToEnd());
}
scheduleBlindsClose(hour, minute) {
console.log(`Scheduling blinds to close at
${this.getTimeFormattedString(hour)}:${this.getTimeFormattedString(minute)}`);
this.scheduleCallback(hour, minute, () => this.blinds.moveDownToEnd());
}
scheduleCallback(hour, minute, callback) {
cron.schedule(`${minute} ${hour} * * *`, callback)
}
getTimeFormattedString(number) {
return String(number).padStart(2, '0');
}
}
module.exports = BlindsScheduler;