Skip to content

Commit

Permalink
Tried to catch astro error: #1365
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 9, 2023
1 parent c778b2e commit dec2951
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,29 +781,40 @@ function startAdapter(options) {
const longitude = parseFloat(obj.message.longitude === undefined ? adapter.config.longitude : obj.message.longitude) || 0;
const latitude = parseFloat(obj.message.latitude === undefined ? adapter.config.latitude : obj.message.latitude) || 0;
const now = new Date();
const astroEvents = mods.suncalc.getTimes(now, latitude, longitude);
astroEvents.nextSunrise = getAstroEvent(
now,
obj.message.sunriseEvent || adapter.config.sunriseEvent,
obj.message.sunriseLimitStart || adapter.config.sunriseLimitStart,
obj.message.sunriseLimitEnd || adapter.config.sunriseLimitEnd,
sunriseOffset,
false,
latitude,
longitude,
true
);
astroEvents.nextSunset = getAstroEvent(
now,
obj.message.sunsetEvent || adapter.config.sunsetEvent,
obj.message.sunsetLimitStart || adapter.config.sunsetLimitStart,
obj.message.sunsetLimitEnd || adapter.config.sunsetLimitEnd,
sunsetOffset,
true,
latitude,
longitude,
true
);
let astroEvents = {};
try {
astroEvents = mods.suncalc.getTimes(now, latitude, longitude);
} catch (e) {
adapter.log.error(`Cannot calculate astro data: ${e}`);
}
if (astroEvents) {
try {
astroEvents.nextSunrise = getAstroEvent(
now,
obj.message.sunriseEvent || adapter.config.sunriseEvent,
obj.message.sunriseLimitStart || adapter.config.sunriseLimitStart,
obj.message.sunriseLimitEnd || adapter.config.sunriseLimitEnd,
sunriseOffset,
false,
latitude,
longitude,
true
);
astroEvents.nextSunset = getAstroEvent(
now,
obj.message.sunsetEvent || adapter.config.sunsetEvent,
obj.message.sunsetLimitStart || adapter.config.sunsetLimitStart,
obj.message.sunsetLimitEnd || adapter.config.sunsetLimitEnd,
sunsetOffset,
true,
latitude,
longitude,
true
);
} catch (e) {
adapter.log.error(`Cannot calculate astro data: ${e}`);
}
}

const result = {};
const keys = Object.keys(astroEvents).sort((a, b) => astroEvents[a] - astroEvents[b]);
Expand Down

0 comments on commit dec2951

Please sign in to comment.