diff --git a/homeassistant/components/template/binary_sensor.py b/homeassistant/components/template/binary_sensor.py index 7de43ea0702..8991ce4c65b 100644 --- a/homeassistant/components/template/binary_sensor.py +++ b/homeassistant/components/template/binary_sensor.py @@ -103,12 +103,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= attribute_templates, ) ) - if not sensors: - _LOGGER.error("No sensors added") - return False async_add_entities(sensors) - return True class BinarySensorTemplate(BinarySensorDevice): diff --git a/homeassistant/components/template/cover.py b/homeassistant/components/template/cover.py index 870e4035c2f..14fc6996378 100644 --- a/homeassistant/components/template/cover.py +++ b/homeassistant/components/template/cover.py @@ -65,30 +65,33 @@ TILT_FEATURES = ( | SUPPORT_SET_TILT_POSITION ) -COVER_SCHEMA = vol.Schema( - { - vol.Inclusive(OPEN_ACTION, CONF_OPEN_OR_CLOSE): cv.SCRIPT_SCHEMA, - vol.Inclusive(CLOSE_ACTION, CONF_OPEN_OR_CLOSE): cv.SCRIPT_SCHEMA, - vol.Optional(STOP_ACTION): cv.SCRIPT_SCHEMA, - vol.Exclusive( - CONF_POSITION_TEMPLATE, CONF_VALUE_OR_POSITION_TEMPLATE - ): cv.template, - vol.Exclusive( - CONF_VALUE_TEMPLATE, CONF_VALUE_OR_POSITION_TEMPLATE - ): cv.template, - vol.Optional(CONF_AVAILABILITY_TEMPLATE): cv.template, - vol.Optional(CONF_POSITION_TEMPLATE): cv.template, - vol.Optional(CONF_TILT_TEMPLATE): cv.template, - vol.Optional(CONF_ICON_TEMPLATE): cv.template, - vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template, - vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA, - vol.Optional(CONF_OPTIMISTIC): cv.boolean, - vol.Optional(CONF_TILT_OPTIMISTIC): cv.boolean, - vol.Optional(POSITION_ACTION): cv.SCRIPT_SCHEMA, - vol.Optional(TILT_ACTION): cv.SCRIPT_SCHEMA, - vol.Optional(CONF_FRIENDLY_NAME): cv.string, - vol.Optional(CONF_ENTITY_ID): cv.entity_ids, - } +COVER_SCHEMA = vol.All( + vol.Schema( + { + vol.Inclusive(OPEN_ACTION, CONF_OPEN_OR_CLOSE): cv.SCRIPT_SCHEMA, + vol.Inclusive(CLOSE_ACTION, CONF_OPEN_OR_CLOSE): cv.SCRIPT_SCHEMA, + vol.Optional(STOP_ACTION): cv.SCRIPT_SCHEMA, + vol.Exclusive( + CONF_POSITION_TEMPLATE, CONF_VALUE_OR_POSITION_TEMPLATE + ): cv.template, + vol.Exclusive( + CONF_VALUE_TEMPLATE, CONF_VALUE_OR_POSITION_TEMPLATE + ): cv.template, + vol.Optional(CONF_AVAILABILITY_TEMPLATE): cv.template, + vol.Optional(CONF_POSITION_TEMPLATE): cv.template, + vol.Optional(CONF_TILT_TEMPLATE): cv.template, + vol.Optional(CONF_ICON_TEMPLATE): cv.template, + vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template, + vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA, + vol.Optional(CONF_OPTIMISTIC): cv.boolean, + vol.Optional(CONF_TILT_OPTIMISTIC): cv.boolean, + vol.Optional(POSITION_ACTION): cv.SCRIPT_SCHEMA, + vol.Optional(TILT_ACTION): cv.SCRIPT_SCHEMA, + vol.Optional(CONF_FRIENDLY_NAME): cv.string, + vol.Optional(CONF_ENTITY_ID): cv.entity_ids, + } + ), + cv.has_at_least_one_key(OPEN_ACTION, POSITION_ACTION), ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( @@ -118,12 +121,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= optimistic = device_config.get(CONF_OPTIMISTIC) tilt_optimistic = device_config.get(CONF_TILT_OPTIMISTIC) - if position_action is None and open_action is None: - _LOGGER.error( - "Must specify at least one of %s" or "%s", OPEN_ACTION, POSITION_ACTION - ) - continue - templates = { CONF_VALUE_TEMPLATE: state_template, CONF_POSITION_TEMPLATE: position_template, @@ -160,12 +157,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= entity_ids, ) ) - if not covers: - _LOGGER.error("No covers added") - return False async_add_entities(covers) - return True class CoverTemplate(CoverDevice): diff --git a/homeassistant/components/template/light.py b/homeassistant/components/template/light.py index a6855a1654b..7948782479b 100644 --- a/homeassistant/components/template/light.py +++ b/homeassistant/components/template/light.py @@ -131,12 +131,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) ) - if not lights: - _LOGGER.error("No lights added") - return False - async_add_entities(lights) - return True class LightTemplate(Light): diff --git a/homeassistant/components/template/switch.py b/homeassistant/components/template/switch.py index c2d8e8158c1..f96ed5479b9 100644 --- a/homeassistant/components/template/switch.py +++ b/homeassistant/components/template/switch.py @@ -93,12 +93,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) ) - if not switches: - _LOGGER.error("No switches added") - return False - async_add_entities(switches) - return True class SwitchTemplate(SwitchDevice): diff --git a/tests/components/template/test_cover.py b/tests/components/template/test_cover.py index 9980691085b..5109607d799 100644 --- a/tests/components/template/test_cover.py +++ b/tests/components/template/test_cover.py @@ -270,26 +270,22 @@ async def test_template_mutex(hass, calls): assert hass.states.async_all() == [] -async def test_template_open_or_position(hass, calls): +async def test_template_open_or_position(hass, caplog): """Test that at least one of open_cover or set_position is used.""" - with assert_setup_component(1, "cover"): - assert await setup.async_setup_component( - hass, - "cover", - { - "cover": { - "platform": "template", - "covers": { - "test_template_cover": {"value_template": "{{ 1 == 1 }}"} - }, - } - }, - ) - - await hass.async_start() + assert await setup.async_setup_component( + hass, + "cover", + { + "cover": { + "platform": "template", + "covers": {"test_template_cover": {"value_template": "{{ 1 == 1 }}"}}, + } + }, + ) await hass.async_block_till_done() assert hass.states.async_all() == [] + assert "Invalid config for [cover.template]" in caplog.text async def test_template_open_and_close(hass, calls):