Skip to content

Commit fdf69fc

Browse files
authored
Improve calculating supported features in template light (#139339)
1 parent e403bee commit fdf69fc

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

homeassistant/components/template/light.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def _update_supports_transition(self, render):
10131013
if render in (None, "None", ""):
10141014
self._supports_transition = False
10151015
return
1016-
self._attr_supported_features &= LightEntityFeature.EFFECT
1016+
self._attr_supported_features &= ~LightEntityFeature.TRANSITION
10171017
self._supports_transition = bool(render)
10181018
if self._supports_transition:
10191019
self._attr_supported_features |= LightEntityFeature.TRANSITION

tests/components/template/test_light.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,60 @@ async def test_supports_transition_template(
18471847
) != expected_value
18481848

18491849

1850+
@pytest.mark.parametrize("count", [1])
1851+
async def test_supports_transition_template_updates(
1852+
hass: HomeAssistant, count: int
1853+
) -> None:
1854+
"""Test the template for the supports transition dynamically."""
1855+
light_config = {
1856+
"test_template_light": {
1857+
"value_template": "{{ 1 == 1 }}",
1858+
"turn_on": {"service": "light.turn_on", "entity_id": "light.test_state"},
1859+
"turn_off": {"service": "light.turn_off", "entity_id": "light.test_state"},
1860+
"set_temperature": {
1861+
"service": "light.turn_on",
1862+
"data_template": {
1863+
"entity_id": "light.test_state",
1864+
"color_temp": "{{color_temp}}",
1865+
},
1866+
},
1867+
"set_effect": {
1868+
"service": "test.automation",
1869+
"data_template": {
1870+
"entity_id": "test.test_state",
1871+
"effect": "{{effect}}",
1872+
},
1873+
},
1874+
"effect_list_template": "{{ ['Disco', 'Police'] }}",
1875+
"effect_template": "{{ None }}",
1876+
"supports_transition_template": "{{ states('sensor.test') }}",
1877+
}
1878+
}
1879+
await async_setup_light(hass, count, light_config)
1880+
state = hass.states.get("light.test_template_light")
1881+
assert state is not None
1882+
1883+
hass.states.async_set("sensor.test", 0)
1884+
await hass.async_block_till_done()
1885+
state = hass.states.get("light.test_template_light")
1886+
supported_features = state.attributes.get("supported_features")
1887+
assert supported_features == LightEntityFeature.EFFECT
1888+
1889+
hass.states.async_set("sensor.test", 1)
1890+
await hass.async_block_till_done()
1891+
state = hass.states.get("light.test_template_light")
1892+
supported_features = state.attributes.get("supported_features")
1893+
assert (
1894+
supported_features == LightEntityFeature.TRANSITION | LightEntityFeature.EFFECT
1895+
)
1896+
1897+
hass.states.async_set("sensor.test", 0)
1898+
await hass.async_block_till_done()
1899+
state = hass.states.get("light.test_template_light")
1900+
supported_features = state.attributes.get("supported_features")
1901+
assert supported_features == LightEntityFeature.EFFECT
1902+
1903+
18501904
@pytest.mark.parametrize("count", [1])
18511905
@pytest.mark.parametrize(
18521906
"light_config",

0 commit comments

Comments
 (0)