diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ea0e69..4340bef3 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 'disableNextEvent' to 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 14667d02..f5c7411d 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -25,7 +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, + 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 @@ -171,21 +171,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.showSunTimes !== "disableNextEvent") { + 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 00000000..5b5d0295 --- /dev/null +++ b/tests/configs/modules/clock/clock_showSunNoEvent.js @@ -0,0 +1,20 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + timeFormat: 12, + + modules: [ + { + module: "clock", + position: "middle_center", + config: { + showSunTimes: "disableNextEvent" + } + } + ] +}; + +/*************** 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 a5a6d2e0..9d9680e1 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");