From 9c129d309fd6dff991125650ec932b566fdfff34 Mon Sep 17 00:00:00 2001 From: David G <34038713+godind@users.noreply.github.com> Date: Fri, 19 Apr 2024 01:18:25 -0400 Subject: [PATCH] fix(moon): change to type specific return values (#123) --- calcs/moon.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/calcs/moon.js b/calcs/moon.js index 6374cf6..da10e48 100644 --- a/calcs/moon.js +++ b/calcs/moon.js @@ -7,14 +7,12 @@ module.exports = function (app, plugin) { optionKey: 'Moon', title: 'Sets environment.moon.* information such as phase, rise, and set', derivedFrom: ['navigation.datetime', 'navigation.position'], - defaults: ['', undefined], + defaults: [undefined, undefined], debounceDelay: 60 * 1000, calculator: function (datetime, position) { - var value - var mode var date - if (datetime && datetime.length > 0) { + if (!_.isUndefined(datetime) && datetime.length > 0) { date = new Date(datetime) } else { date = new Date() @@ -22,9 +20,9 @@ module.exports = function (app, plugin) { app.debug(`Using datetime: ${date} position: ${JSON.stringify(position)}`) - var illumination = suncalc.getMoonIllumination(date) + const illumination = suncalc.getMoonIllumination(date) _.keys(illumination).forEach(key => { - illumination[key] = illumination[key].toFixed(2) + illumination[key] = _.round(illumination[key], 2) }) app.debug('moon illumination:' + JSON.stringify(illumination, null, 2)) @@ -57,7 +55,7 @@ module.exports = function (app, plugin) { } app.debug('Phase Name:' + phaseName) - var times = suncalc.getMoonTimes( + const times = suncalc.getMoonTimes( date, position.latitude, position.longitude @@ -65,7 +63,10 @@ module.exports = function (app, plugin) { app.debug('moon times:' + JSON.stringify(times, null, 2)) return [ - { path: 'environment.moon.fraction', value: illumination.fraction }, + { + path: 'environment.moon.fraction', + value: illumination.fraction + }, { path: 'environment.moon.phase', value: illumination.phase }, { path: 'environment.moon.phaseName', value: phaseName }, { path: 'environment.moon.angle', value: illumination.angle }, @@ -73,11 +74,11 @@ module.exports = function (app, plugin) { { path: 'environment.moon.times.set', value: times.set || null }, { path: 'environment.moon.times.alwaysUp', - value: times.alwaysUp ? 'true' : 'false' + value: !!times.alwaysUp }, { path: 'environment.moon.times.alwaysDown', - value: times.alwaysDown ? 'true' : 'false' + value: !!times.alwaysDown } ] }