本文整理汇总了Python中tests.components.switch.common.turn_on函数的典型用法代码示例。如果您正苦于以下问题:Python turn_on函数的具体用法?Python turn_on怎么用?Python turn_on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了turn_on函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_state_json_value
def test_state_json_value(self):
"""Test with state JSON value."""
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
oncmd = json.dumps({'status': 'ok'})
offcmd = json.dumps({'status': 'nope'})
test_switch = {
'command_state': 'cat {}'.format(path),
'command_on': 'echo \'{}\' > {}'.format(oncmd, path),
'command_off': 'echo \'{}\' > {}'.format(offcmd, path),
'value_template': '{{ value_json.status=="ok" }}'
}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'command_line',
'switches': {
'test': test_switch
}
}
}))
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
common.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
common.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
开发者ID:tmcarr,项目名称:home-assistant,代码行数:35,代码来源:test_command_line.py
示例2: test_valid_hostname
def test_valid_hostname(self):
"""Test with valid hostname."""
global TEST_STATE
TEST_STATE = False
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'wake_on_lan',
'mac_address': '00-01-02-03-04-05',
'host': 'validhostname',
}
}))
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_OFF, state.state)
TEST_STATE = True
common.turn_on(self.hass, 'switch.wake_on_lan')
self.hass.block_till_done()
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_ON, state.state)
common.turn_off(self.hass, 'switch.wake_on_lan')
self.hass.block_till_done()
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_ON, state.state)
开发者ID:tmcarr,项目名称:home-assistant,代码行数:28,代码来源:test_wake_on_lan.py
示例3: test_state_none
def test_state_none(self):
"""Test with none state."""
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {
'command_on': 'echo 1 > {}'.format(path),
'command_off': 'echo 0 > {}'.format(path),
}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'command_line',
'switches': {
'test': test_switch
}
}
}))
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
common.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
common.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
开发者ID:tmcarr,项目名称:home-assistant,代码行数:31,代码来源:test_command_line.py
示例4: test_state_value
def test_state_value(self):
"""Test with state value."""
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {
'command_state': 'cat {}'.format(path),
'command_on': 'echo 1 > {}'.format(path),
'command_off': 'echo 0 > {}'.format(path),
'value_template': '{{ value=="1" }}'
}
assert setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'command_line',
'switches': {
'test': test_switch
}
}
})
state = self.hass.states.get('switch.test')
assert STATE_OFF == state.state
common.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
assert STATE_ON == state.state
common.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
state = self.hass.states.get('switch.test')
assert STATE_OFF == state.state
开发者ID:ManHammer,项目名称:home-assistant,代码行数:33,代码来源:test_command_line.py
示例5: test_on_action
def test_on_action(self):
"""Test on action."""
assert setup.setup_component(self.hass, 'switch', {
'switch': {
'platform': 'template',
'switches': {
'test_template_switch': {
'value_template':
"{{ states.switch.test_state.state }}",
'turn_on': {
'service': 'test.automation'
},
'turn_off': {
'service': 'switch.turn_off',
'entity_id': 'switch.test_state'
},
}
}
}
})
self.hass.start()
self.hass.block_till_done()
self.hass.states.set('switch.test_state', STATE_OFF)
self.hass.block_till_done()
state = self.hass.states.get('switch.test_template_switch')
assert state.state == STATE_OFF
common.turn_on(self.hass, 'switch.test_template_switch')
self.hass.block_till_done()
assert len(self.calls) == 1
开发者ID:ManHammer,项目名称:home-assistant,代码行数:34,代码来源:test_template.py
示例6: test_on_off
def test_on_off(self):
"""Test turning the switch on and off."""
assert self.switch().state == 'off'
assert self.other_switch().state == 'off'
assert not switch.is_on(self.hass, ENTITY_SWITCH)
common.turn_on(self.hass, ENTITY_SWITCH)
self.hass.block_till_done()
self.mock_lj.press_switch.assert_called_with(ENTITY_SWITCH_NUMBER)
common.turn_off(self.hass, ENTITY_SWITCH)
self.hass.block_till_done()
self.mock_lj.release_switch.assert_called_with(ENTITY_SWITCH_NUMBER)
开发者ID:boced66,项目名称:home-assistant,代码行数:14,代码来源:test_litejet.py
示例7: test_flux_after_sunrise_before_sunset_stop_next_day
def test_flux_after_sunrise_before_sunset_stop_next_day(self):
"""
Test the flux switch after sunrise and before sunset.
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
{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('xy_color'))
self.assertIsNone(state.attributes.get('brightness'))
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)
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id],
'stop_time': '01:00'
}
})
turn_on_calls = mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux')
self.hass.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.block_till_done()
call = turn_on_calls[-1]
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 173)
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.439, 0.37])
开发者ID:tmcarr,项目名称:home-assistant,代码行数:49,代码来源:test_flux.py
示例8: test_broadcast_config
def test_broadcast_config(self):
"""Test with broadcast address config."""
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'wake_on_lan',
'mac_address': '00-01-02-03-04-05',
'broadcast_address': '255.255.255.255',
}
}))
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_OFF, state.state)
common.turn_on(self.hass, 'switch.wake_on_lan')
self.hass.block_till_done()
开发者ID:tmcarr,项目名称:home-assistant,代码行数:15,代码来源:test_wake_on_lan.py
示例9: test_flux_before_sunrise_stop_next_day
def test_flux_before_sunrise_stop_next_day(self):
"""Test the flux switch before sunrise.
This test has the stop_time on the next day (after midnight).
"""
platform = loader.get_component(self.hass, 'light.test')
platform.init()
assert setup_component(self.hass, light.DOMAIN,
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0]
# Verify initial state of light
state = self.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
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)
def event_date(hass, event, now=None):
if event == SUN_EVENT_SUNRISE:
return sunrise_time
return sunset_time
with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date',
side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id],
'stop_time': '01:00'
}
})
turn_on_calls = mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux')
self.hass.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.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]
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:48,代码来源:test_switch.py
示例10: test_methods
def test_methods(self):
"""Test is_on, turn_on, turn_off methods."""
self.assertTrue(setup_component(
self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}}
))
self.assertTrue(switch.is_on(self.hass))
self.assertEqual(
STATE_ON,
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id))
common.turn_off(self.hass, self.switch_1.entity_id)
common.turn_on(self.hass, self.switch_2.entity_id)
self.hass.block_till_done()
self.assertTrue(switch.is_on(self.hass))
self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id))
# Turn all off
common.turn_off(self.hass)
self.hass.block_till_done()
self.assertFalse(switch.is_on(self.hass))
self.assertEqual(
STATE_OFF,
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
self.assertFalse(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_2.entity_id))
self.assertFalse(switch.is_on(self.hass, self.switch_3.entity_id))
# Turn all on
common.turn_on(self.hass)
self.hass.block_till_done()
self.assertTrue(switch.is_on(self.hass))
self.assertEqual(
STATE_ON,
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state)
self.assertTrue(switch.is_on(self.hass, self.switch_1.entity_id))
self.assertTrue(switch.is_on(self.hass, self.switch_2.entity_id))
self.assertTrue(switch.is_on(self.hass, self.switch_3.entity_id))
开发者ID:tmcarr,项目名称:home-assistant,代码行数:47,代码来源:test_init.py
示例11: test_flux_with_rgb
def test_flux_with_rgb(self):
"""Test the flux switch´s mode rgb."""
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
{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)
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id],
'mode': 'rgb'
}
})
turn_on_calls = mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux')
self.hass.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.block_till_done()
call = turn_on_calls[-1]
rgb = (255, 198, 152)
rounded_call = tuple(map(round, call.data[light.ATTR_RGB_COLOR]))
self.assertEqual(rounded_call, rgb)
开发者ID:tmcarr,项目名称:home-assistant,代码行数:45,代码来源:test_flux.py
示例12: test_methods
def test_methods(self):
"""Test is_on, turn_on, turn_off methods."""
assert setup_component(
self.hass, switch.DOMAIN, {switch.DOMAIN: {CONF_PLATFORM: 'test'}}
)
assert switch.is_on(self.hass)
assert STATE_ON == \
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
assert switch.is_on(self.hass, self.switch_1.entity_id)
assert not switch.is_on(self.hass, self.switch_2.entity_id)
assert not switch.is_on(self.hass, self.switch_3.entity_id)
common.turn_off(self.hass, self.switch_1.entity_id)
common.turn_on(self.hass, self.switch_2.entity_id)
self.hass.block_till_done()
assert switch.is_on(self.hass)
assert not switch.is_on(self.hass, self.switch_1.entity_id)
assert switch.is_on(self.hass, self.switch_2.entity_id)
# Turn all off
common.turn_off(self.hass)
self.hass.block_till_done()
assert not switch.is_on(self.hass)
assert STATE_OFF == \
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
assert not switch.is_on(self.hass, self.switch_1.entity_id)
assert not switch.is_on(self.hass, self.switch_2.entity_id)
assert not switch.is_on(self.hass, self.switch_3.entity_id)
# Turn all on
common.turn_on(self.hass)
self.hass.block_till_done()
assert switch.is_on(self.hass)
assert STATE_ON == \
self.hass.states.get(switch.ENTITY_ID_ALL_SWITCHES).state
assert switch.is_on(self.hass, self.switch_1.entity_id)
assert switch.is_on(self.hass, self.switch_2.entity_id)
assert switch.is_on(self.hass, self.switch_3.entity_id)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:44,代码来源:test_init.py
示例13: test_flux_with_mired
def test_flux_with_mired(self):
"""Test the flux switch´s mode mired."""
platform = loader.get_component(self.hass, 'light.test')
platform.init()
assert setup_component(self.hass, light.DOMAIN,
{light.DOMAIN: {CONF_PLATFORM: 'test'}})
dev1 = platform.DEVICES[0]
# Verify initial state of light
state = self.hass.states.get(dev1.entity_id)
assert STATE_ON == state.state
assert state.attributes.get('color_temp') is None
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)
def event_date(hass, event, now=None):
if event == SUN_EVENT_SUNRISE:
return sunrise_time
return sunset_time
with patch('homeassistant.components.flux.switch.dt_utcnow',
return_value=test_time), \
patch('homeassistant.helpers.sun.get_astral_event_date',
side_effect=event_date):
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)
common.turn_on(self.hass, 'switch.flux')
self.hass.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.block_till_done()
call = turn_on_calls[-1]
assert call.data[light.ATTR_COLOR_TEMP] == 269
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:43,代码来源:test_switch.py
示例14: test_sending_mqtt_commands_and_optimistic
async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
"""Test the sending MQTT commands in optimistic mode."""
fake_state = ha.State('switch.test', 'on')
with patch('homeassistant.helpers.restore_state.RestoreEntity'
'.async_get_last_state',
return_value=mock_coro(fake_state)):
assert await async_setup_component(hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'command_topic': 'command-topic',
'payload_on': 'beer on',
'payload_off': 'beer off',
'qos': '2'
}
})
state = hass.states.get('switch.test')
assert STATE_ON == state.state
assert state.attributes.get(ATTR_ASSUMED_STATE)
common.turn_on(hass, 'switch.test')
await hass.async_block_till_done()
mock_publish.async_publish.assert_called_once_with(
'command-topic', 'beer on', 2, False)
mock_publish.async_publish.reset_mock()
state = hass.states.get('switch.test')
assert STATE_ON == state.state
common.turn_off(hass, 'switch.test')
await hass.async_block_till_done()
await hass.async_block_till_done()
mock_publish.async_publish.assert_called_once_with(
'command-topic', 'beer off', 2, False)
state = hass.states.get('switch.test')
assert STATE_OFF == state.state
开发者ID:Martwall,项目名称:home-assistant,代码行数:39,代码来源:test_switch.py
示例15: test_valid_hostname_windows
def test_valid_hostname_windows(self):
"""Test with valid hostname on windows."""
global TEST_STATE
TEST_STATE = False
assert setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'wake_on_lan',
'mac_address': '00-01-02-03-04-05',
'host': 'validhostname',
}
})
state = self.hass.states.get('switch.wake_on_lan')
assert STATE_OFF == state.state
TEST_STATE = True
common.turn_on(self.hass, 'switch.wake_on_lan')
self.hass.block_till_done()
state = self.hass.states.get('switch.wake_on_lan')
assert STATE_ON == state.state
开发者ID:Martwall,项目名称:home-assistant,代码行数:22,代码来源:test_wake_on_lan.py
示例16: test_sending_mqtt_commands_and_optimistic
def test_sending_mqtt_commands_and_optimistic(self):
"""Test the sending MQTT commands in optimistic mode."""
fake_state = ha.State('switch.test', 'on')
with patch('homeassistant.components.switch.mqtt.async_get_last_state',
return_value=mock_coro(fake_state)):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'command_topic': 'command-topic',
'payload_on': 'beer on',
'payload_off': 'beer off',
'qos': '2'
}
})
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
common.turn_on(self.hass, 'switch.test')
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'command-topic', 'beer on', 2, False)
self.mock_publish.async_publish.reset_mock()
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_ON, state.state)
common.turn_off(self.hass, 'switch.test')
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'command-topic', 'beer off', 2, False)
state = self.hass.states.get('switch.test')
self.assertEqual(STATE_OFF, state.state)
开发者ID:tmcarr,项目名称:home-assistant,代码行数:37,代码来源:test_mqtt.py
示例17: test_off_script
def test_off_script(self):
"""Test with turn off script."""
global TEST_STATE
TEST_STATE = False
self.assertTrue(setup_component(self.hass, switch.DOMAIN, {
'switch': {
'platform': 'wake_on_lan',
'mac_address': '00-01-02-03-04-05',
'host': 'validhostname',
'turn_off': {
'service': 'shell_command.turn_off_TARGET',
},
}
}))
calls = mock_service(self.hass, 'shell_command', 'turn_off_TARGET')
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_OFF, state.state)
TEST_STATE = True
common.turn_on(self.hass, 'switch.wake_on_lan')
self.hass.block_till_done()
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_ON, state.state)
assert len(calls) == 0
TEST_STATE = False
common.turn_off(self.hass, 'switch.wake_on_lan')
self.hass.block_till_done()
state = self.hass.states.get('switch.wake_on_lan')
self.assertEqual(STATE_OFF, state.state)
assert len(calls) == 1
开发者ID:tmcarr,项目名称:home-assistant,代码行数:36,代码来源:test_wake_on_lan.py
示例18: test_flux_with_multiple_lights
def test_flux_with_multiple_lights(self):
"""Test the flux switch with multiple light entities."""
platform = loader.get_component(self.hass, 'light.test')
platform.init()
self.assertTrue(
setup_component(self.hass, light.DOMAIN,
{light.DOMAIN: {CONF_PLATFORM: 'test'}}))
dev1, dev2, dev3 = platform.DEVICES
common_light.turn_on(self.hass, entity_id=dev2.entity_id)
self.hass.block_till_done()
common_light.turn_on(self.hass, entity_id=dev3.entity_id)
self.hass.block_till_done()
state = self.hass.states.get(dev1.entity_id)
self.assertEqual(STATE_ON, state.state)
self.assertIsNone(state.attributes.get('xy_color'))
self.assertIsNone(state.attributes.get('brightness'))
state = self.hass.states.get(dev2.entity_id)
self.assertEqual(STATE_ON, state.state)
self.assertIsNone(state.attributes.get('xy_color'))
self.assertIsNone(state.attributes.get('brightness'))
state = self.hass.states.get(dev3.entity_id)
self.assertEqual(STATE_ON, state.state)
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)
sunset_time = test_time.replace(hour=17, minute=0, second=0)
sunrise_time = test_time.replace(hour=5, minute=0, second=0)
def event_date(hass, event, now=None):
if event == 'sunrise':
print('sunrise {}'.format(sunrise_time))
return sunrise_time
print('sunset {}'.format(sunset_time))
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
side_effect=event_date):
assert setup_component(self.hass, switch.DOMAIN, {
switch.DOMAIN: {
'platform': 'flux',
'name': 'flux',
'lights': [dev1.entity_id,
dev2.entity_id,
dev3.entity_id]
}
})
turn_on_calls = mock_service(
self.hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(self.hass, 'switch.flux')
self.hass.block_till_done()
fire_time_changed(self.hass, test_time)
self.hass.block_till_done()
call = turn_on_calls[-1]
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 163)
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.46, 0.376])
call = turn_on_calls[-2]
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 163)
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.46, 0.376])
call = turn_on_calls[-3]
self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 163)
self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.46, 0.376])
开发者ID:tmcarr,项目名称:home-assistant,代码行数:67,代码来源:test_flux.py
注:本文中的tests.components.switch.common.turn_on函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论