From fe6ed9fb2cbe837403b2763d3ce0f6a3595ca780 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 12 Sep 2020 13:18:15 +0200 Subject: [PATCH] get times from astral in UTC --- .../circadian_lighting/switch.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/custom_components/circadian_lighting/switch.py b/custom_components/circadian_lighting/switch.py index d83183b8..e1cb2b20 100755 --- a/custom_components/circadian_lighting/switch.py +++ b/custom_components/circadian_lighting/switch.py @@ -393,32 +393,28 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): location = get_astral_location(self.hass) sunrise = ( - location.sunrise(date) + location.sunrise(date, local=False) if self._sunrise_time is None else _replace_time(date, "sunrise") ) + self._sunrise_offset sunset = ( - location.sunset(date) + location.sunset(date, local=False) if self._sunset_time is None else _replace_time(date, "sunset") ) + self._sunset_offset if self._sunrise_time is None and self._sunset_time is None: - solar_noon = location.solar_noon(date) - solar_midnight = location.solar_midnight(date) + solar_noon = location.solar_noon(date, local=False) + solar_midnight = location.solar_midnight(date, local=False) else: solar_noon = sunrise + (sunset - sunrise) / 2 solar_midnight = sunset + ((sunrise + timedelta(days=1)) - sunset) / 2 - datetimes = { - SUN_EVENT_SUNRISE: sunrise, - SUN_EVENT_SUNSET: sunset, - SUN_EVENT_NOON: solar_noon, - SUN_EVENT_MIDNIGHT: solar_midnight, - } - return { - k: dt.astimezone(dt_util.UTC).timestamp() for k, dt in datetimes.items() + SUN_EVENT_SUNRISE: sunrise.timestamp(), + SUN_EVENT_SUNSET: sunset.timestamp(), + SUN_EVENT_NOON: solar_noon.timestamp(), + SUN_EVENT_MIDNIGHT: solar_midnight.timestamp(), } def _calc_percent(self):