From 9bab2c7869d1340daa93a3059ba3dfc67dd1092f Mon Sep 17 00:00:00 2001 From: Adam Cohen-Rose Date: Sun, 14 Feb 2021 20:31:56 +0000 Subject: [PATCH] feat: add weekday + shuffle config to alarm clock weekday config courtesy of SimonMellerin https://github.com/volumio/Volumio2/pull/1640 --- app/i18n/strings_en.json | 13 ++- .../miscellanea/alarm-clock/UIConfig.json | 88 ++++++++++++++++++- .../miscellanea/alarm-clock/config.json | 8 ++ app/plugins/miscellanea/alarm-clock/index.js | 56 +++++++++++- 4 files changed, 159 insertions(+), 6 deletions(-) diff --git a/app/i18n/strings_en.json b/app/i18n/strings_en.json index a6b2c0da0..9642a9e4c 100644 --- a/app/i18n/strings_en.json +++ b/app/i18n/strings_en.json @@ -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", diff --git a/app/plugins/miscellanea/alarm-clock/UIConfig.json b/app/plugins/miscellanea/alarm-clock/UIConfig.json index 467e98987..e725ac027 100755 --- a/app/plugins/miscellanea/alarm-clock/UIConfig.json +++ b/app/plugins/miscellanea/alarm-clock/UIConfig.json @@ -13,8 +13,16 @@ "label": "Save", "data": [ "enabled", + "shuffle", "hour", - "minute" + "minute", + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + "sunday" ] }, "content": [ @@ -24,6 +32,12 @@ "label": "Enable", "value": true }, + { + "id": "shuffle", + "element": "switch", + "label": "TRANSLATE.ALARM.SHUFFLE", + "value": true + }, { "id": "hour", "element": "select", @@ -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 + } } ] } ] -} \ No newline at end of file +} diff --git a/app/plugins/miscellanea/alarm-clock/config.json b/app/plugins/miscellanea/alarm-clock/config.json index 132a63122..832912e51 100755 --- a/app/plugins/miscellanea/alarm-clock/config.json +++ b/app/plugins/miscellanea/alarm-clock/config.json @@ -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"}, diff --git a/app/plugins/miscellanea/alarm-clock/index.js b/app/plugins/miscellanea/alarm-clock/index.js index 4e30b5f29..d83e69342 100755 --- a/app/plugins/miscellanea/alarm-clock/index.js +++ b/app/plugins/miscellanea/alarm-clock/index.js @@ -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; }; @@ -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); }; @@ -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); @@ -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')); } }