Set flux default stop time to dusk (#12062)

This is more in line with how one would expect light temperature
transitions to take place, but still allows for a user defined
stop_time.
This commit is contained in:
Gerben Meijer authored and Fabian Affolter committed 2018-01-31 12:00:47 +01:00
1 parent 434d2afbfc
commit 6ae3fa40cf
2 files changed
+18 -7

No files matched your search

+12 -4
View File
@@ -48,7 +48,7 @@ PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_LIGHTS): cv.entity_ids,
vol.Optional(CONF_NAME, default="Flux"): cv.string,
vol.Optional(CONF_START_TIME): cv.time,
vol.Optional(CONF_STOP_TIME, default=datetime.time(22, 0)): cv.time,
vol.Optional(CONF_STOP_TIME): cv.time,
vol.Optional(CONF_START_CT, default=4000):
vol.All(vol.Coerce(int), vol.Range(min=1000, max=40000)),
vol.Optional(CONF_SUNSET_CT, default=3000):
@@ -184,9 +184,7 @@ class FluxSwitch(SwitchDevice):
sunset = get_astral_event_date(self.hass, 'sunset', now.date())
start_time = self.find_start_time(now)
stop_time = now.replace(
hour=self._stop_time.hour, minute=self._stop_time.minute,
second=0)
stop_time = self.find_stop_time(now)
if stop_time <= start_time:
# stop_time does not happen in the same day as start_time
@@ -270,3 +268,13 @@ class FluxSwitch(SwitchDevice):
else:
sunrise = get_astral_event_date(self.hass, 'sunrise', now.date())
return sunrise
def find_stop_time(self, now):
"""Return dusk or stop_time if given."""
if self._stop_time:
dusk = now.replace(
hour=self._stop_time.hour, minute=self._stop_time.minute,
second=0)
else:
dusk = get_astral_event_date(self.hass, 'dusk', now.date())
return dusk