Update template fan platform to the new entity framework (#162328)

This commit is contained in:
Petro31
2026-02-09 14:13:23 +01:00
committed by GitHub
parent 8d37917d8b
commit c945f32989
2 changed files with 67 additions and 225 deletions
+20 -10
View File
@@ -17,7 +17,7 @@ from homeassistant.components.fan import (
FanEntityFeature,
NotValidPresetModeError,
)
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
@@ -469,7 +469,17 @@ async def test_state_template(hass: HomeAssistant) -> None:
("{{ True }}", STATE_ON),
("{{ False }}", STATE_OFF),
("{{ x - 1 }}", STATE_UNAVAILABLE),
("{{ 7.45 }}", STATE_OFF),
("{{ 1 }}", STATE_ON),
("{{ 'true' }}", STATE_ON),
("{{ 'yes' }}", STATE_ON),
("{{ 'on' }}", STATE_ON),
("{{ 'enable' }}", STATE_ON),
("{{ 0 }}", STATE_OFF),
("{{ 'false' }}", STATE_OFF),
("{{ 'no' }}", STATE_OFF),
("{{ 'off' }}", STATE_OFF),
("{{ 'disable' }}", STATE_OFF),
("{{ None }}", STATE_UNKNOWN),
],
)
@pytest.mark.parametrize(
@@ -564,8 +574,8 @@ async def test_icon_template(hass: HomeAssistant) -> None:
[
("0", 0),
("33", 33),
("invalid", 0),
("5000", 0),
("invalid", None),
("5000", None),
("100", 100),
],
)
@@ -751,7 +761,7 @@ async def test_availability_template_with_entities(hass: HomeAssistant) -> None:
"value_template": "{{ 'unavailable' }}",
**OPTIMISTIC_ON_OFF_ACTIONS,
},
[STATE_OFF, None, None, None],
[STATE_UNKNOWN, None, None, None],
),
(
ConfigurationStyle.MODERN,
@@ -759,7 +769,7 @@ async def test_availability_template_with_entities(hass: HomeAssistant) -> None:
"state": "{{ 'unavailable' }}",
**OPTIMISTIC_ON_OFF_ACTIONS,
},
[STATE_OFF, None, None, None],
[STATE_UNKNOWN, None, None, None],
),
(
ConfigurationStyle.TRIGGER,
@@ -767,7 +777,7 @@ async def test_availability_template_with_entities(hass: HomeAssistant) -> None:
"state": "{{ 'unavailable' }}",
**OPTIMISTIC_ON_OFF_ACTIONS,
},
[STATE_OFF, None, None, None],
[STATE_UNKNOWN, None, None, None],
),
(
ConfigurationStyle.LEGACY,
@@ -858,7 +868,7 @@ async def test_availability_template_with_entities(hass: HomeAssistant) -> None:
"direction_template": "{{ 'right' }}",
**DIRECTION_ACTION,
},
[STATE_OFF, 0, None, None],
[STATE_UNKNOWN, 0, None, None],
),
(
ConfigurationStyle.MODERN,
@@ -871,7 +881,7 @@ async def test_availability_template_with_entities(hass: HomeAssistant) -> None:
"direction": "{{ 'right' }}",
**DIRECTION_ACTION,
},
[STATE_OFF, 0, None, None],
[STATE_UNKNOWN, 0, None, None],
),
(
ConfigurationStyle.TRIGGER,
@@ -884,7 +894,7 @@ async def test_availability_template_with_entities(hass: HomeAssistant) -> None:
"direction": "{{ 'right' }}",
**DIRECTION_ACTION,
},
[STATE_OFF, 0, None, None],
[STATE_UNKNOWN, 0, None, None],
),
],
)