fix time_zone AttributeError, fixes #128

Thanks @yurnih!
This commit is contained in:
Bas Nijholt 2021-06-03 09:56:38 +02:00 committed by GitHub
commit 40bc5dad17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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