Fix time zone for flux switch (#18102)
This commit is contained in:
parent
5a802c1069
commit
dce6a9f882
2 changed files with 38 additions and 36 deletions
|
@ -25,7 +25,7 @@ from homeassistant.util import slugify
|
|||
from homeassistant.util.color import (
|
||||
color_temperature_to_rgb, color_RGB_to_xy_brightness,
|
||||
color_temperature_kelvin_to_mired)
|
||||
from homeassistant.util.dt import now as dt_now
|
||||
from homeassistant.util.dt import utcnow as dt_utcnow, as_local
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -195,10 +195,12 @@ class FluxSwitch(SwitchDevice):
|
|||
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def flux_update(self, now=None):
|
||||
def flux_update(self, utcnow=None):
|
||||
"""Update all the lights using flux."""
|
||||
if now is None:
|
||||
now = dt_now()
|
||||
if utcnow is None:
|
||||
utcnow = dt_utcnow()
|
||||
|
||||
now = as_local(utcnow)
|
||||
|
||||
sunset = get_astral_event_date(self.hass, 'sunset', now.date())
|
||||
start_time = self.find_start_time(now)
|
||||
|
|
|
@ -87,7 +87,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=10, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=10, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -96,7 +96,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.util.dt.now', return_value=test_time):
|
||||
with patch('homeassistant.util.dt.utcnow', return_value=test_time):
|
||||
with patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
|
@ -128,7 +128,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=2, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=2, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -137,7 +137,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.util.dt.now', return_value=test_time):
|
||||
with patch('homeassistant.util.dt.utcnow', return_value=test_time):
|
||||
with patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
|
@ -174,7 +174,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -183,7 +183,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -221,7 +221,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -230,7 +230,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -269,7 +269,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=23, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=23, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -278,7 +278,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.util.dt.now', return_value=test_time):
|
||||
with patch('homeassistant.util.dt.utcnow', return_value=test_time):
|
||||
with patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
|
@ -315,7 +315,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -324,7 +324,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -366,7 +366,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=2, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=2, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -375,7 +375,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -418,7 +418,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -427,7 +427,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -469,7 +469,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=23, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=23, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -478,7 +478,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.util.dt.now', return_value=test_time):
|
||||
with patch('homeassistant.util.dt.utcnow', return_value=test_time):
|
||||
with patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
assert setup_component(self.hass, switch.DOMAIN, {
|
||||
|
@ -519,7 +519,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=00, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=00, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -528,7 +528,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -570,7 +570,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=2, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=2, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -579,7 +579,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -618,7 +618,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -627,7 +627,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -668,7 +668,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=17, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=17, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -677,7 +677,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -729,7 +729,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertIsNone(state.attributes.get('xy_color'))
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=12, minute=0, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=12, minute=0, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -740,7 +740,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
print('sunset {}'.format(sunset_time))
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -784,7 +784,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -793,7 +793,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
@ -829,7 +829,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertIsNone(state.attributes.get('color_temp'))
|
||||
|
||||
test_time = dt_util.now().replace(hour=8, minute=30, second=0)
|
||||
test_time = dt_util.utcnow().replace(hour=8, minute=30, second=0)
|
||||
sunset_time = test_time.replace(hour=17, minute=0, second=0)
|
||||
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
|
||||
|
||||
|
@ -838,7 +838,7 @@ class TestSwitchFlux(unittest.TestCase):
|
|||
return sunrise_time
|
||||
return sunset_time
|
||||
|
||||
with patch('homeassistant.components.switch.flux.dt_now',
|
||||
with patch('homeassistant.components.switch.flux.dt_utcnow',
|
||||
return_value=test_time), \
|
||||
patch('homeassistant.helpers.sun.get_astral_event_date',
|
||||
side_effect=event_date):
|
||||
|
|
Loading…
Add table
Reference in a new issue