widalarmeta: Move getNextAlarm

master
Erik Andresen 2023-02-26 09:28:45 +01:00
parent dd0f88245a
commit 3ca236d835
1 changed files with 13 additions and 13 deletions

View File

@ -6,11 +6,9 @@
showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute
}, require("Storage").readJSON("widalarmeta.json",1) || {});
function draw() {
if (this.nextAlarm === undefined) {
const getNextAlarm = (date) => {
function getNextAlarm(date) {
const alarms = (require("Storage").readJSON("sched.json",1) || []).filter(alarm => alarm.on && alarm.hidden !== true);
this.numActiveAlarms = alarms.length;
WIDGETS["widalarmeta"].numActiveAlarms = alarms.length;
const times = alarms.map(alarm => require("sched").getTimeToAlarm(alarm, date) || Number.POSITIVE_INFINITY);
const eta = times.length > 0 ? Math.min.apply(null, times) : 0;
if (eta !== Number.POSITIVE_INFINITY) {
@ -19,8 +17,10 @@
delete alarm.msg; delete alarm.id; delete alarm.data; // free some memory
return alarm;
}
}; // getNextAlarm
} // getNextAlarm
function draw() {
if (this.nextAlarm === undefined) {
let alarm = getNextAlarm();
if (alarm === undefined) {
// try again with next hour