Add transition support to scenes, cleanup blocking parameter (#34434)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-04-20 18:07:50 -07:00
1 parent 19be31d13a
commit bc5a2da7b7
66 files changed
+547 -229

No files matched your search

@@ -70,8 +70,7 @@ async def test_reproducing_states(hass, caplog):
State("alarm_control_panel.entity_armed_night", STATE_ALARM_ARMED_NIGHT),
State("alarm_control_panel.entity_disarmed", STATE_ALARM_DISARMED),
State("alarm_control_panel.entity_triggered", STATE_ALARM_TRIGGERED),
],
blocking=True,
]
)
assert len(arm_away_calls) == 0
@@ -83,7 +82,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("alarm_control_panel.entity_triggered", "not_supported")], blocking=True
[State("alarm_control_panel.entity_triggered", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -109,8 +108,7 @@ async def test_reproducing_states(hass, caplog):
State("alarm_control_panel.entity_triggered", STATE_ALARM_DISARMED),
# Should not raise
State("alarm_control_panel.non_existing", "on"),
],
blocking=True,
]
)
assert len(arm_away_calls) == 1
@@ -14,8 +14,7 @@ async def test_reproducing_states(hass, caplog):
# These calls should do nothing as entities already in desired state
await hass.helpers.state.async_reproduce_state(
[State("automation.entity_off", "off"), State("automation.entity_on", "on")],
blocking=True,
[State("automation.entity_off", "off"), State("automation.entity_on", "on")]
)
assert len(turn_on_calls) == 0
@@ -23,7 +22,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("automation.entity_off", "not_supported")], blocking=True
[State("automation.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -37,8 +36,7 @@ async def test_reproducing_states(hass, caplog):
State("automation.entity_off", "on"),
# Should not raise
State("automation.non_existing", "on"),
],
blocking=True,
]
)
assert len(turn_on_calls) == 1
@@ -82,7 +82,9 @@ async def test_state_with_context(hass):
context = Context()
await async_reproduce_states(hass, [State(ENTITY_1, HVAC_MODE_HEAT)], context)
await async_reproduce_states(
hass, [State(ENTITY_1, HVAC_MODE_HEAT)], context=context
)
await hass.async_block_till_done()
@@ -24,15 +24,14 @@ async def test_reproducing_states(hass, caplog):
"8",
{"initial": 12, "minimum": 5, "maximum": 15, "step": 3},
),
],
blocking=True,
]
)
assert len(configure_calls) == 0
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("counter.entity", "not_supported")], blocking=True
[State("counter.entity", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -49,8 +48,7 @@ async def test_reproducing_states(hass, caplog):
),
# Should not raise
State("counter.non_existing", "6"),
],
blocking=True,
]
)
valid_calls = [
@@ -93,8 +93,7 @@ async def test_reproducing_states(hass, caplog):
STATE_OPEN,
{ATTR_CURRENT_POSITION: 100, ATTR_CURRENT_TILT_POSITION: 100},
),
],
blocking=True,
]
)
assert len(close_calls) == 0
@@ -106,7 +105,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("cover.entity_close", "not_supported")], blocking=True
[State("cover.entity_close", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -145,7 +144,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("cover.non_existing", "on"),
],
blocking=True,
)
valid_close_calls = [
+1 -3
View File
@@ -27,7 +27,6 @@ async def test_reproducing_states(hass, caplog):
State("fan.entity_oscillating", "on", {"oscillating": True}),
State("fan.entity_direction", "on", {"direction": "forward"}),
],
blocking=True,
)
assert len(turn_on_calls) == 0
@@ -38,7 +37,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("fan.entity_off", "not_supported")], blocking=True
[State("fan.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -59,7 +58,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("fan.non_existing", "on"),
],
blocking=True,
)
assert len(turn_on_calls) == 1
@@ -39,7 +39,7 @@ async def test_reproduce_group(hass):
state = State("group.test", "on")
await async_reproduce_states(hass, [state], context)
await async_reproduce_states(hass, [state], context=context)
fun.assert_called_once_with(
hass,
@@ -48,6 +48,6 @@ async def test_reproduce_group(hass):
clone_state(state, "light.test2"),
clone_state(state, "switch.test1"),
],
blocking=True,
context=context,
reproduce_options=None,
)
@@ -58,6 +58,24 @@ async def test_apply_service(hass):
assert state.state == "on"
assert state.attributes["brightness"] == 50
turn_on_calls = async_mock_service(hass, "light", "turn_on")
assert await hass.services.async_call(
"scene",
"apply",
{
"transition": 42,
"entities": {"light.bed_light": {"state": "on", "brightness": 50}},
},
blocking=True,
)
assert len(turn_on_calls) == 1
assert turn_on_calls[0].domain == "light"
assert turn_on_calls[0].service == "turn_on"
assert turn_on_calls[0].data.get("transition") == 42
assert turn_on_calls[0].data.get("entity_id") == "light.bed_light"
assert turn_on_calls[0].data.get("brightness") == 50
async def test_create_service(hass, caplog):
"""Test the create service."""
@@ -22,7 +22,6 @@ async def test_reproducing_states(hass):
# Should not raise
State("input_boolean.non_existing", "on"),
],
blocking=True,
)
assert hass.states.get("input_boolean.initial_off").state == "on"
assert hass.states.get("input_boolean.initial_on").state == "off"
@@ -34,7 +33,6 @@ async def test_reproducing_states(hass):
# Set to state it already is.
State("input_boolean.initial_off", "on"),
],
blocking=True,
)
assert hass.states.get("input_boolean.initial_on").state == "off"
@@ -29,7 +29,6 @@ async def test_reproducing_states(hass, caplog):
State("input_datetime.entity_time", "01:20:00"),
State("input_datetime.entity_date", "2010-10-10"),
],
blocking=True,
)
assert len(datetime_calls) == 0
@@ -42,7 +41,6 @@ async def test_reproducing_states(hass, caplog):
State("input_datetime.entity_datetime", "not:valid:time"),
State("input_datetime.entity_datetime", "1234-56-78 90:12:34"),
],
blocking=True,
)
assert "not_supported" in caplog.text
@@ -60,7 +58,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_datetime.non_existing", "2010-10-10 01:20:00"),
],
blocking=True,
)
valid_calls = [
@@ -26,7 +26,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_number.non_existing", "234"),
],
blocking=True,
)
assert hass.states.get("input_number.test_number").state == VALID_NUMBER1
@@ -38,14 +37,13 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_number.non_existing", "234"),
],
blocking=True,
)
assert hass.states.get("input_number.test_number").state == VALID_NUMBER2
# Test setting state to number out of range
await hass.helpers.state.async_reproduce_state(
[State("input_number.test_number", "150")], blocking=True
[State("input_number.test_number", "150")]
)
# The entity states should be unchanged after trying to set them to out-of-range number
@@ -58,5 +56,4 @@ async def test_reproducing_states(hass, caplog):
# Set to state it already is.
State("input_number.test_number", VALID_NUMBER2),
],
blocking=True,
)
@@ -35,7 +35,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_select.non_existing", VALID_OPTION1),
],
blocking=True,
)
# Test that entity is in desired state
@@ -48,23 +47,20 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_select.non_existing", VALID_OPTION3),
],
blocking=True,
)
# Test that we got the desired result
assert hass.states.get(ENTITY).state == VALID_OPTION3
# Test setting state to invalid state
await hass.helpers.state.async_reproduce_state(
[State(ENTITY, INVALID_OPTION)], blocking=True
)
await hass.helpers.state.async_reproduce_state([State(ENTITY, INVALID_OPTION)])
# The entity state should be unchanged
assert hass.states.get(ENTITY).state == VALID_OPTION3
# Test setting a different option set
await hass.helpers.state.async_reproduce_state(
[State(ENTITY, VALID_OPTION5, {"options": VALID_OPTION_SET2})], blocking=True
[State(ENTITY, VALID_OPTION5, {"options": VALID_OPTION_SET2})]
)
# These should fail if options weren't changed to VALID_OPTION_SET2
@@ -29,7 +29,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_text.non_existing", VALID_TEXT1),
],
blocking=True,
)
# Test that entity is in desired state
@@ -42,7 +41,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("input_text.non_existing", VALID_TEXT2),
],
blocking=True,
)
# Test that the state was changed
@@ -50,7 +48,7 @@ async def test_reproducing_states(hass, caplog):
# Test setting state to invalid state (length too long)
await hass.helpers.state.async_reproduce_state(
[State("input_text.test_text", INVALID_TEXT1)], blocking=True
[State("input_text.test_text", INVALID_TEXT1)]
)
# The entity state should be unchanged
@@ -58,7 +56,7 @@ async def test_reproducing_states(hass, caplog):
# Test setting state to invalid state (length too short)
await hass.helpers.state.async_reproduce_state(
[State("input_text.test_text", INVALID_TEXT2)], blocking=True
[State("input_text.test_text", INVALID_TEXT2)]
)
# The entity state should be unchanged
@@ -53,8 +53,7 @@ async def test_reproducing_states(hass, caplog):
State("light.entity_profile", "on", VALID_PROFILE),
State("light.entity_rgb", "on", VALID_RGB_COLOR),
State("light.entity_xy", "on", VALID_XY_COLOR),
],
blocking=True,
]
)
assert len(turn_on_calls) == 0
@@ -62,7 +61,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("light.entity_off", "not_supported")], blocking=True
[State("light.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -86,7 +85,6 @@ async def test_reproducing_states(hass, caplog):
State("light.entity_profile", "on", VALID_RGB_COLOR),
State("light.entity_rgb", "on", VALID_XY_COLOR),
],
blocking=True,
)
assert len(turn_on_calls) == 12
@@ -163,7 +161,7 @@ async def test_deprecation_warning(hass, caplog):
hass.states.async_set("light.entity_off", "off", {})
turn_on_calls = async_mock_service(hass, "light", "turn_on")
await hass.helpers.state.async_reproduce_state(
[State("light.entity_off", "on", {"brightness_pct": 80})], blocking=True
[State("light.entity_off", "on", {"brightness_pct": 80})]
)
assert len(turn_on_calls) == 1
assert DEPRECATION_WARNING % ["brightness_pct"] in caplog.text
@@ -18,7 +18,6 @@ async def test_reproducing_states(hass, caplog):
State("lock.entity_locked", "locked"),
State("lock.entity_unlocked", "unlocked", {}),
],
blocking=True,
)
assert len(lock_calls) == 0
@@ -26,7 +25,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("lock.entity_locked", "not_supported")], blocking=True
[State("lock.entity_locked", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -41,7 +40,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("lock.non_existing", "on"),
],
blocking=True,
)
assert len(lock_calls) == 1
@@ -115,7 +115,7 @@ async def test_state_with_context(hass):
context = Context()
await async_reproduce_states(hass, [State(ENTITY_1, "on")], context)
await async_reproduce_states(hass, [State(ENTITY_1, "on")], context=context)
await hass.async_block_till_done()
@@ -15,7 +15,6 @@ async def test_reproducing_states(hass, caplog):
# These calls should do nothing as entities already in desired state
await hass.helpers.state.async_reproduce_state(
[State("remote.entity_off", "off"), State("remote.entity_on", "on")],
blocking=True,
)
assert len(turn_on_calls) == 0
@@ -23,7 +22,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("remote.entity_off", "not_supported")], blocking=True
[State("remote.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -38,7 +37,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("remote.non_existing", "on"),
],
blocking=True,
)
assert len(turn_on_calls) == 1
+14 -2
View File
@@ -6,7 +6,7 @@ from homeassistant.components import light, scene
from homeassistant.setup import async_setup_component, setup_component
from homeassistant.util.yaml import loader as yaml_loader
from tests.common import get_test_home_assistant
from tests.common import get_test_home_assistant, mock_service
from tests.components.light import common as common_light
from tests.components.scene import common
@@ -127,7 +127,19 @@ class TestScene(unittest.TestCase):
assert self.light_1.is_on
assert self.light_2.is_on
assert 100 == self.light_2.last_call("turn_on")[1].get("brightness")
assert self.light_2.last_call("turn_on")[1].get("brightness") == 100
turn_on_calls = mock_service(self.hass, "light", "turn_on")
self.hass.services.call(
scene.DOMAIN, "turn_on", {"transition": 42, "entity_id": "scene.test"}
)
self.hass.block_till_done()
assert len(turn_on_calls) == 1
assert turn_on_calls[0].domain == "light"
assert turn_on_calls[0].service == "turn_on"
assert turn_on_calls[0].data.get("transition") == 42
async def test_services_registered(hass):
@@ -15,7 +15,6 @@ async def test_reproducing_states(hass, caplog):
# These calls should do nothing as entities already in desired state
await hass.helpers.state.async_reproduce_state(
[State("switch.entity_off", "off"), State("switch.entity_on", "on", {})],
blocking=True,
)
assert len(turn_on_calls) == 0
@@ -23,7 +22,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("switch.entity_off", "not_supported")], blocking=True
[State("switch.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -37,8 +36,7 @@ async def test_reproducing_states(hass, caplog):
State("switch.entity_off", "on", {}),
# Should not raise
State("switch.non_existing", "on"),
],
blocking=True,
]
)
assert len(turn_on_calls) == 1
@@ -36,7 +36,6 @@ async def test_reproducing_states(hass, caplog):
"timer.entity_active_attr", STATUS_ACTIVE, {ATTR_DURATION: "00:01:00"}
),
],
blocking=True,
)
assert len(start_calls) == 0
@@ -45,7 +44,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("timer.entity_idle", "not_supported")], blocking=True
[State("timer.entity_idle", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -63,7 +62,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("timer.non_existing", "on"),
],
blocking=True,
)
valid_start_calls = [
@@ -59,7 +59,6 @@ async def test_reproducing_states(hass, caplog):
State("vacuum.entity_returning", STATE_RETURNING),
State("vacuum.entity_paused", STATE_PAUSED),
],
blocking=True,
)
assert len(turn_on_calls) == 0
@@ -72,7 +71,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("vacuum.entity_off", "not_supported")], blocking=True
[State("vacuum.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -98,7 +97,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("vacuum.non_existing", STATE_ON),
],
blocking=True,
)
assert len(turn_on_calls) == 1
@@ -45,8 +45,7 @@ async def test_reproducing_states(hass, caplog):
STATE_ECO,
{ATTR_AWAY_MODE: True, ATTR_TEMPERATURE: 45},
),
],
blocking=True,
]
)
assert len(turn_on_calls) == 0
@@ -57,7 +56,7 @@ async def test_reproducing_states(hass, caplog):
# Test invalid state is handled
await hass.helpers.state.async_reproduce_state(
[State("water_heater.entity_off", "not_supported")], blocking=True
[State("water_heater.entity_off", "not_supported")]
)
assert "not_supported" in caplog.text
@@ -82,7 +81,6 @@ async def test_reproducing_states(hass, caplog):
# Should not raise
State("water_heater.non_existing", "on"),
],
blocking=True,
)
assert len(turn_on_calls) == 1
+5 -6
View File
@@ -68,17 +68,16 @@ async def test_call_to_component(hass):
context = "dummy_context"
await state.async_reproduce_state(
hass,
[state_media_player, state_climate],
blocking=True,
context=context,
hass, [state_media_player, state_climate], context=context,
)
media_player_fun.assert_called_once_with(
hass, [state_media_player], context=context
hass, [state_media_player], context=context, reproduce_options=None
)
climate_fun.assert_called_once_with(hass, [state_climate], context=context)
climate_fun.assert_called_once_with(
hass, [state_climate], context=context, reproduce_options=None
)
async def test_get_changed_since(hass):