diff --git a/homeassistant/components/template/fan.py b/homeassistant/components/template/fan.py index 7289eeb72e6..f39d49fa9fd 100644 --- a/homeassistant/components/template/fan.py +++ b/homeassistant/components/template/fan.py @@ -18,6 +18,7 @@ from homeassistant.components.fan import ( SPEED_OFF, SUPPORT_DIRECTION, SUPPORT_OSCILLATE, + SUPPORT_PRESET_MODE, SUPPORT_SET_SPEED, FanEntity, preset_modes_from_speed_list, @@ -250,12 +251,10 @@ class TemplateFan(TemplateEntity, FanEntity): self._oscillating = None self._direction = None - if ( - self._speed_template - or self._percentage_template - or self._preset_mode_template - ): + if self._speed_template or self._percentage_template: self._supported_features |= SUPPORT_SET_SPEED + if self._preset_mode_template and preset_modes: + self._supported_features |= SUPPORT_PRESET_MODE if self._oscillating_template: self._supported_features |= SUPPORT_OSCILLATE if self._direction_template: diff --git a/tests/components/template/test_fan.py b/tests/components/template/test_fan.py index 91910a11e1f..2beb2e6fd2d 100644 --- a/tests/components/template/test_fan.py +++ b/tests/components/template/test_fan.py @@ -16,6 +16,8 @@ from homeassistant.components.fan import ( SPEED_LOW, SPEED_MEDIUM, SPEED_OFF, + SUPPORT_PRESET_MODE, + SUPPORT_SET_SPEED, ) from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE @@ -234,8 +236,8 @@ async def test_templates_with_entities(hass, start_ha): [ ("0", None, None, None), ("invalid", None, None, None), - ("auto", None, "auto", "auto"), - ("smart", None, "smart", "smart"), + ("auto", None, None, "auto"), + ("smart", None, None, "smart"), ("invalid", None, None, None), ], ), @@ -869,6 +871,7 @@ async def test_implemented_percentage(hass, speed_count, percentage_step): state = hass.states.get("fan.mechanical_ventilation") attributes = state.attributes assert attributes["percentage_step"] == percentage_step + assert attributes.get("supported_features") or SUPPORT_SET_SPEED @pytest.mark.parametrize("count,domain", [(1, DOMAIN)]) @@ -935,7 +938,8 @@ async def test_implemented_preset_mode(hass, start_ha): state = hass.states.get("fan.mechanical_ventilation") attributes = state.attributes - assert attributes["percentage"] is None + assert attributes.get("percentage") is None + assert attributes.get("supported_features") or SUPPORT_PRESET_MODE @pytest.mark.parametrize("count,domain", [(1, DOMAIN)])