From 40bc5dad17045facfa2bb5f384591aeea0256e9e Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 3 Jun 2021 09:56:38 +0200 Subject: [PATCH] fix time_zone AttributeError, fixes #128 Thanks @yurnih! --- custom_components/adaptive_lighting/switch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 8eb86f8c..cfe073c1 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1042,7 +1042,10 @@ class SunLightSettings: def _replace_time(date: datetime.datetime, key: str) -> datetime.datetime: time = getattr(self, f"{key}_time") date_time = datetime.datetime.combine(date, time) - utc_time = self.time_zone.localize(date_time).astimezone(dt_util.UTC) + try: # HA ≤2021.05, https://github.com/basnijholt/adaptive-lighting/issues/128 + utc_time = self.time_zone.localize(date_time).astimezone(dt_util.UTC) + except AttributeError: # HA ≥2021.06 + utc_time = date_time.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE).astimezone(dt_util.UTC) return utc_time location = self.astral_location