Skip to content

Commit

Permalink
Verbose log messages for astro
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Feb 23, 2024
1 parent 7752c2a commit 879b28f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,7 @@ function sandBox(script, name, verbose, debug, context) {
}

// ensure events are calculated independent of current time
// TODO: use getAstroStartOfDay of adapter?
const todayNoon = new Date(nowdate);
todayNoon.setHours(12, 0, 0, 0);
let ts = mods.suncalc.getTimes(todayNoon, adapter.config.latitude, adapter.config.longitude)[pattern.astro];
Expand All @@ -1658,12 +1659,12 @@ function sandBox(script, name, verbose, debug, context) {
pattern.astro === 'nightEnd' ||
pattern.astro === 'nauticalDusk'
) {
ts.setMinutes(59);
ts.setHours(23);
ts.setMinutes(59);
ts.setSeconds(59);
} else {
ts.setMinutes(59);
ts.setHours(23);
ts.setMinutes(59);
ts.setSeconds(58);
}
}
Expand All @@ -1688,13 +1689,15 @@ function sandBox(script, name, verbose, debug, context) {
sandbox.log(`More than ${sandbox.__engine.__schedules} schedules registered. Check your script!`, 'warn');
}

sandbox.verbose && sandbox.log(`schedule(astro=${pattern.astro}, offset=${pattern.shift}) is tomorrow, waiting until ${date.toISOString()}`, 'info');

// Calculate new schedule in the next day
sandbox.setTimeout(() => {
if (sandbox.__engine.__schedules > 0) {
sandbox.__engine.__schedules--;
}
sandbox.schedule(pattern, callback);
}, date.getTime() - nowdate.getTime());
}, date.getTime() - Date.now());

return;
}
Expand All @@ -1719,9 +1722,9 @@ function sandBox(script, name, verbose, debug, context) {
sandbox.schedule(pattern, callback);
}, 2000);

}, ts.getTime() - nowdate.getTime());
}, ts.getTime() - Date.now());

sandbox.verbose && sandbox.log(`schedule(astro=${pattern.astro}, offset=${pattern.shift})`, 'info');
sandbox.verbose && sandbox.log(`schedule(astro=${pattern.astro}, offset=${pattern.shift}) is today, waiting until ${ts.toISOString()}`, 'info');
} else {
// fix a problem with sunday and 7
if (typeof pattern === 'string') {
Expand Down
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1474,13 +1474,14 @@ async function sunTimeSchedules(adapter, context) {
},
native: {},
});
await adapter.setStateAsync(objId, { val: timeFormatted, c: calcDate.toISOString(), ack: true });
await adapter.setStateAsync(objId, { val: timeFormatted, c: times[t].toISOString(), ack: true });
}

const todayDate = new Date();
todayDate.setHours(0);
todayDate.setMinutes(0);
todayDate.setSeconds(1);
todayDate.setMilliseconds(0);
todayDate.setDate(todayDate.getDate() + 1);

adapter.log.debug(`[sunTimeSchedules] Next: ${todayDate.toISOString()}`);
Expand Down

0 comments on commit 879b28f

Please sign in to comment.