mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -7,54 +7,59 @@ import voluptuous as vol
|
||||
from homeassistant import setup
|
||||
from homeassistant.const import STATE_ON, STATE_OFF
|
||||
from homeassistant.components.fan import (
|
||||
ATTR_SPEED, ATTR_OSCILLATING, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH,
|
||||
ATTR_DIRECTION, DIRECTION_FORWARD, DIRECTION_REVERSE)
|
||||
ATTR_SPEED,
|
||||
ATTR_OSCILLATING,
|
||||
SPEED_LOW,
|
||||
SPEED_MEDIUM,
|
||||
SPEED_HIGH,
|
||||
ATTR_DIRECTION,
|
||||
DIRECTION_FORWARD,
|
||||
DIRECTION_REVERSE,
|
||||
)
|
||||
|
||||
from tests.common import (
|
||||
async_mock_service, assert_setup_component)
|
||||
from tests.common import async_mock_service, assert_setup_component
|
||||
from tests.components.fan import common
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
_TEST_FAN = 'fan.test_fan'
|
||||
_TEST_FAN = "fan.test_fan"
|
||||
# Represent for fan's state
|
||||
_STATE_INPUT_BOOLEAN = 'input_boolean.state'
|
||||
_STATE_INPUT_BOOLEAN = "input_boolean.state"
|
||||
# Represent for fan's speed
|
||||
_SPEED_INPUT_SELECT = 'input_select.speed'
|
||||
_SPEED_INPUT_SELECT = "input_select.speed"
|
||||
# Represent for fan's oscillating
|
||||
_OSC_INPUT = 'input_select.osc'
|
||||
_OSC_INPUT = "input_select.osc"
|
||||
# Represent for fan's direction
|
||||
_DIRECTION_INPUT_SELECT = 'input_select.direction'
|
||||
_DIRECTION_INPUT_SELECT = "input_select.direction"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def calls(hass):
|
||||
"""Track calls to a mock serivce."""
|
||||
return async_mock_service(hass, 'test', 'automation')
|
||||
return async_mock_service(hass, "test", "automation")
|
||||
|
||||
|
||||
# Configuration tests #
|
||||
async def test_missing_optional_config(hass, calls):
|
||||
"""Test: missing optional template is ok."""
|
||||
with assert_setup_component(1, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template': "{{ 'on' }}",
|
||||
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'script.fan_off'
|
||||
with assert_setup_component(1, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": "{{ 'on' }}",
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
"turn_off": {"service": "script.fan_off"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -64,22 +69,22 @@ async def test_missing_optional_config(hass, calls):
|
||||
|
||||
async def test_missing_value_template_config(hass, calls):
|
||||
"""Test: missing 'value_template' will fail."""
|
||||
with assert_setup_component(0, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'script.fan_off'
|
||||
with assert_setup_component(0, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
"turn_off": {"service": "script.fan_off"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -89,20 +94,22 @@ async def test_missing_value_template_config(hass, calls):
|
||||
|
||||
async def test_missing_turn_on_config(hass, calls):
|
||||
"""Test: missing 'turn_on' will fail."""
|
||||
with assert_setup_component(0, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template': "{{ 'on' }}",
|
||||
'turn_off': {
|
||||
'service': 'script.fan_off'
|
||||
with assert_setup_component(0, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": "{{ 'on' }}",
|
||||
"turn_off": {"service": "script.fan_off"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -112,20 +119,22 @@ async def test_missing_turn_on_config(hass, calls):
|
||||
|
||||
async def test_missing_turn_off_config(hass, calls):
|
||||
"""Test: missing 'turn_off' will fail."""
|
||||
with assert_setup_component(0, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template': "{{ 'on' }}",
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
with assert_setup_component(0, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": "{{ 'on' }}",
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -135,24 +144,27 @@ async def test_missing_turn_off_config(hass, calls):
|
||||
|
||||
async def test_invalid_config(hass, calls):
|
||||
"""Test: missing 'turn_off' will fail."""
|
||||
with assert_setup_component(0, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template': "{{ 'on' }}",
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
with assert_setup_component(0, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": "{{ 'on' }}",
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.async_all() == []
|
||||
|
||||
|
||||
# End of configuration tests #
|
||||
|
||||
|
||||
@@ -167,29 +179,26 @@ async def test_templates_with_entities(hass, calls):
|
||||
{% endif %}
|
||||
"""
|
||||
|
||||
with assert_setup_component(1, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template': value_template,
|
||||
'speed_template':
|
||||
"{{ states('input_select.speed') }}",
|
||||
'oscillating_template':
|
||||
"{{ states('input_select.osc') }}",
|
||||
'direction_template':
|
||||
"{{ states('input_select.direction') }}",
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'script.fan_off'
|
||||
with assert_setup_component(1, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": value_template,
|
||||
"speed_template": "{{ states('input_select.speed') }}",
|
||||
"oscillating_template": "{{ states('input_select.osc') }}",
|
||||
"direction_template": "{{ states('input_select.direction') }}",
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
"turn_off": {"service": "script.fan_off"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -198,7 +207,7 @@ async def test_templates_with_entities(hass, calls):
|
||||
|
||||
hass.states.async_set(_STATE_INPUT_BOOLEAN, True)
|
||||
hass.states.async_set(_SPEED_INPUT_SELECT, SPEED_MEDIUM)
|
||||
hass.states.async_set(_OSC_INPUT, 'True')
|
||||
hass.states.async_set(_OSC_INPUT, "True")
|
||||
hass.states.async_set(_DIRECTION_INPUT_SELECT, DIRECTION_FORWARD)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -207,31 +216,26 @@ async def test_templates_with_entities(hass, calls):
|
||||
|
||||
async def test_templates_with_valid_values(hass, calls):
|
||||
"""Test templates with valid values."""
|
||||
with assert_setup_component(1, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template':
|
||||
"{{ 'on' }}",
|
||||
'speed_template':
|
||||
"{{ 'medium' }}",
|
||||
'oscillating_template':
|
||||
"{{ 1 == 1 }}",
|
||||
'direction_template':
|
||||
"{{ 'forward' }}",
|
||||
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'script.fan_off'
|
||||
with assert_setup_component(1, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": "{{ 'on' }}",
|
||||
"speed_template": "{{ 'medium' }}",
|
||||
"oscillating_template": "{{ 1 == 1 }}",
|
||||
"direction_template": "{{ 'forward' }}",
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
"turn_off": {"service": "script.fan_off"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
@@ -241,37 +245,33 @@ async def test_templates_with_valid_values(hass, calls):
|
||||
|
||||
async def test_templates_invalid_values(hass, calls):
|
||||
"""Test templates with invalid values."""
|
||||
with assert_setup_component(1, 'fan'):
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': {
|
||||
'value_template':
|
||||
"{{ 'abc' }}",
|
||||
'speed_template':
|
||||
"{{ '0' }}",
|
||||
'oscillating_template':
|
||||
"{{ 'xyz' }}",
|
||||
'direction_template':
|
||||
"{{ 'right' }}",
|
||||
|
||||
'turn_on': {
|
||||
'service': 'script.fan_on'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'script.fan_off'
|
||||
with assert_setup_component(1, "fan"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{
|
||||
"fan": {
|
||||
"platform": "template",
|
||||
"fans": {
|
||||
"test_fan": {
|
||||
"value_template": "{{ 'abc' }}",
|
||||
"speed_template": "{{ '0' }}",
|
||||
"oscillating_template": "{{ 'xyz' }}",
|
||||
"direction_template": "{{ 'right' }}",
|
||||
"turn_on": {"service": "script.fan_on"},
|
||||
"turn_off": {"service": "script.fan_off"},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
_verify(hass, STATE_OFF, None, None, None)
|
||||
|
||||
|
||||
# End of template tests #
|
||||
|
||||
|
||||
@@ -338,10 +338,10 @@ async def test_set_invalid_speed_from_initial_stage(hass, calls):
|
||||
await common.async_turn_on(hass, _TEST_FAN)
|
||||
|
||||
# Set fan's speed to 'invalid'
|
||||
await common.async_set_speed(hass, _TEST_FAN, 'invalid')
|
||||
await common.async_set_speed(hass, _TEST_FAN, "invalid")
|
||||
|
||||
# verify speed is unchanged
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == ''
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == ""
|
||||
_verify(hass, STATE_ON, None, None, None)
|
||||
|
||||
|
||||
@@ -360,7 +360,7 @@ async def test_set_invalid_speed(hass, calls):
|
||||
_verify(hass, STATE_ON, SPEED_HIGH, None, None)
|
||||
|
||||
# Set fan's speed to 'invalid'
|
||||
await common.async_set_speed(hass, _TEST_FAN, 'invalid')
|
||||
await common.async_set_speed(hass, _TEST_FAN, "invalid")
|
||||
|
||||
# verify speed is unchanged
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == SPEED_HIGH
|
||||
@@ -369,24 +369,24 @@ async def test_set_invalid_speed(hass, calls):
|
||||
|
||||
async def test_custom_speed_list(hass, calls):
|
||||
"""Test set custom speed list."""
|
||||
await _register_components(hass, ['1', '2', '3'])
|
||||
await _register_components(hass, ["1", "2", "3"])
|
||||
|
||||
# Turn on fan
|
||||
await common.async_turn_on(hass, _TEST_FAN)
|
||||
|
||||
# Set fan's speed to '1'
|
||||
await common.async_set_speed(hass, _TEST_FAN, '1')
|
||||
await common.async_set_speed(hass, _TEST_FAN, "1")
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == '1'
|
||||
_verify(hass, STATE_ON, '1', None, None)
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == "1"
|
||||
_verify(hass, STATE_ON, "1", None, None)
|
||||
|
||||
# Set fan's speed to 'medium' which is invalid
|
||||
await common.async_set_speed(hass, _TEST_FAN, SPEED_MEDIUM)
|
||||
|
||||
# verify that speed is unchanged
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == '1'
|
||||
_verify(hass, STATE_ON, '1', None, None)
|
||||
assert hass.states.get(_SPEED_INPUT_SELECT).state == "1"
|
||||
_verify(hass, STATE_ON, "1", None, None)
|
||||
|
||||
|
||||
async def test_set_osc(hass, calls):
|
||||
@@ -400,14 +400,14 @@ async def test_set_osc(hass, calls):
|
||||
await common.async_oscillate(hass, _TEST_FAN, True)
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_OSC_INPUT).state == 'True'
|
||||
assert hass.states.get(_OSC_INPUT).state == "True"
|
||||
_verify(hass, STATE_ON, None, True, None)
|
||||
|
||||
# Set fan's osc to False
|
||||
await common.async_oscillate(hass, _TEST_FAN, False)
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_OSC_INPUT).state == 'False'
|
||||
assert hass.states.get(_OSC_INPUT).state == "False"
|
||||
_verify(hass, STATE_ON, None, False, None)
|
||||
|
||||
|
||||
@@ -420,10 +420,10 @@ async def test_set_invalid_osc_from_initial_state(hass, calls):
|
||||
|
||||
# Set fan's osc to 'invalid'
|
||||
with pytest.raises(vol.Invalid):
|
||||
await common.async_oscillate(hass, _TEST_FAN, 'invalid')
|
||||
await common.async_oscillate(hass, _TEST_FAN, "invalid")
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_OSC_INPUT).state == ''
|
||||
assert hass.states.get(_OSC_INPUT).state == ""
|
||||
_verify(hass, STATE_ON, None, None, None)
|
||||
|
||||
|
||||
@@ -438,7 +438,7 @@ async def test_set_invalid_osc(hass, calls):
|
||||
await common.async_oscillate(hass, _TEST_FAN, True)
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_OSC_INPUT).state == 'True'
|
||||
assert hass.states.get(_OSC_INPUT).state == "True"
|
||||
_verify(hass, STATE_ON, None, True, None)
|
||||
|
||||
# Set fan's osc to None
|
||||
@@ -446,7 +446,7 @@ async def test_set_invalid_osc(hass, calls):
|
||||
await common.async_oscillate(hass, _TEST_FAN, None)
|
||||
|
||||
# verify osc is unchanged
|
||||
assert hass.states.get(_OSC_INPUT).state == 'True'
|
||||
assert hass.states.get(_OSC_INPUT).state == "True"
|
||||
_verify(hass, STATE_ON, None, True, None)
|
||||
|
||||
|
||||
@@ -461,16 +461,14 @@ async def test_set_direction(hass, calls):
|
||||
await common.async_set_direction(hass, _TEST_FAN, DIRECTION_FORWARD)
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state \
|
||||
== DIRECTION_FORWARD
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == DIRECTION_FORWARD
|
||||
_verify(hass, STATE_ON, None, None, DIRECTION_FORWARD)
|
||||
|
||||
# Set fan's direction to reverse
|
||||
await common.async_set_direction(hass, _TEST_FAN, DIRECTION_REVERSE)
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state \
|
||||
== DIRECTION_REVERSE
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == DIRECTION_REVERSE
|
||||
_verify(hass, STATE_ON, None, None, DIRECTION_REVERSE)
|
||||
|
||||
|
||||
@@ -482,10 +480,10 @@ async def test_set_invalid_direction_from_initial_stage(hass, calls):
|
||||
await common.async_turn_on(hass, _TEST_FAN)
|
||||
|
||||
# Set fan's direction to 'invalid'
|
||||
await common.async_set_direction(hass, _TEST_FAN, 'invalid')
|
||||
await common.async_set_direction(hass, _TEST_FAN, "invalid")
|
||||
|
||||
# verify direction is unchanged
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == ''
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == ""
|
||||
_verify(hass, STATE_ON, None, None, None)
|
||||
|
||||
|
||||
@@ -500,21 +498,20 @@ async def test_set_invalid_direction(hass, calls):
|
||||
await common.async_set_direction(hass, _TEST_FAN, DIRECTION_FORWARD)
|
||||
|
||||
# verify
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == \
|
||||
DIRECTION_FORWARD
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == DIRECTION_FORWARD
|
||||
_verify(hass, STATE_ON, None, None, DIRECTION_FORWARD)
|
||||
|
||||
# Set fan's direction to 'invalid'
|
||||
await common.async_set_direction(hass, _TEST_FAN, 'invalid')
|
||||
await common.async_set_direction(hass, _TEST_FAN, "invalid")
|
||||
|
||||
# verify direction is unchanged
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == \
|
||||
DIRECTION_FORWARD
|
||||
assert hass.states.get(_DIRECTION_INPUT_SELECT).state == DIRECTION_FORWARD
|
||||
_verify(hass, STATE_ON, None, None, DIRECTION_FORWARD)
|
||||
|
||||
|
||||
def _verify(hass, expected_state, expected_speed, expected_oscillating,
|
||||
expected_direction):
|
||||
def _verify(
|
||||
hass, expected_state, expected_speed, expected_oscillating, expected_direction
|
||||
):
|
||||
"""Verify fan's state, speed and osc."""
|
||||
state = hass.states.get(_TEST_FAN)
|
||||
attributes = state.attributes
|
||||
@@ -526,35 +523,39 @@ def _verify(hass, expected_state, expected_speed, expected_oscillating,
|
||||
|
||||
async def _register_components(hass, speed_list=None):
|
||||
"""Register basic components for testing."""
|
||||
with assert_setup_component(1, 'input_boolean'):
|
||||
with assert_setup_component(1, "input_boolean"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
'input_boolean',
|
||||
{'input_boolean': {'state': None}}
|
||||
hass, "input_boolean", {"input_boolean": {"state": None}}
|
||||
)
|
||||
|
||||
with assert_setup_component(3, 'input_select'):
|
||||
assert await setup.async_setup_component(hass, 'input_select', {
|
||||
'input_select': {
|
||||
'speed': {
|
||||
'name': 'Speed',
|
||||
'options': ['', SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH,
|
||||
'1', '2', '3']
|
||||
},
|
||||
with assert_setup_component(3, "input_select"):
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"input_select",
|
||||
{
|
||||
"input_select": {
|
||||
"speed": {
|
||||
"name": "Speed",
|
||||
"options": [
|
||||
"",
|
||||
SPEED_LOW,
|
||||
SPEED_MEDIUM,
|
||||
SPEED_HIGH,
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
],
|
||||
},
|
||||
"osc": {"name": "oscillating", "options": ["", "True", "False"]},
|
||||
"direction": {
|
||||
"name": "Direction",
|
||||
"options": ["", DIRECTION_FORWARD, DIRECTION_REVERSE],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
'osc': {
|
||||
'name': 'oscillating',
|
||||
'options': ['', 'True', 'False']
|
||||
},
|
||||
|
||||
'direction': {
|
||||
'name': 'Direction',
|
||||
'options': ['', DIRECTION_FORWARD, DIRECTION_REVERSE]
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
with assert_setup_component(1, 'fan'):
|
||||
with assert_setup_component(1, "fan"):
|
||||
value_template = """
|
||||
{% if is_state('input_boolean.state', 'on') %}
|
||||
{{ 'on' }}
|
||||
@@ -564,59 +565,49 @@ async def _register_components(hass, speed_list=None):
|
||||
"""
|
||||
|
||||
test_fan_config = {
|
||||
'value_template': value_template,
|
||||
'speed_template':
|
||||
"{{ states('input_select.speed') }}",
|
||||
'oscillating_template':
|
||||
"{{ states('input_select.osc') }}",
|
||||
'direction_template':
|
||||
"{{ states('input_select.direction') }}",
|
||||
|
||||
'turn_on': {
|
||||
'service': 'input_boolean.turn_on',
|
||||
'entity_id': _STATE_INPUT_BOOLEAN
|
||||
"value_template": value_template,
|
||||
"speed_template": "{{ states('input_select.speed') }}",
|
||||
"oscillating_template": "{{ states('input_select.osc') }}",
|
||||
"direction_template": "{{ states('input_select.direction') }}",
|
||||
"turn_on": {
|
||||
"service": "input_boolean.turn_on",
|
||||
"entity_id": _STATE_INPUT_BOOLEAN,
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'input_boolean.turn_off',
|
||||
'entity_id': _STATE_INPUT_BOOLEAN
|
||||
"turn_off": {
|
||||
"service": "input_boolean.turn_off",
|
||||
"entity_id": _STATE_INPUT_BOOLEAN,
|
||||
},
|
||||
'set_speed': {
|
||||
'service': 'input_select.select_option',
|
||||
|
||||
'data_template': {
|
||||
'entity_id': _SPEED_INPUT_SELECT,
|
||||
'option': '{{ speed }}'
|
||||
}
|
||||
"set_speed": {
|
||||
"service": "input_select.select_option",
|
||||
"data_template": {
|
||||
"entity_id": _SPEED_INPUT_SELECT,
|
||||
"option": "{{ speed }}",
|
||||
},
|
||||
},
|
||||
'set_oscillating': {
|
||||
'service': 'input_select.select_option',
|
||||
|
||||
'data_template': {
|
||||
'entity_id': _OSC_INPUT,
|
||||
'option': '{{ oscillating }}'
|
||||
}
|
||||
"set_oscillating": {
|
||||
"service": "input_select.select_option",
|
||||
"data_template": {
|
||||
"entity_id": _OSC_INPUT,
|
||||
"option": "{{ oscillating }}",
|
||||
},
|
||||
},
|
||||
"set_direction": {
|
||||
"service": "input_select.select_option",
|
||||
"data_template": {
|
||||
"entity_id": _DIRECTION_INPUT_SELECT,
|
||||
"option": "{{ direction }}",
|
||||
},
|
||||
},
|
||||
'set_direction': {
|
||||
'service': 'input_select.select_option',
|
||||
|
||||
'data_template': {
|
||||
'entity_id': _DIRECTION_INPUT_SELECT,
|
||||
'option': '{{ direction }}'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if speed_list:
|
||||
test_fan_config['speeds'] = speed_list
|
||||
test_fan_config["speeds"] = speed_list
|
||||
|
||||
assert await setup.async_setup_component(hass, 'fan', {
|
||||
'fan': {
|
||||
'platform': 'template',
|
||||
'fans': {
|
||||
'test_fan': test_fan_config
|
||||
}
|
||||
}
|
||||
})
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
"fan",
|
||||
{"fan": {"platform": "template", "fans": {"test_fan": test_fan_config}}},
|
||||
)
|
||||
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
Reference in New Issue
Block a user