From 20a37b41035fc38c470ea611777fe7d962a05512 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Fri, 30 Apr 2021 11:00:06 +0200 Subject: [PATCH] fix 'AttributeError: 'Location' object has no attribute 'solar_noon'' --- custom_components/adaptive_lighting/switch.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 6fa23bf2..45783ee8 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1036,8 +1036,14 @@ class SunLightSettings: ) + self.sunset_offset if self.sunrise_time is None and self.sunset_time is None: - solar_noon = location.solar_noon(date, local=False) - solar_midnight = location.solar_midnight(date, local=False) + try: + # Astral v1 + solar_noon = location.solar_noon(date, local=False) + solar_midnight = location.solar_midnight(date, local=False) + except AttributeError: + # Astral v2 + solar_noon = location.noon(date, local=False) + solar_midnight = location.midnight(date, local=False) else: solar_noon = sunrise + (sunset - sunrise) / 2 solar_midnight = sunset + ((sunrise + timedelta(days=1)) - sunset) / 2