Fix cover template entities honoring titlecase True/False (#39803)

This commit is contained in:
J. Nick Koston 2020-09-08 10:08:31 -05:00 committed by Paulus Schoutsen
parent 0d27e10d77
commit fa07787007
3 changed files with 46 additions and 4 deletions

View File

@ -249,15 +249,16 @@ class CoverTemplate(TemplateEntity, CoverEntity):
self._position = None self._position = None
return return
if result in _VALID_STATES: state = result.lower()
if result in ("true", STATE_OPEN): if state in _VALID_STATES:
if state in ("true", STATE_OPEN):
self._position = 100 self._position = 100
else: else:
self._position = 0 self._position = 0
else: else:
_LOGGER.error( _LOGGER.error(
"Received invalid cover is_on state: %s. Expected: %s", "Received invalid cover is_on state: %s. Expected: %s",
result, state,
", ".join(_VALID_STATES), ", ".join(_VALID_STATES),
) )
self._position = None self._position = None

View File

@ -412,7 +412,7 @@ class LightTemplate(TemplateEntity, LightEntity):
self._available = True self._available = True
return return
state = str(result).lower() state = result.lower()
if state in _VALID_STATES: if state in _VALID_STATES:
self._state = state in ("true", STATE_ON) self._state = state in ("true", STATE_ON)
else: else:

View File

@ -1079,3 +1079,44 @@ async def test_unique_id(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 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