Skip to content

Commit

Permalink
feat: add weekday + shuffle config to alarm clock
Browse files Browse the repository at this point in the history
weekday config courtesy of SimonMellerin
volumio#1640
  • Loading branch information
Adam Cohen-Rose committed Feb 14, 2021
1 parent 4c35e51 commit 9bab2c7
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 6 deletions.
13 changes: 11 additions & 2 deletions app/i18n/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
"SLEEP_MODE_SYSTEM_WILL": "The system will",
"SLEEP_MODE_TITLE": "Sleep Mode",
"STOP_MUSIC": "Stop Music",
"TIME_SELECT_ERROR": "Please select an alarm start time",
"TURN_OFF": "Turn off"
"TURN_OFF": "Turn off",
"TIME_SELECT_ERROR":"Please select an alarm start time",
"DAY_SELECT_ERROR":"Please select at least one day of week",
"SHUFFLE":"Shuffle",
"MONDAY":"Monday",
"TUESDAY":"Tuesday",
"WEDNESDAY":"Wednesday",
"THURSDAY":"Thursday",
"FRIDAY":"Friday",
"SATURDAY":"Saturday",
"SUNDAY":"Sunday"
},
"APPEARANCE": {
"ALBUMARTIST": "Albumartist",
Expand Down
88 changes: 86 additions & 2 deletions app/plugins/miscellanea/alarm-clock/UIConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
"label": "Save",
"data": [
"enabled",
"shuffle",
"hour",
"minute"
"minute",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday"
]
},
"content": [
Expand All @@ -24,6 +32,12 @@
"label": "Enable",
"value": true
},
{
"id": "shuffle",
"element": "switch",
"label": "TRANSLATE.ALARM.SHUFFLE",
"value": true
},
{
"id": "hour",
"element": "select",
Expand Down Expand Up @@ -392,8 +406,78 @@
"value": true
}

},
{
"id": "monday",
"element": "switch",
"label": "TRANSLATE.ALARM.MONDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
},
{
"id": "tuesday",
"element": "switch",
"label": "TRANSLATE.ALARM.TUESDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
},
{
"id": "wednesday",
"element": "switch",
"label": "TRANSLATE.ALARM.WEDNESDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
},
{
"id": "thursday",
"element": "switch",
"label": "TRANSLATE.ALARM.THURSDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
},
{
"id": "friday",
"element": "switch",
"label": "TRANSLATE.ALARM.FRIDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
},
{
"id": "saturday",
"element": "switch",
"label": "TRANSLATE.ALARM.SATURDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
},
{
"id": "sunday",
"element": "switch",
"label": "TRANSLATE.ALARM.SUNDAY",
"value": true,
"visibleIf": {
"field": "enabled",
"value": true
}
}
]
}
]
}
}
8 changes: 8 additions & 0 deletions app/plugins/miscellanea/alarm-clock/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"enabled":{"value":true,"type":"boolean"},
"shuffle":{"value":true,"type":"boolean"},
"hour":{"value":"8","type":"number"},
"minute":{"value":"0","type":"number"},
"monday":{"value":true,"type":"boolean"},
"tuesday":{"value":true,"type":"boolean"},
"wednesday":{"value":true,"type":"boolean"},
"thursday":{"value":true,"type":"boolean"},
"friday":{"value":true,"type":"boolean"},
"saturday":{"value":true,"type":"boolean"},
"sunday":{"value":true,"type":"boolean"},
"sleep_enabled":{"type":"boolean","value":false},
"sleep_hour":{"value":"0","type":"number"},
"sleep_minute":{"value":"0","type":"number"},
Expand Down
56 changes: 54 additions & 2 deletions app/plugins/miscellanea/alarm-clock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,35 @@ AlarmClock.prototype.getUIConfig = function () {
// enable
uiconf.sections[0].content[0].value = config.get('enabled');

// shuffle
uiconf.sections[0].content[1].value = config.get('shuffle');

// hour
uiconf.sections[0].content[1].value.value = config.get('hour');
uiconf.sections[0].content[2].value.value = config.get('hour');

// minute
uiconf.sections[0].content[2].value.value = config.get('minute');
uiconf.sections[0].content[3].value.value = config.get('minute');

//monday
uiconf.sections[0].content[4].value.value=config.get('monday');

//tuesday
uiconf.sections[0].content[5].value.value=config.get('tuesday');

//wednesday
uiconf.sections[0].content[6].value.value=config.get('wednesday');

//thursday
uiconf.sections[0].content[7].value.value=config.get('thursday');

//friday
uiconf.sections[0].content[8].value.value=config.get('friday');

//saturday
uiconf.sections[0].content[9].value.value=config.get('saturday');

//sunday
uiconf.sections[0].content[10].value.value=config.get('sunday');

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

self.logger.info('Starting Scheduled Playlist ' + alarm.playlist);
if (alarm.shuffle) {
self.commandRouter.setRandom({"value": true})
}
self.commandRouter.playPlaylist(alarm.playlist);
};

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

var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [];
if (item.monday) {
rule.dayOfWeek.push(1);
}
if (item.tuesday) {
rule.dayOfWeek.push(2);
}
if (item.wednesday) {
rule.dayOfWeek.push(3);
}
if (item.thursday) {
rule.dayOfWeek.push(4);
}
if (item.friday) {
rule.dayOfWeek.push(5);
}
if (item.saturday) {
rule.dayOfWeek.push(6);
}
if (item.sunday) {
rule.dayOfWeek.push(7);
}
rule.minute = d.getMinutes();
rule.hour = d.getHours();
let currentItem = Object.assign({}, item);
Expand Down Expand Up @@ -196,6 +245,9 @@ AlarmClock.prototype.saveAlarm = function (data) {
} else if (!data[i].playlist) {
var error = true;
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('ALARM.ALARM_CLOCK_TITLE'), self.commandRouter.getI18nString('ALARM.PLAYLIST_SELECT_ERROR'));
} else if (!data[i].monday && !data[i].tuesday && !data[i].wednesday && !data[i].thursday && !data[i].friday && !data[i].saturday && !data[i].sunday) {
var error = true;
self.commandRouter.pushToastMessage('error', self.commandRouter.getI18nString('ALARM.ALARM_CLOCK_TITLE'), self.commandRouter.getI18nString('ALARM.DAY_SELECT_ERROR'));
}
}

Expand Down

0 comments on commit 9bab2c7

Please sign in to comment.