From 80fabc8fde017e6fbdc744e207c2e51f1f8b5616 Mon Sep 17 00:00:00 2001 From: Striken5 <80947718+Striken5@users.noreply.github.com> Date: Sun, 28 May 2023 14:44:10 +0200 Subject: [PATCH 1/2] Update derivedVariables.py Code to handle NeverUpError an AlwaysUpError, for Stations fare North and fare South --- lib/derivedVariables.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/derivedVariables.py b/lib/derivedVariables.py index 90ab559..47eb070 100644 --- a/lib/derivedVariables.py +++ b/lib/derivedVariables.py @@ -1412,14 +1412,27 @@ def peakSunHours(radiation, peakSun, device, apiData, config): Now = datetime.now(pytz.utc).astimezone(Tz) # Calculate time of sunrise and sunset or use existing values + UTC = datetime.now(pytz.utc) + AlwaysUpRise = datetime(UTC.year, UTC.month, UTC.day, 0, 0, 0) + AlwaysUpSet = datetime(UTC.year, UTC.month, UTC.day, 23, 59, 59) + NeverUpRise = datetime(UTC.year, UTC.month, UTC.day, 23, 59, 49) + NeverUpSet = datetime(UTC.year, UTC.month, UTC.day, 23, 59, 59) + if peakSun[0] is None or Now > datetime.fromtimestamp(peakSun[5], Tz): Observer = ephem.Observer() Observer.pressure = 0 Observer.lat = str(config['Station']['Latitude']) Observer.lon = str(config['Station']['Longitude']) Observer.horizon = '-0:34' - sunrise = Observer.next_rising(ephem.Sun()).datetime().timestamp() - sunset = Observer.next_setting(ephem.Sun()).datetime().timestamp() + try: + sunrise = Observer.next_rising(ephem.Sun()).datetime().timestamp() + sunset = Observer.next_setting(ephem.Sun()).datetime().timestamp() + except (ephem.AlwaysUpError, ephem.NeverUpError) as e: + sunrise = AlwaysUpRise.timestamp() + sunset = AlwaysUpSet.timestamp() + except ephem.NeverUpError as e: + sunrise = NeverUpRise.timestamp() + sunset = NeverUpSet.timestamp() else: sunrise = peakSun[4] sunset = peakSun[5] From 0c64f3627567b2fd4dfa640650b96c509048f6b8 Mon Sep 17 00:00:00 2001 From: Striken5 <80947718+Striken5@users.noreply.github.com> Date: Sun, 28 May 2023 14:50:09 +0200 Subject: [PATCH 2/2] Update derivedVariables.py Code to handle NeverUpError an AlwaysUpError, for Stations fare North and fare South --- lib/derivedVariables.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/derivedVariables.py b/lib/derivedVariables.py index 47eb070..c2dff3a 100644 --- a/lib/derivedVariables.py +++ b/lib/derivedVariables.py @@ -1427,12 +1427,9 @@ def peakSunHours(radiation, peakSun, device, apiData, config): try: sunrise = Observer.next_rising(ephem.Sun()).datetime().timestamp() sunset = Observer.next_setting(ephem.Sun()).datetime().timestamp() - except (ephem.AlwaysUpError, ephem.NeverUpError) as e: + except (ephem.AlwaysUpError, ephem.NeverUpError): sunrise = AlwaysUpRise.timestamp() sunset = AlwaysUpSet.timestamp() - except ephem.NeverUpError as e: - sunrise = NeverUpRise.timestamp() - sunset = NeverUpSet.timestamp() else: sunrise = peakSun[4] sunset = peakSun[5]