From 9e03d5aeebea2694690e6ac5a1101a38737344fd Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 1 Sep 2020 18:40:19 +0200 Subject: [PATCH] remove arg in get_sunrise_sunset and call update in __init__ --- .../circadian_lighting/__init__.py | 30 ++++++++++--------- .../circadian_lighting/sensor.py | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/custom_components/circadian_lighting/__init__.py b/custom_components/circadian_lighting/__init__.py index 281d9afa..3477a175 100755 --- a/custom_components/circadian_lighting/__init__.py +++ b/custom_components/circadian_lighting/__init__.py @@ -157,11 +157,13 @@ class CircadianLighting: self._elevation = elevation self._transition = transition self._timezone = self.get_timezone() - self._percent = self.calc_percent() - self._colortemp = self.calc_colortemp() - self._rgb_color = self.calc_rgb() - self._xy_color = self.calc_xy() - self._hs_color = self.calc_hs() + + self._percent = None + self._colortemp = None + self._rgb_color = None + self._xy_color = None + self._hs_color = None + self.update() if self._manual_time["sunrise"] is not None: async_track_time_change( @@ -201,7 +203,7 @@ class CircadianLighting: microsecond=other_date.microsecond, ) - def get_sunrise_sunset(self, date, as_timestamps=True): + def get_sunrise_sunset(self, date): if ( self._manual_time["sunrise"] is not None and self._manual_time["sunset"] is not None @@ -237,15 +239,15 @@ class CircadianLighting: sunset = sunset + self._sunset_offset datetimes = { - SUN_EVENT_SUNRISE: sunrise.astimezone(self._timezone), - SUN_EVENT_SUNSET: sunset.astimezone(self._timezone), - SUN_EVENT_NOON: solar_noon.astimezone(self._timezone), - SUN_EVENT_MIDNIGHT: solar_midnight.astimezone(self._timezone), + SUN_EVENT_SUNRISE: sunrise, + SUN_EVENT_SUNSET: sunset, + SUN_EVENT_NOON: solar_noon, + SUN_EVENT_MIDNIGHT: solar_midnight, + } + + return { + k: dt.astimezone(self._timezone).timestamp() for k, dt in datetimes.items() } - if as_timestamps: - return {k: dt.timestamp() for k, dt in datetimes.items()} - else: - return datetimes def calc_percent(self): now = dt_now(self._timezone) diff --git a/custom_components/circadian_lighting/sensor.py b/custom_components/circadian_lighting/sensor.py index b924fa3f..35947f92 100755 --- a/custom_components/circadian_lighting/sensor.py +++ b/custom_components/circadian_lighting/sensor.py @@ -93,5 +93,5 @@ class CircadianSensor(Entity): @callback def _update_callback(self) -> None: - """Triggers update of properties after receiving signal from CircadianLighting.""" + """Triggers update of properties.""" self.async_schedule_update_ha_state(force_refresh=False)