fix tz bug

This commit is contained in:
Bas Nijholt 2020-10-17 15:43:24 +02:00
commit 7ce7f4e2c1
2 changed files with 11 additions and 10 deletions

View file

@ -100,12 +100,16 @@ async def async_unload_entry(hass, config_entry: ConfigEntry) -> bool:
)
data = hass.data[DOMAIN]
data[config_entry.entry_id][UNDO_UPDATE_LISTENER]()
if len(data) == 1: # no more config_entries
if unload_ok:
data.pop(config_entry.entry_id)
if len(data) == 1 and ATTR_TURN_ON_OFF_LISTENER in data:
# no more config_entries
turn_on_off_listener = data.pop(ATTR_TURN_ON_OFF_LISTENER)
turn_on_off_listener.remove_listener()
turn_on_off_listener.remove_listener2()
if unload_ok:
data.pop(config_entry.entry_id)
if not data:
hass.data.pop(DOMAIN)
return unload_ok

View file

@ -213,6 +213,7 @@ async def async_setup_entry(
):
"""Set up the AdaptiveLighting switch."""
data = hass.data[DOMAIN]
assert config_entry.entry_id in data
if ATTR_TURN_ON_OFF_LISTENER not in data:
data[ATTR_TURN_ON_OFF_LISTENER] = TurnOnOffListener(hass)
@ -880,16 +881,12 @@ class SunLightSettings:
def _replace_time(date: datetime.datetime, key: str) -> datetime.datetime:
time = getattr(self, f"{key}_time")
date_time = datetime.datetime.combine(datetime.date.today(), time)
date_time = datetime.datetime.combine(date, time)
utc_time = self.time_zone.localize(date_time).astimezone(dt_util.UTC)
return date.replace(
hour=utc_time.hour,
minute=utc_time.minute,
second=utc_time.second,
microsecond=utc_time.microsecond,
)
return utc_time
location = self.astral_location
sunrise = (
location.sunrise(date, local=False)
if self.sunrise_time is None