From 8d20af5cee0e279b0f811c6bd8daf4f47209261c Mon Sep 17 00:00:00 2001 From: BugHaver <43462320+lsaadeh@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:15:06 +1000 Subject: [PATCH 1/2] Update clock.js --- CHANGELOG.md | 4 +++ modules/default/clock/clock.js | 36 +++++++++++-------- .../modules/clock/clock_showSunNoEvent.js | 21 +++++++++++ tests/e2e/modules/clock_spec.js | 18 ++++++++++ 4 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 tests/configs/modules/clock/clock_showSunNoEvent.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ea0e697a..ee0195de25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 planned for 2025-07-01 +### Added + +- [clock] Added option showSunNextEvent to show/hide next sun event. + ### Changed - [refactor] Simplify module loading process diff --git a/modules/default/clock/clock.js b/modules/default/clock/clock.js index 14667d0227..727b464e6d 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -26,6 +26,7 @@ Module.register("clock", { secondsColor: "#888888", // DEPRECATED, use CSS instead. Class "clock-second-digital" for digital clock, "clock-second" for analog clock. showSunTimes: false, + showSunNextEvent: true, showMoonTimes: false, // options: false, 'times' (rise/set), 'percent' (lit percent), 'phase' (current phase), or 'both' (percent & phase) lat: 47.630539, lon: -122.344147 @@ -171,21 +172,28 @@ Module.register("clock", { if (this.config.showSunTimes) { const sunTimes = SunCalc.getTimes(now, this.config.lat, this.config.lon); const isVisible = now.isBetween(sunTimes.sunrise, sunTimes.sunset); - let nextEvent; - if (now.isBefore(sunTimes.sunrise)) { - nextEvent = sunTimes.sunrise; - } else if (now.isBefore(sunTimes.sunset)) { - nextEvent = sunTimes.sunset; - } else { - const tomorrowSunTimes = SunCalc.getTimes(now.clone().add(1, "day"), this.config.lat, this.config.lon); - nextEvent = tomorrowSunTimes.sunrise; + let sunWrapperInnerHTML = ""; + + if (this.config.showSunNextEvent) { + let nextEvent; + if (now.isBefore(sunTimes.sunrise)) { + nextEvent = sunTimes.sunrise; + } else if (now.isBefore(sunTimes.sunset)) { + nextEvent = sunTimes.sunset; + } else { + const tomorrowSunTimes = SunCalc.getTimes(now.clone().add(1, "day"), this.config.lat, this.config.lon); + nextEvent = tomorrowSunTimes.sunrise; + } + const untilNextEvent = moment.duration(moment(nextEvent).diff(now)); + const untilNextEventString = `${untilNextEvent.hours()}h ${untilNextEvent.minutes()}m`; + + sunWrapperInnerHTML = ` ${untilNextEventString}`; } - const untilNextEvent = moment.duration(moment(nextEvent).diff(now)); - const untilNextEventString = `${untilNextEvent.hours()}h ${untilNextEvent.minutes()}m`; - sunWrapper.innerHTML - = ` ${untilNextEventString}` - + ` ${formatTime(this.config, sunTimes.sunrise)}` - + ` ${formatTime(this.config, sunTimes.sunset)}`; + + sunWrapperInnerHTML += ` ${formatTime(this.config, sunTimes.sunrise)}` + + ` ${formatTime(this.config, sunTimes.sunset)}`; + + sunWrapper.innerHTML = sunWrapperInnerHTML; digitalWrapper.appendChild(sunWrapper); } diff --git a/tests/configs/modules/clock/clock_showSunNoEvent.js b/tests/configs/modules/clock/clock_showSunNoEvent.js new file mode 100644 index 0000000000..d2eef8c308 --- /dev/null +++ b/tests/configs/modules/clock/clock_showSunNoEvent.js @@ -0,0 +1,21 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + timeFormat: 12, + + modules: [ + { + module: "clock", + position: "middle_center", + config: { + showSunTimes: true, + showSunNextEvent: false + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index a5a6d2e0ca..9d9680e1c4 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -92,6 +92,9 @@ describe("Clock module", () => { it("should show the sun times", async () => { const elem = await helpers.waitForElement(".clock .digital .sun"); expect(elem).not.toBeNull(); + + const elem2 = await helpers.waitForElement(".clock .digital .sun .fas.fa-sun"); + expect(elem2).not.toBeNull(); }); it("should show the moon times", async () => { @@ -100,6 +103,21 @@ describe("Clock module", () => { }); }); + describe("with showSunNextEvent disabled", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/clock/clock_showSunNoEvent.js"); + await helpers.getDocument(); + }); + + it("should show the sun times", async () => { + const elem = await helpers.waitForElement(".clock .digital .sun"); + expect(elem).not.toBeNull(); + + const elem2 = document.querySelector(".clock .digital .sun .fas.fa-sun"); + expect(elem2).toBeNull(); + }); + }); + describe("with showWeek config enabled", () => { beforeAll(async () => { await helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js"); From b7eaa6f8d718cbef80ea70e1b70a4426a22e5133 Mon Sep 17 00:00:00 2001 From: BugHaver <43462320+bughaver@users.noreply.github.com> Date: Sun, 27 Apr 2025 16:45:39 +1000 Subject: [PATCH 2/2] single variable for showSunTimes sub options --- CHANGELOG.md | 2 +- modules/default/clock/clock.js | 5 ++--- tests/configs/modules/clock/clock_showSunNoEvent.js | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee0195de25..4340bef331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ planned for 2025-07-01 ### Added -- [clock] Added option showSunNextEvent to show/hide next sun event. +- [clock] Added option 'disableNextEvent' to hide next sun event. ### Changed diff --git a/modules/default/clock/clock.js b/modules/default/clock/clock.js index 727b464e6d..f5c7411d23 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -25,8 +25,7 @@ Module.register("clock", { analogShowDate: "top", // OBSOLETE, can be replaced with analogPlacement and showTime, options: false, 'top', or 'bottom' secondsColor: "#888888", // DEPRECATED, use CSS instead. Class "clock-second-digital" for digital clock, "clock-second" for analog clock. - showSunTimes: false, - showSunNextEvent: true, + showSunTimes: false, // options: true, false, 'disableNextEvent' showMoonTimes: false, // options: false, 'times' (rise/set), 'percent' (lit percent), 'phase' (current phase), or 'both' (percent & phase) lat: 47.630539, lon: -122.344147 @@ -174,7 +173,7 @@ Module.register("clock", { const isVisible = now.isBetween(sunTimes.sunrise, sunTimes.sunset); let sunWrapperInnerHTML = ""; - if (this.config.showSunNextEvent) { + if (this.config.showSunTimes !== "disableNextEvent") { let nextEvent; if (now.isBefore(sunTimes.sunrise)) { nextEvent = sunTimes.sunrise; diff --git a/tests/configs/modules/clock/clock_showSunNoEvent.js b/tests/configs/modules/clock/clock_showSunNoEvent.js index d2eef8c308..5b5d029544 100644 --- a/tests/configs/modules/clock/clock_showSunNoEvent.js +++ b/tests/configs/modules/clock/clock_showSunNoEvent.js @@ -8,8 +8,7 @@ let config = { module: "clock", position: "middle_center", config: { - showSunTimes: true, - showSunNextEvent: false + showSunTimes: "disableNextEvent" } } ]