Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions homeassistant/components/template/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def __init__(
self._optimistic = optimistic or (not state_template and not position_template)
self._tilt_optimistic = tilt_optimistic or not tilt_template
self._position = None
self._is_opening = False
self._is_closing = False
self._tilt_value = None
self._unique_id = unique_id

Expand Down Expand Up @@ -262,6 +264,9 @@ def _update_state(self, result):
self._position = 100
else:
self._position = 0

self._is_opening = state == STATE_OPENING
self._is_closing = state == STATE_CLOSING
else:
_LOGGER.error(
"Received invalid cover is_on state: %s. Expected: %s",
Expand Down Expand Up @@ -321,6 +326,16 @@ def is_closed(self):
"""Return if the cover is closed."""
return self._position == 0

@property
def is_opening(self):
"""Return if the cover is currently opening."""
return self._is_opening

@property
def is_closing(self):
"""Return if the cover is currently closing."""
return self._is_closing

@property
def current_cover_position(self):
"""Return current position of cover.
Expand Down
16 changes: 15 additions & 1 deletion tests/components/template/test_cover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""The tests the cover command line platform."""
"""The tests for the Template cover platform."""
import pytest

from homeassistant import setup
Expand All @@ -15,9 +15,11 @@
SERVICE_TOGGLE,
SERVICE_TOGGLE_COVER_TILT,
STATE_CLOSED,
STATE_CLOSING,
STATE_OFF,
STATE_ON,
STATE_OPEN,
STATE_OPENING,
STATE_UNAVAILABLE,
)

Expand Down Expand Up @@ -74,6 +76,18 @@ async def test_template_state_text(hass, calls):
state = hass.states.get("cover.test_template_cover")
assert state.state == STATE_CLOSED

state = hass.states.async_set("cover.test_state", STATE_OPENING)
await hass.async_block_till_done()

state = hass.states.get("cover.test_template_cover")
assert state.state == STATE_OPENING

state = hass.states.async_set("cover.test_state", STATE_CLOSING)
await hass.async_block_till_done()

state = hass.states.get("cover.test_template_cover")
assert state.state == STATE_CLOSING


async def test_template_state_boolean(hass, calls):
"""Test the value_template attribute."""
Expand Down