From 281ae99eb662834a3eeca7cc763354d731e0d6e6 Mon Sep 17 00:00:00 2001 From: slametps Date: Thu, 3 May 2018 00:09:54 +0700 Subject: [PATCH 1/6] add custom sound config to each alarm add custom sound config to each alarm --- MMM-AlarmClock.js | 24 ++++++++++++++++++------ README.md | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/MMM-AlarmClock.js b/MMM-AlarmClock.js index 13a056d..570b6ec 100644 --- a/MMM-AlarmClock.js +++ b/MMM-AlarmClock.js @@ -31,8 +31,7 @@ Module.register('MMM-AlarmClock', { getTranslations() { return { en: 'translations/en.json', - de: 'translations/de.json', - id: 'translations/id.json' + de: 'translations/de.json' }; }, @@ -55,6 +54,7 @@ Module.register('MMM-AlarmClock', { if (!this.config.touch) { alert.timer = this.config.timer; } + this.sendNotification('MMM-TTS', 'This is an AlarmClock event. Please stay tuned!'); // MMM-TTS integration this.sendNotification('SHOW_ALERT', alert); this.alarmFired = true; this.updateDom(300); @@ -124,6 +124,7 @@ Module.register('MMM-AlarmClock', { getDom() { const wrapper = document.createElement('div'); const header = document.createElement('header'); + //header.classList.add('align-right'); const logo = document.createElement('i'); logo.classList.add('fa', 'fa-bell-o', 'logo'); @@ -141,11 +142,22 @@ Module.register('MMM-AlarmClock', { wrapper.appendChild(text); } else if (this.alarmFired) { const sound = document.createElement('audio'); - if (this.config.sound.match(/^https?:\/\//)) { - sound.src = this.config.sound; - } else { - sound.src = this.file(`sounds/${this.config.sound}`); + srcSound = null; + if (this.next.sound) { + if (this.next.sound.match(/^https?:\/\//)) { + srcSound = this.next.sound; + } else { + srcSound = this.file(`sounds/${this.next.sound}`); + } + } + else { + if (this.config.sound.match(/^https?:\/\//)) { + srcSound = this.config.sound; + } else { + srcSound = this.file(`sounds/${this.config.sound}`); + } } + sound.src = srcSound; sound.volume = this.config.volume; sound.setAttribute('autoplay', true); sound.setAttribute('loop', true); diff --git a/README.md b/README.md index aba9f30..bb5fafa 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Alarm Clock Module for MagicMirror2 position: 'top_right', config: { alarms: [ - {time: "18:30", days: [2,4], title: "Soccer", message: "Get ready for soccer training!"}, + {time: "18:30", days: [2,4], title: "Soccer", message: "Get ready for soccer training!", sound: "alarm.mp3"}, ... ], ... @@ -33,7 +33,7 @@ Alarm Clock Module for MagicMirror2 | **Option** | **Default** | **Description** | | --- | --- | --- | -| `alarm` | `REQUIRED` | An Array with all your alarms as objects. Those objects need to have the properties -> time: 24h format, days: Array of all days the alarm should be fired (0 = Sunday, 6 = Saturday), title and message. | +| `alarms` | `REQUIRED` | An Array with all your alarms as objects. Those objects need to have the properties -> time: 24h format, days: Array of all days the alarm should be fired (0 = Sunday, 6 = Saturday), title, message, and sound. If sound is not defined, alarm will be fired with module defined/default alarm sound. | | `sound` | `'alarm.mp3'` | Name and extension of your alarm sound. File needs to be placed in `~/MagicMirror/modules/MMM-AlarmClock/sounds`. Standard files are `alarm.mp3` and `blackforest.mp3`. Alternatively specify a web stream `http` or `https`. | | `volume` | `1.0` | The volume of the alarm sound in a range from `0.0` to `1.0` | | `touch` | `false` | If you are using a touch screen device you need to press a button to disable an alarm.. | From 5d984f9922328fe113d469cae1b28cf6404e326c Mon Sep 17 00:00:00 2001 From: slametps Date: Thu, 3 May 2018 15:21:57 +0700 Subject: [PATCH 2/6] add custom sound config to an alarm add custom sound config to an alarm --- MMM-AlarmClock.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MMM-AlarmClock.js b/MMM-AlarmClock.js index af51950..4a87ded 100644 --- a/MMM-AlarmClock.js +++ b/MMM-AlarmClock.js @@ -267,11 +267,7 @@ Module.register('MMM-AlarmClock', { getDom() { const wrapper = document.createElement('div'); const header = document.createElement('header'); -<<<<<<< HEAD - //header.classList.add('align-right'); -======= header.classList.add('align-left'); ->>>>>>> origin/master const logo = document.createElement('i'); logo.classList.add('fa', 'fa-bell-o', 'logo'); @@ -289,7 +285,6 @@ Module.register('MMM-AlarmClock', { wrapper.appendChild(text); } else if (this.alarmFired) { const sound = document.createElement('audio'); -<<<<<<< HEAD srcSound = null; if (this.next.sound) { if (this.next.sound.match(/^https?:\/\//)) { From 28af0f6cc80447a0832eba77a1637404cd7d00e1 Mon Sep 17 00:00:00 2001 From: slametps Date: Fri, 4 May 2018 09:17:46 +0700 Subject: [PATCH 3/6] add custom sound option in alarm add custom sound option in alarm --- MMM-AlarmClock.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/MMM-AlarmClock.js b/MMM-AlarmClock.js index 4a87ded..7047d69 100644 --- a/MMM-AlarmClock.js +++ b/MMM-AlarmClock.js @@ -302,7 +302,6 @@ Module.register('MMM-AlarmClock', { } sound.src = srcSound; sound.volume = this.config.volume; -======= sound.setAttribute('id', 'MMM-AlarmClock-Player'); if (this.config.sound.match(/^https?:\/\//)) { sound.src = this.config.sound; @@ -310,7 +309,6 @@ Module.register('MMM-AlarmClock', { sound.src = this.file(`sounds/${this.config.sound}`); } sound.volume = this.config.fade ? 0 : this.config.volume; ->>>>>>> b5158cbf6071ab77c8f5f15e359c0046ea1fc4ff sound.setAttribute('autoplay', true); sound.setAttribute('loop', true); if (this.config.fade === true) { From 6b2c6cc3f4e6a800784997cc43cab257cebbc6df Mon Sep 17 00:00:00 2001 From: slametps Date: Fri, 4 May 2018 13:19:11 +0700 Subject: [PATCH 4/6] code refactor custom sound option for an alarm code refactor custom sound option for an alarm --- MMM-AlarmClock.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/MMM-AlarmClock.js b/MMM-AlarmClock.js index 7047d69..37ff0b4 100644 --- a/MMM-AlarmClock.js +++ b/MMM-AlarmClock.js @@ -144,7 +144,6 @@ Module.register('MMM-AlarmClock', { if (!this.config.touch) { alert.timer = this.config.timer; } - this.sendNotification('MMM-TTS', 'This is an AlarmClock event. Please stay tuned!'); // MMM-TTS integration this.sendNotification('SHOW_ALERT', alert); this.alarmFired = true; this.updateDom(300); @@ -285,20 +284,12 @@ Module.register('MMM-AlarmClock', { wrapper.appendChild(text); } else if (this.alarmFired) { const sound = document.createElement('audio'); - srcSound = null; + var srcSound = this.config.sound; if (this.next.sound) { - if (this.next.sound.match(/^https?:\/\//)) { - srcSound = this.next.sound; - } else { - srcSound = this.file(`sounds/${this.next.sound}`); - } + srcSound = this.next.sound; } - else { - if (this.config.sound.match(/^https?:\/\//)) { - srcSound = this.config.sound; - } else { - srcSound = this.file(`sounds/${this.config.sound}`); - } + if (!srcSound.match(/^https?:\/\//)) { + srcSound = this.file(`sounds/${srcSound}`); } sound.src = srcSound; sound.volume = this.config.volume; From 7938af76cbacffb2ad0bb486b8871965975c3c7d Mon Sep 17 00:00:00 2001 From: slametps Date: Fri, 4 May 2018 13:23:09 +0700 Subject: [PATCH 5/6] code refactor custom sound option for an alarm code refactor custom sound option for an alarm --- MMM-AlarmClock.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MMM-AlarmClock.js b/MMM-AlarmClock.js index 37ff0b4..164062d 100644 --- a/MMM-AlarmClock.js +++ b/MMM-AlarmClock.js @@ -284,12 +284,12 @@ Module.register('MMM-AlarmClock', { wrapper.appendChild(text); } else if (this.alarmFired) { const sound = document.createElement('audio'); - var srcSound = this.config.sound; + let srcSound = this.config.sound; if (this.next.sound) { - srcSound = this.next.sound; + srcSound = this.next.sound; } if (!srcSound.match(/^https?:\/\//)) { - srcSound = this.file(`sounds/${srcSound}`); + srcSound = this.file(`sounds/${srcSound}`); } sound.src = srcSound; sound.volume = this.config.volume; From 7b99ad071a2df0c12bc9ea402a6c8708bd691ebb Mon Sep 17 00:00:00 2001 From: slametps Date: Fri, 4 May 2018 21:09:48 +0700 Subject: [PATCH 6/6] code refactor custom sound option for an alarm code refactor custom sound option for an alarm --- MMM-AlarmClock.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MMM-AlarmClock.js b/MMM-AlarmClock.js index 164062d..16dfaa1 100644 --- a/MMM-AlarmClock.js +++ b/MMM-AlarmClock.js @@ -294,11 +294,6 @@ Module.register('MMM-AlarmClock', { sound.src = srcSound; sound.volume = this.config.volume; sound.setAttribute('id', 'MMM-AlarmClock-Player'); - if (this.config.sound.match(/^https?:\/\//)) { - sound.src = this.config.sound; - } else { - sound.src = this.file(`sounds/${this.config.sound}`); - } sound.volume = this.config.fade ? 0 : this.config.volume; sound.setAttribute('autoplay', true); sound.setAttribute('loop', true);