mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix cover template entities honoring titlecase True/False (#39803)
This commit is contained in:
parent
0d27e10d77
commit
fa07787007
@ -249,15 +249,16 @@ class CoverTemplate(TemplateEntity, CoverEntity):
|
||||
self._position = None
|
||||
return
|
||||
|
||||
if result in _VALID_STATES:
|
||||
if result in ("true", STATE_OPEN):
|
||||
state = result.lower()
|
||||
if state in _VALID_STATES:
|
||||
if state in ("true", STATE_OPEN):
|
||||
self._position = 100
|
||||
else:
|
||||
self._position = 0
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Received invalid cover is_on state: %s. Expected: %s",
|
||||
result,
|
||||
state,
|
||||
", ".join(_VALID_STATES),
|
||||
)
|
||||
self._position = None
|
||||
|
@ -412,7 +412,7 @@ class LightTemplate(TemplateEntity, LightEntity):
|
||||
self._available = True
|
||||
return
|
||||
|
||||
state = str(result).lower()
|
||||
state = result.lower()
|
||||
if state in _VALID_STATES:
|
||||
self._state = state in ("true", STATE_ON)
|
||||
else:
|
||||
|
@ -1079,3 +1079,44 @@ async def test_unique_id(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
|
||||
async def test_state_gets_lowercased(hass):
|
||||
"""Test True/False is lowercased."""
|
||||
|
||||
hass.states.async_set("binary_sensor.garage_door_sensor", "off")
|
||||
|
||||
await setup.async_setup_component(
|
||||
hass,
|
||||
"cover",
|
||||
{
|
||||
"cover": {
|
||||
"platform": "template",
|
||||
"covers": {
|
||||
"garage_door": {
|
||||
"friendly_name": "Garage Door",
|
||||
"value_template": "{{ is_state('binary_sensor.garage_door_sensor', 'off') }}",
|
||||
"open_cover": {
|
||||
"service": "cover.open_cover",
|
||||
"entity_id": "cover.test_state",
|
||||
},
|
||||
"close_cover": {
|
||||
"service": "cover.close_cover",
|
||||
"entity_id": "cover.test_state",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 2
|
||||
|
||||
assert hass.states.get("cover.garage_door").state == STATE_OPEN
|
||||
hass.states.async_set("binary_sensor.garage_door_sensor", "on")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("cover.garage_door").state == STATE_CLOSED
|
||||
|
Loading…
x
Reference in New Issue
Block a user