Refactor sun component for correctness (#7295)
* Refactor sun component for correctness * Convert datetimes to dates for astral * Fix tests for updated code * Fix times now that calcs are fixed * Move sun functions to helpers * Fix flake on new file * Additional tweaks from review * Update requirements
This commit is contained in:
parent
419d97fc06
commit
40d27cde0e
19 changed files with 754 additions and 756 deletions
|
@ -11,18 +11,18 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import is_on, turn_on
|
||||
from homeassistant.components.sun import next_setting, next_rising
|
||||
from homeassistant.components.switch import DOMAIN, SwitchDevice
|
||||
from homeassistant.const import CONF_NAME, CONF_PLATFORM
|
||||
from homeassistant.helpers.event import track_time_change
|
||||
from homeassistant.helpers.sun import get_astral_event_date
|
||||
from homeassistant.util.color import (
|
||||
color_temperature_to_rgb, color_RGB_to_xy,
|
||||
color_temperature_kelvin_to_mired)
|
||||
from homeassistant.util.dt import now as dt_now
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
DEPENDENCIES = ['sun', 'light']
|
||||
SUN = "sun.sun"
|
||||
DEPENDENCIES = ['light']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_LIGHTS = 'lights'
|
||||
|
@ -159,8 +159,7 @@ class FluxSwitch(SwitchDevice):
|
|||
"""Update all the lights using flux."""
|
||||
if now is None:
|
||||
now = dt_now()
|
||||
sunset = next_setting(self.hass, SUN).replace(
|
||||
day=now.day, month=now.month, year=now.year)
|
||||
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,
|
||||
|
@ -221,6 +220,5 @@ class FluxSwitch(SwitchDevice):
|
|||
hour=self._start_time.hour, minute=self._start_time.minute,
|
||||
second=0)
|
||||
else:
|
||||
sunrise = next_rising(self.hass, SUN).replace(
|
||||
day=now.day, month=now.month, year=now.year)
|
||||
sunrise = get_astral_event_date(self.hass, 'sunrise', now.date())
|
||||
return sunrise
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue