Flux switch (#24542)

* Updated to pytest

* Additional test case
This commit is contained in:
Penny Wood 2019-06-15 13:32:51 +08:00 committed by GitHub
parent fe8a330a45
commit aa8ddeca34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,34 +1,23 @@
"""The tests for the Flux switch platform.""" """The tests for the Flux switch platform."""
import unittest from asynctest.mock import patch
from unittest.mock import patch import pytest
from homeassistant.setup import setup_component from homeassistant.setup import async_setup_component
from homeassistant.components import switch, light from homeassistant.components import switch, light
from homeassistant.const import ( from homeassistant.const import (
CONF_PLATFORM, STATE_ON, SERVICE_TURN_ON, SUN_EVENT_SUNRISE) CONF_PLATFORM, STATE_ON, SERVICE_TURN_ON, SUN_EVENT_SUNRISE)
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from tests.common import ( from tests.common import (
assert_setup_component, get_test_home_assistant, fire_time_changed, assert_setup_component, async_fire_time_changed,
mock_service) async_mock_service)
from tests.components.light import common as common_light from tests.components.light import common as common_light
from tests.components.switch import common from tests.components.switch import common
class TestSwitchFlux(unittest.TestCase): async def test_valid_config(hass):
"""Test the Flux switch platform."""
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
def test_valid_config(self):
"""Test configuration.""" """Test configuration."""
assert setup_component(self.hass, 'switch', { assert await async_setup_component(hass, 'switch', {
'switch': { 'switch': {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -36,9 +25,10 @@ class TestSwitchFlux(unittest.TestCase):
} }
}) })
def test_valid_config_with_info(self):
async def test_valid_config_with_info(hass):
"""Test configuration.""" """Test configuration."""
assert setup_component(self.hass, 'switch', { assert await async_setup_component(hass, 'switch', {
'switch': { 'switch': {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -51,37 +41,41 @@ class TestSwitchFlux(unittest.TestCase):
} }
}) })
def test_valid_config_no_name(self):
async def test_valid_config_no_name(hass):
"""Test configuration.""" """Test configuration."""
with assert_setup_component(1, 'switch'): with assert_setup_component(1, 'switch'):
assert setup_component(self.hass, 'switch', { assert await async_setup_component(hass, 'switch', {
'switch': { 'switch': {
'platform': 'flux', 'platform': 'flux',
'lights': ['light.desk', 'light.lamp'] 'lights': ['light.desk', 'light.lamp']
} }
}) })
def test_invalid_config_no_lights(self):
async def test_invalid_config_no_lights(hass):
"""Test configuration.""" """Test configuration."""
with assert_setup_component(0, 'switch'): with assert_setup_component(0, 'switch'):
assert setup_component(self.hass, 'switch', { assert await async_setup_component(hass, 'switch', {
'switch': { 'switch': {
'platform': 'flux', 'platform': 'flux',
'name': 'flux' 'name': 'flux'
} }
}) })
def test_flux_when_switch_is_off(self):
async def test_flux_when_switch_is_off(hass):
"""Test the flux switch when it is off.""" """Test the flux switch when it is off."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(
hass, light.DOMAIN,
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) {light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -95,78 +89,130 @@ class TestSwitchFlux(unittest.TestCase):
return sunrise_time return sunrise_time
return sunset_time return sunset_time
with patch('homeassistant.util.dt.utcnow', return_value=test_time): with patch('homeassistant.components.flux.switch.dt_utcnow',
with patch('homeassistant.helpers.sun.get_astral_event_date', return_value=test_time), \
patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { turn_on_calls = async_mock_service(
hass, light.DOMAIN, SERVICE_TURN_ON)
assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
'lights': [dev1.entity_id] 'lights': [dev1.entity_id]
} }
}) })
turn_on_calls = mock_service( async_fire_time_changed(hass, test_time)
self.hass, light.DOMAIN, SERVICE_TURN_ON) await hass.async_block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.block_till_done()
assert 0 == len(turn_on_calls)
def test_flux_before_sunrise(self): assert not turn_on_calls
async def test_flux_before_sunrise(hass):
"""Test the flux switch before sunrise.""" """Test the flux switch before sunrise."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
test_time = dt_util.utcnow().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) sunset_time = test_time.replace(hour=17, minute=0, second=0)
sunrise_time = test_time.replace(hour=5, minute=0, second=0) sunrise_time = test_time.replace(hour=5, minute=0, second=5)
def event_date(hass, event, now=None): def event_date(hass, event, now=None):
if event == SUN_EVENT_SUNRISE: if event == SUN_EVENT_SUNRISE:
return sunrise_time return sunrise_time
return sunset_time return sunset_time
with patch('homeassistant.util.dt.utcnow', return_value=test_time): await hass.async_block_till_done()
with patch('homeassistant.helpers.sun.get_astral_event_date', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \
patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
'lights': [dev1.entity_id] 'lights': [dev1.entity_id]
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') await common.async_turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 112 assert call.data[light.ATTR_BRIGHTNESS] == 112
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379] assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
# pylint: disable=invalid-name
def test_flux_after_sunrise_before_sunset(self): async def test_flux_before_sunrise_known_location(hass):
"""Test the flux switch after sunrise and before sunset.""" """Test the flux switch before sunrise."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None
hass.config.latitude = 55.948372
hass.config.longitude = -3.199466
hass.config.elevation = 17
test_time = dt_util.utcnow().replace(
hour=2, minute=0, second=0, day=21, month=6, year=2019)
await hass.async_block_till_done()
with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time):
assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id],
# 'brightness': 255,
# 'disable_brightness_adjust': True,
# 'mode': 'rgb',
# 'interval': 120
}
})
turn_on_calls = async_mock_service(
hass, light.DOMAIN, SERVICE_TURN_ON)
await common.async_turn_on(hass, 'switch.flux')
await hass.async_block_till_done()
async_fire_time_changed(hass, test_time)
await hass.async_block_till_done()
call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 112
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
# pylint: disable=invalid-name
async def test_flux_after_sunrise_before_sunset(hass):
"""Test the flux switch after sunrise and before sunset."""
platform = getattr(hass.components, 'test.light')
platform.init()
assert await async_setup_component(hass, light.DOMAIN, {
light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0]
# Verify initial state of light
state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -182,37 +228,38 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
'lights': [dev1.entity_id] 'lights': [dev1.entity_id]
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') await common.async_turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 173 assert call.data[light.ATTR_BRIGHTNESS] == 173
assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37] assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_after_sunset_before_stop(self): async def test_flux_after_sunset_before_stop(hass):
"""Test the flux switch after sunset and before stop.""" """Test the flux switch after sunset and before stop."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -228,9 +275,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -238,28 +285,29 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '22:00' 'stop_time': '22:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 146 assert call.data[light.ATTR_BRIGHTNESS] == 146
assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385] assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_after_stop_before_sunrise(self): async def test_flux_after_stop_before_sunrise(hass):
"""Test the flux switch after stop and before sunrise.""" """Test the flux switch after stop and before sunrise."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -273,38 +321,40 @@ class TestSwitchFlux(unittest.TestCase):
return sunrise_time return sunrise_time
return sunset_time return sunset_time
with patch('homeassistant.util.dt.utcnow', return_value=test_time): with patch('homeassistant.components.flux.switch.dt_utcnow',
with patch('homeassistant.helpers.sun.get_astral_event_date', return_value=test_time), \
patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
'lights': [dev1.entity_id] 'lights': [dev1.entity_id]
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 112 assert call.data[light.ATTR_BRIGHTNESS] == 112
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379] assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_with_custom_start_stop_times(self): async def test_flux_with_custom_start_stop_times(hass):
"""Test the flux with custom start and stop times.""" """Test the flux with custom start and stop times."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -320,9 +370,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -331,30 +381,31 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '23:30' 'stop_time': '23:30'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 147 assert call.data[light.ATTR_BRIGHTNESS] == 147
assert call.data[light.ATTR_XY_COLOR] == [0.504, 0.385] assert call.data[light.ATTR_XY_COLOR] == [0.504, 0.385]
def test_flux_before_sunrise_stop_next_day(self):
async def test_flux_before_sunrise_stop_next_day(hass):
"""Test the flux switch before sunrise. """Test the flux switch before sunrise.
This test has the stop_time on the next day (after midnight). This test has the stop_time on the next day (after midnight).
""" """
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -370,9 +421,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -380,32 +431,33 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '01:00' 'stop_time': '01:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 112 assert call.data[light.ATTR_BRIGHTNESS] == 112
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379] assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_after_sunrise_before_sunset_stop_next_day(self): async def test_flux_after_sunrise_before_sunset_stop_next_day(hass):
""" """
Test the flux switch after sunrise and before sunset. Test the flux switch after sunrise and before sunset.
This test has the stop_time on the next day (after midnight). This test has the stop_time on the next day (after midnight).
""" """
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -421,9 +473,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -431,31 +483,33 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '01:00' 'stop_time': '01:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 173 assert call.data[light.ATTR_BRIGHTNESS] == 173
assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37] assert call.data[light.ATTR_XY_COLOR] == [0.439, 0.37]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_after_sunset_before_midnight_stop_next_day(self): @pytest.mark.parametrize("x", [0, 1])
async def test_flux_after_sunset_before_midnight_stop_next_day(hass, x):
"""Test the flux switch after sunset and before stop. """Test the flux switch after sunset and before stop.
This test has the stop_time on the next day (after midnight). This test has the stop_time on the next day (after midnight).
""" """
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -469,10 +523,11 @@ class TestSwitchFlux(unittest.TestCase):
return sunrise_time return sunrise_time
return sunset_time return sunset_time
with patch('homeassistant.util.dt.utcnow', return_value=test_time): with patch('homeassistant.components.flux.switch.dt_utcnow',
with patch('homeassistant.helpers.sun.get_astral_event_date', return_value=test_time), \
patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -480,31 +535,32 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '01:00' 'stop_time': '01:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 119 assert call.data[light.ATTR_BRIGHTNESS] == 119
assert call.data[light.ATTR_XY_COLOR] == [0.588, 0.386] assert call.data[light.ATTR_XY_COLOR] == [0.588, 0.386]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_after_sunset_after_midnight_stop_next_day(self): async def test_flux_after_sunset_after_midnight_stop_next_day(hass):
"""Test the flux switch after sunset and before stop. """Test the flux switch after sunset and before stop.
This test has the stop_time on the next day (after midnight). This test has the stop_time on the next day (after midnight).
""" """
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -520,9 +576,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -530,31 +586,32 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '01:00' 'stop_time': '01:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 114 assert call.data[light.ATTR_BRIGHTNESS] == 114
assert call.data[light.ATTR_XY_COLOR] == [0.601, 0.382] assert call.data[light.ATTR_XY_COLOR] == [0.601, 0.382]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_after_stop_before_sunrise_stop_next_day(self): async def test_flux_after_stop_before_sunrise_stop_next_day(hass):
"""Test the flux switch after stop and before sunrise. """Test the flux switch after stop and before sunrise.
This test has the stop_time on the next day (after midnight). This test has the stop_time on the next day (after midnight).
""" """
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -570,9 +627,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -580,28 +637,29 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '01:00' 'stop_time': '01:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 112 assert call.data[light.ATTR_BRIGHTNESS] == 112
assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379] assert call.data[light.ATTR_XY_COLOR] == [0.606, 0.379]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_with_custom_colortemps(self): async def test_flux_with_custom_colortemps(hass):
"""Test the flux with custom start and stop colortemps.""" """Test the flux with custom start and stop colortemps."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -617,9 +675,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -629,28 +687,29 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '22:00' 'stop_time': '22:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 159 assert call.data[light.ATTR_BRIGHTNESS] == 159
assert call.data[light.ATTR_XY_COLOR] == [0.469, 0.378] assert call.data[light.ATTR_XY_COLOR] == [0.469, 0.378]
# pylint: disable=invalid-name # pylint: disable=invalid-name
def test_flux_with_custom_brightness(self): async def test_flux_with_custom_brightness(hass):
"""Test the flux with custom start and stop colortemps.""" """Test the flux with custom start and stop colortemps."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -666,9 +725,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -677,40 +736,41 @@ class TestSwitchFlux(unittest.TestCase):
'stop_time': '22:00' 'stop_time': '22:00'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 255 assert call.data[light.ATTR_BRIGHTNESS] == 255
assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385] assert call.data[light.ATTR_XY_COLOR] == [0.506, 0.385]
def test_flux_with_multiple_lights(self):
async def test_flux_with_multiple_lights(hass):
"""Test the flux switch with multiple light entities.""" """Test the flux switch with multiple light entities."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1, dev2, dev3 = platform.DEVICES dev1, dev2, dev3 = platform.DEVICES
common_light.turn_on(self.hass, entity_id=dev2.entity_id) common_light.turn_on(hass, entity_id=dev2.entity_id)
self.hass.block_till_done() await hass.async_block_till_done()
common_light.turn_on(self.hass, entity_id=dev3.entity_id) common_light.turn_on(hass, entity_id=dev3.entity_id)
self.hass.block_till_done() await hass.async_block_till_done()
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
state = self.hass.states.get(dev2.entity_id) state = hass.states.get(dev2.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
state = self.hass.states.get(dev3.entity_id) state = hass.states.get(dev3.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('xy_color') is None assert state.attributes.get('xy_color') is None
assert state.attributes.get('brightness') is None assert state.attributes.get('brightness') is None
@ -728,23 +788,24 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
'lights': [dev1.entity_id, 'lights': [
dev1.entity_id,
dev2.entity_id, dev2.entity_id,
dev3.entity_id] dev3.entity_id]
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_BRIGHTNESS] == 163 assert call.data[light.ATTR_BRIGHTNESS] == 163
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376] assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
@ -755,17 +816,18 @@ class TestSwitchFlux(unittest.TestCase):
assert call.data[light.ATTR_BRIGHTNESS] == 163 assert call.data[light.ATTR_BRIGHTNESS] == 163
assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376] assert call.data[light.ATTR_XY_COLOR] == [0.46, 0.376]
def test_flux_with_mired(self):
async def test_flux_with_mired(hass):
"""Test the flux switch´s mode mired.""" """Test the flux switch´s mode mired."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('color_temp') is None assert state.attributes.get('color_temp') is None
@ -780,9 +842,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -790,26 +852,27 @@ class TestSwitchFlux(unittest.TestCase):
'mode': 'mired' 'mode': 'mired'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') common.turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
assert call.data[light.ATTR_COLOR_TEMP] == 269 assert call.data[light.ATTR_COLOR_TEMP] == 269
def test_flux_with_rgb(self):
async def test_flux_with_rgb(hass):
"""Test the flux switch´s mode rgb.""" """Test the flux switch´s mode rgb."""
platform = getattr(self.hass.components, 'test.light') platform = getattr(hass.components, 'test.light')
platform.init() platform.init()
assert setup_component(self.hass, light.DOMAIN, assert await async_setup_component(hass, light.DOMAIN, {
{light.DOMAIN: {CONF_PLATFORM: 'test'}}) light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0] dev1 = platform.DEVICES[0]
# Verify initial state of light # Verify initial state of light
state = self.hass.states.get(dev1.entity_id) state = hass.states.get(dev1.entity_id)
assert STATE_ON == state.state assert STATE_ON == state.state
assert state.attributes.get('color_temp') is None assert state.attributes.get('color_temp') is None
@ -824,9 +887,9 @@ class TestSwitchFlux(unittest.TestCase):
with patch('homeassistant.components.flux.switch.dt_utcnow', with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \ return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date', patch('homeassistant.components.flux.switch.get_astral_event_date',
side_effect=event_date): side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, { assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: { switch.DOMAIN: {
'platform': 'flux', 'platform': 'flux',
'name': 'flux', 'name': 'flux',
@ -834,12 +897,12 @@ class TestSwitchFlux(unittest.TestCase):
'mode': 'rgb' 'mode': 'rgb'
} }
}) })
turn_on_calls = mock_service( turn_on_calls = async_mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON) hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux') await common.async_turn_on(hass, 'switch.flux')
self.hass.block_till_done() await hass.async_block_till_done()
fire_time_changed(self.hass, test_time) async_fire_time_changed(hass, test_time)
self.hass.block_till_done() await hass.async_block_till_done()
call = turn_on_calls[-1] call = turn_on_calls[-1]
rgb = (255, 198, 152) rgb = (255, 198, 152)
rounded_call = tuple(map(round, call.data[light.ATTR_RGB_COLOR])) rounded_call = tuple(map(round, call.data[light.ATTR_RGB_COLOR]))