Skip to content

Commit

Permalink
fix tz bug
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Oct 17, 2020
1 parent d386116 commit 7ce7f4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 7 additions & 3 deletions custom_components/adaptive_lighting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 4 additions & 7 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -880,16 +881,12 @@ def get_sun_events(self, date: datetime.datetime) -> Dict[str, float]:

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
Expand Down

0 comments on commit 7ce7f4e

Please sign in to comment.