Fix supported_features behaviour for fan platform (#58065)

pull/58093/head
Jan Bouwhuis 2021-10-20 13:06:06 +02:00 committed by GitHub
parent a679ebcee7
commit 62b7453719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -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:

View File

@ -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)])