Add improved scene support for input_select (#27697)

* Add improved scene support for input_select

* Add tests for reproducing input_select states.

* Add some comments.

* Add support for set_options

Allows defining the options for an input_select in a scene.

* Add tests for set_options in test_reproduce_state

* Execute for real instead of mock execution.
This commit is contained in:
Rolf K authored and Paulus Schoutsen committed 2019-10-15 16:15:42 -07:00
1 parent 93f9afcd21
commit 8720ca38b5
2 files changed
+152

No files matched your search

@@ -0,0 +1,72 @@
"""Test reproduce state for Input select."""
from homeassistant.core import State
from homeassistant.setup import async_setup_component
VALID_OPTION1 = "Option A"
VALID_OPTION2 = "Option B"
VALID_OPTION3 = "Option C"
VALID_OPTION4 = "Option D"
VALID_OPTION5 = "Option E"
VALID_OPTION6 = "Option F"
INVALID_OPTION = "Option X"
VALID_OPTION_SET1 = [VALID_OPTION1, VALID_OPTION2, VALID_OPTION3]
VALID_OPTION_SET2 = [VALID_OPTION4, VALID_OPTION5, VALID_OPTION6]
ENTITY = "input_select.test_select"
async def test_reproducing_states(hass, caplog):
"""Test reproducing Input select states."""
# Setup entity
assert await async_setup_component(
hass,
"input_select",
{
"input_select": {
"test_select": {"options": VALID_OPTION_SET1, "initial": VALID_OPTION1}
}
},
)
# These calls should do nothing as entities already in desired state
await hass.helpers.state.async_reproduce_state(
[
State(ENTITY, VALID_OPTION1),
# Should not raise
State("input_select.non_existing", VALID_OPTION1),
],
blocking=True,
)
# Test that entity is in desired state
assert hass.states.get(ENTITY).state == VALID_OPTION1
# Try reproducing with different state
await hass.helpers.state.async_reproduce_state(
[
State(ENTITY, VALID_OPTION3),
# 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
)
# 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
)
# These should fail if options weren't changed to VALID_OPTION_SET2
assert hass.states.get(ENTITY).attributes == {"options": VALID_OPTION_SET2}
assert hass.states.get(ENTITY).state == VALID_OPTION5