1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-28 04:33:49 +01:00

Add device actions to cover (#28064)

* Add device actions to cover

* Remove toggle action, improve tests

* lint

* lint

* Simplify actions

* Update homeassistant/components/cover/device_action.py

Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>

* Improve tests

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Erik Montnemery
2020-02-28 06:05:43 +01:00
committed by GitHub
parent 223c01d842
commit 3b17e570df
4 changed files with 686 additions and 2 deletions

View File

@@ -3,7 +3,17 @@ Provide a mock cover platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.components.cover import CoverDevice
from homeassistant.components.cover import (
SUPPORT_CLOSE,
SUPPORT_CLOSE_TILT,
SUPPORT_OPEN,
SUPPORT_OPEN_TILT,
SUPPORT_SET_POSITION,
SUPPORT_SET_TILT_POSITION,
SUPPORT_STOP,
SUPPORT_STOP_TILT,
CoverDevice,
)
from tests.common import MockEntity
@@ -18,18 +28,31 @@ def init(empty=False):
[]
if empty
else [
MockCover(name=f"Simple cover", is_on=True, unique_id=f"unique_cover"),
MockCover(
name=f"Simple cover",
is_on=True,
unique_id=f"unique_cover",
supports_tilt=False,
),
MockCover(
name=f"Set position cover",
is_on=True,
unique_id=f"unique_set_pos_cover",
current_cover_position=50,
supports_tilt=False,
),
MockCover(
name=f"Set tilt position cover",
is_on=True,
unique_id=f"unique_set_pos_tilt_cover",
current_cover_tilt_position=50,
supports_tilt=True,
),
MockCover(
name=f"Tilt cover",
is_on=True,
unique_id=f"unique_tilt_cover",
supports_tilt=True,
),
]
)
@@ -59,3 +82,26 @@ class MockCover(MockEntity, CoverDevice):
def current_cover_tilt_position(self):
"""Return current position of cover tilt."""
return self._handle("current_cover_tilt_position")
@property
def supported_features(self):
"""Flag supported features."""
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
if self._handle("supports_tilt"):
supported_features |= (
SUPPORT_OPEN_TILT | SUPPORT_CLOSE_TILT | SUPPORT_STOP_TILT
)
if self.current_cover_position is not None:
supported_features |= SUPPORT_SET_POSITION
if self.current_cover_tilt_position is not None:
supported_features |= (
SUPPORT_OPEN_TILT
| SUPPORT_CLOSE_TILT
| SUPPORT_STOP_TILT
| SUPPORT_SET_TILT_POSITION
)
return supported_features