Skip to content

Commit 9bab2c7

Browse files
committed
feat: add weekday + shuffle config to alarm clock
weekday config courtesy of SimonMellerin volumio#1640
1 parent 4c35e51 commit 9bab2c7

File tree

4 files changed

+159
-6
lines changed

4 files changed

+159
-6
lines changed

app/i18n/strings_en.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@
99
"SLEEP_MODE_SYSTEM_WILL": "The system will",
1010
"SLEEP_MODE_TITLE": "Sleep Mode",
1111
"STOP_MUSIC": "Stop Music",
12-
"TIME_SELECT_ERROR": "Please select an alarm start time",
13-
"TURN_OFF": "Turn off"
12+
"TURN_OFF": "Turn off",
13+
"TIME_SELECT_ERROR":"Please select an alarm start time",
14+
"DAY_SELECT_ERROR":"Please select at least one day of week",
15+
"SHUFFLE":"Shuffle",
16+
"MONDAY":"Monday",
17+
"TUESDAY":"Tuesday",
18+
"WEDNESDAY":"Wednesday",
19+
"THURSDAY":"Thursday",
20+
"FRIDAY":"Friday",
21+
"SATURDAY":"Saturday",
22+
"SUNDAY":"Sunday"
1423
},
1524
"APPEARANCE": {
1625
"ALBUMARTIST": "Albumartist",

app/plugins/miscellanea/alarm-clock/UIConfig.json

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
"label": "Save",
1414
"data": [
1515
"enabled",
16+
"shuffle",
1617
"hour",
17-
"minute"
18+
"minute",
19+
"monday",
20+
"tuesday",
21+
"wednesday",
22+
"thursday",
23+
"friday",
24+
"saturday",
25+
"sunday"
1826
]
1927
},
2028
"content": [
@@ -24,6 +32,12 @@
2432
"label": "Enable",
2533
"value": true
2634
},
35+
{
36+
"id": "shuffle",
37+
"element": "switch",
38+
"label": "TRANSLATE.ALARM.SHUFFLE",
39+
"value": true
40+
},
2741
{
2842
"id": "hour",
2943
"element": "select",
@@ -392,8 +406,78 @@
392406
"value": true
393407
}
394408

409+
},
410+
{
411+
"id": "monday",
412+
"element": "switch",
413+
"label": "TRANSLATE.ALARM.MONDAY",
414+
"value": true,
415+
"visibleIf": {
416+
"field": "enabled",
417+
"value": true
418+
}
419+
},
420+
{
421+
"id": "tuesday",
422+
"element": "switch",
423+
"label": "TRANSLATE.ALARM.TUESDAY",
424+
"value": true,
425+
"visibleIf": {
426+
"field": "enabled",
427+
"value": true
428+
}
429+
},
430+
{
431+
"id": "wednesday",
432+
"element": "switch",
433+
"label": "TRANSLATE.ALARM.WEDNESDAY",
434+
"value": true,
435+
"visibleIf": {
436+
"field": "enabled",
437+
"value": true
438+
}
439+
},
440+
{
441+
"id": "thursday",
442+
"element": "switch",
443+
"label": "TRANSLATE.ALARM.THURSDAY",
444+
"value": true,
445+
"visibleIf": {
446+
"field": "enabled",
447+
"value": true
448+
}
449+
},
450+
{
451+
"id": "friday",
452+
"element": "switch",
453+
"label": "TRANSLATE.ALARM.FRIDAY",
454+
"value": true,
455+
"visibleIf": {
456+
"field": "enabled",
457+
"value": true
458+
}
459+
},
460+
{
461+
"id": "saturday",
462+
"element": "switch",
463+
"label": "TRANSLATE.ALARM.SATURDAY",
464+
"value": true,
465+
"visibleIf": {
466+
"field": "enabled",
467+
"value": true
468+
}
469+
},
470+
{
471+
"id": "sunday",
472+
"element": "switch",
473+
"label": "TRANSLATE.ALARM.SUNDAY",
474+
"value": true,
475+
"visibleIf": {
476+
"field": "enabled",
477+
"value": true
478+
}
395479
}
396480
]
397481
}
398482
]
399-
}
483+
}

