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