Added mired and kelvin mode to flux (#2665)

* Added mired and kelvin mode to flux

* changed as requested

* Renamed varible

* attempt to add test for new method in flux.py

* removed line to fix lint error
This commit is contained in:
HBDK authored and Paulus Schoutsen committed 2016-07-31 16:55:48 -07:00
1 parent c39c10a088
commit a73c2e57a8
2 files changed
+125 -17

No files matched your search

+84
View File
@@ -480,3 +480,87 @@ class TestSwitchFlux(unittest.TestCase):
call = turn_on_calls[-3]
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 171)
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.452, 0.386])
def test_flux_with_mired(self):
"""Test the flux switch´s mode mired"""
platform = loader.get_component('light.test')
platform.init()
self.assertTrue(
light.setup(self.hass, {light.DOMAIN: {CONF_PLATFORM: 'test'}}))
dev1 = platform.DEVICES[0]
# Verify initial state of light
state = self.hass.states.get(dev1.entity_id)
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)
sunset_time = test_time.replace(hour=17, minute=0, second=0)
sunrise_time = test_time.replace(hour=5,
minute=0,
second=0) + timedelta(days=1)
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.components.sun.next_rising',
return_value=sunrise_time):
with patch('homeassistant.components.sun.next_setting',
return_value=sunset_time):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id],
'mode': 'mired'
}
})
turn_on_calls = mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON)
switch.turn_on(self.hass, 'switch.flux')
self.hass.pool.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.pool.block_till_done()
call = turn_on_calls[-1]
self.assertEqual(call.data[light.ATTR_COLOR_TEMP], 269)
def test_flux_with_kelvin(self):
"""Test the flux switch´s mode kelvin"""
platform = loader.get_component('light.test')
platform.init()
self.assertTrue(
light.setup(self.hass, {light.DOMAIN: {CONF_PLATFORM: 'test'}}))
dev1 = platform.DEVICES[0]
# Verify initial state of light
state = self.hass.states.get(dev1.entity_id)
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)
sunset_time = test_time.replace(hour=17, minute=0, second=0)
sunrise_time = test_time.replace(hour=5,
minute=0,
second=0) + timedelta(days=1)
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.components.sun.next_rising',
return_value=sunrise_time):
with patch('homeassistant.components.sun.next_setting',
return_value=sunset_time):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id],
'mode': 'kelvin'
}
})
turn_on_calls = mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON)
switch.turn_on(self.hass, 'switch.flux')
self.hass.pool.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.pool.block_till_done()
call = turn_on_calls[-1]
self.assertEqual(call.data[light.ATTR_COLOR_TEMP], 3708)