app/plugins/miscellanea/alarm-clock/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
22
"enabled":{"value":true,"type":"boolean"},
3+
"shuffle":{"value":true,"type":"boolean"},
34
"hour":{"value":"8","type":"number"},
45
"minute":{"value":"0","type":"number"},
6+
"monday":{"value":true,"type":"boolean"},
7+
"tuesday":{"value":true,"type":"boolean"},
8+
"wednesday":{"value":true,"type":"boolean"},
9+
"thursday":{"value":true,"type":"boolean"},
10+
"friday":{"value":true,"type":"boolean"},
11+
"saturday":{"value":true,"type":"boolean"},
12+
"sunday":{"value":true,"type":"boolean"},
513
"sleep_enabled":{"type":"boolean","value":false},
614
"sleep_hour":{"value":"0","type":"number"},
715
"sleep_minute":{"value":"0","type":"number"},

app/plugins/miscellanea/alarm-clock/index.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,35 @@ AlarmClock.prototype.getUIConfig = function () {
6969
// enable
7070
uiconf.sections[0].content[0].value = config.get('enabled');
7171

72+
// shuffle
73+
uiconf.sections[0].content[1].value = config.get('shuffle');
74+
7275
// hour
73-
uiconf.sections[0].content[1].value.value = config.get('hour');
76+
uiconf.sections[0].content[2].value.value = config.get('hour');
7477

7578
// minute
76-
uiconf.sections[0].content[2].value.value = config.get('minute');
79+
uiconf.sections[0].content[3].value.value = config.get('minute');
80+
81+
//monday
82+
uiconf.sections[0].content[4].value.value=config.get('monday');
83+
84+
//tuesday
85+
uiconf.sections[0].content[5].value.value=config.get('tuesday');
86+
87+
//wednesday
88+
uiconf.sections[0].content[6].value.value=config.get('wednesday');
89+
90+
//thursday
91+
uiconf.sections[0].content[7].value.value=config.get('thursday');
92+
93+
//friday
94+
uiconf.sections[0].content[8].value.value=config.get('friday');
95+
96+
//saturday
97+
uiconf.sections[0].content[9].value.value=config.get('saturday');
98+
99+
//sunday
100+
uiconf.sections[0].content[10].value.value=config.get('sunday');
77101

78102
return uiconf;
79103
};
@@ -98,6 +122,9 @@ AlarmClock.prototype.fireAlarm = function (alarm) {
98122
var self = this;
99123

100124
self.logger.info('Starting Scheduled Playlist ' + alarm.playlist);
125+
if (alarm.shuffle) {
126+
self.commandRouter.setRandom({"value": true})
127+
}
101128
self.commandRouter.playPlaylist(alarm.playlist);
102129
};
103130

@@ -121,6 +148,28 @@ AlarmClock.prototype.applyConf = function (conf) {
121148

122149
var schedule = require('node-schedule');
123150
var rule = new schedule.RecurrenceRule();
151+
rule.dayOfWeek = [];
152+
if (item.monday) {
153+
rule.dayOfWeek.push(1);
154+
}
155+
if (item.tuesday) {
156+
rule.dayOfWeek.push(2);
157+
}
158+
if (item.wednesday) {
159+
rule.dayOfWeek.push(3);
160+
}
161+
if (item.thursday) {
162+
rule.dayOfWeek.push(4);
163+
}
164+
if (item.friday) {
165+
rule.dayOfWeek.push(5);
166+
}
167+
if (item.saturday) {
168+
rule.dayOfWeek.push(6);
169+
}
170+
if (item.sunday) {
171+
rule.dayOfWeek.push(7);
172+
}
124173
rule.minute = d.getMinutes();
125174
rule.hour = d.getHours();
126175
let currentItem = Object.assign({}, item);
@@ -196,6 +245,9 @@ AlarmClock.prototype.saveAlarm = function (data) {
196245
} else if (!data[i].playlist) {
197246
var error = true;
198247
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('ALARM.ALARM_CLOCK_TITLE'), self.commandRouter.getI18nString('ALARM.PLAYLIST_SELECT_ERROR'));
248+
} else if (!data[i].monday && !data[i].tuesday && !data[i].wednesday && !data[i].thursday && !data[i].friday && !data[i].saturday && !data[i].sunday) {
249+
var error = true;
250+
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('ALARM.ALARM_CLOCK_TITLE'), self.commandRouter.getI18nString('ALARM.DAY_SELECT_ERROR'));
199251
}
200252
}
201253

0 commit comments

Comments
 (0)