Cover entity
Cover entity 控制 opening 或 cover,例如 garage door 或 window shade。从 homeassistant.components.cover.CoverEntity 派生 platform entity。
Note
Cover entity 应仅用于控制 opening 或 cover 的 devices。
对于其他类型的 device entities(如 Number),应改用它们,即使过去并非如此。
属性
Tip
Properties 应该只从内存返回信息,而不要执行 I/O(如网络请求)。请实现 update() 或 async_update() 来获取数据。
状态
State 通过设置上述 properties 来定义。Resulting state 使用 CoverState enum 返回以下成员之一。
设备类型
支持的功能
Supported features 通过使用 CoverEntityFeature enum 中的值来定义,
并使用按位或(|)运算符组合。
方法
打开
仅当设置了 CoverEntityFeature.OPEN 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
关闭
仅当设置了 CoverEntityFeature.CLOSE 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def close_cover(self, **kwargs: Any) -> None:
"""Close cover."""
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close cover."""
设置位置
仅当设置了 CoverEntityFeature.SET_POSITION 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
停止
仅当设置了 CoverEntityFeature.STOP 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
打开 tilt
仅当设置了 CoverEntityFeature.OPEN_TILT 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the cover tilt."""
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the cover tilt."""
关闭 tilt
仅当设置了 CoverEntityFeature.CLOSE_TILT 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the cover tilt."""
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the cover tilt."""
设置 tilt 位置
仅当设置了 CoverEntityFeature.SET_TILT_POSITION 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def set_cover_tilt_position(self, **kwargs: Any) -> None:
"""Move the cover tilt to a specific position."""
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
"""Move the cover tilt to a specific position."""
停止 tilt
仅当设置了 CoverEntityFeature.STOP_TILT 标志时,才实现此 method。
class MyCover(CoverEntity):
# 实现以下方法之一。
def stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop the cover."""
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop the cover."""