mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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:
parent
434d2afbfc
commit
6ae3fa40cf
@ -48,7 +48,7 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||||||
vol.Required(CONF_LIGHTS): cv.entity_ids,
|
vol.Required(CONF_LIGHTS): cv.entity_ids,
|
||||||
vol.Optional(CONF_NAME, default="Flux"): cv.string,
|
vol.Optional(CONF_NAME, default="Flux"): cv.string,
|
||||||
vol.Optional(CONF_START_TIME): cv.time,
|
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.Optional(CONF_START_CT, default=4000):
|
||||||
vol.All(vol.Coerce(int), vol.Range(min=1000, max=40000)),
|
vol.All(vol.Coerce(int), vol.Range(min=1000, max=40000)),
|
||||||
vol.Optional(CONF_SUNSET_CT, default=3000):
|
vol.Optional(CONF_SUNSET_CT, default=3000):
|
||||||
@ -184,9 +184,7 @@ class FluxSwitch(SwitchDevice):
|
|||||||
|
|
||||||
sunset = get_astral_event_date(self.hass, 'sunset', now.date())
|
sunset = get_astral_event_date(self.hass, 'sunset', now.date())
|
||||||
start_time = self.find_start_time(now)
|
start_time = self.find_start_time(now)
|
||||||
stop_time = now.replace(
|
stop_time = self.find_stop_time(now)
|
||||||
hour=self._stop_time.hour, minute=self._stop_time.minute,
|
|
||||||
second=0)
|
|
||||||
|
|
||||||
if stop_time <= start_time:
|
if stop_time <= start_time:
|
||||||
# stop_time does not happen in the same day as start_time
|
# stop_time does not happen in the same day as start_time
|
||||||
@ -270,3 +268,13 @@ class FluxSwitch(SwitchDevice):
|
|||||||
else:
|
else:
|
||||||
sunrise = get_astral_event_date(self.hass, 'sunrise', now.date())
|
sunrise = get_astral_event_date(self.hass, 'sunrise', now.date())
|
||||||
return sunrise
|
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
|
||||||
|
@ -238,7 +238,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||||||
switch.DOMAIN: {
|
switch.DOMAIN: {
|
||||||
'platform': 'flux',
|
'platform': 'flux',
|
||||||
'name': 'flux',
|
'name': 'flux',
|
||||||
'lights': [dev1.entity_id]
|
'lights': [dev1.entity_id],
|
||||||
|
'stop_time': '22:00'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
turn_on_calls = mock_service(
|
turn_on_calls = mock_service(
|
||||||
@ -638,7 +639,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||||||
'name': 'flux',
|
'name': 'flux',
|
||||||
'lights': [dev1.entity_id],
|
'lights': [dev1.entity_id],
|
||||||
'start_colortemp': '1000',
|
'start_colortemp': '1000',
|
||||||
'stop_colortemp': '6000'
|
'stop_colortemp': '6000',
|
||||||
|
'stop_time': '22:00'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
turn_on_calls = mock_service(
|
turn_on_calls = mock_service(
|
||||||
@ -686,7 +688,8 @@ class TestSwitchFlux(unittest.TestCase):
|
|||||||
'platform': 'flux',
|
'platform': 'flux',
|
||||||
'name': 'flux',
|
'name': 'flux',
|
||||||
'lights': [dev1.entity_id],
|
'lights': [dev1.entity_id],
|
||||||
'brightness': 255
|
'brightness': 255,
|
||||||
|
'stop_time': '22:00'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
turn_on_calls = mock_service(
|
turn_on_calls = mock_service(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user