mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Define CoverEntity entity attributes as class variables (#51236)
* Define CoverEntity entity attributes as class variables * Fix supported features
This commit is contained in:
parent
d66d7cbd37
commit
255e13930c
@ -1,4 +1,6 @@
|
||||
"""Support for Cover devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
@ -167,22 +169,32 @@ async def async_unload_entry(hass, entry):
|
||||
class CoverEntity(Entity):
|
||||
"""Base class for cover entities."""
|
||||
|
||||
_attr_current_cover_position: int | None = None
|
||||
_attr_current_cover_tilt_position: int | None = None
|
||||
_attr_is_closed: bool | None
|
||||
_attr_is_closing: bool | None = None
|
||||
_attr_is_opening: bool | None = None
|
||||
_attr_state: None = None
|
||||
|
||||
@property
|
||||
def current_cover_position(self):
|
||||
def current_cover_position(self) -> int | None:
|
||||
"""Return current position of cover.
|
||||
|
||||
None is unknown, 0 is closed, 100 is fully open.
|
||||
"""
|
||||
return self._attr_current_cover_position
|
||||
|
||||
@property
|
||||
def current_cover_tilt_position(self):
|
||||
def current_cover_tilt_position(self) -> int | None:
|
||||
"""Return current position of cover tilt.
|
||||
|
||||
None is unknown, 0 is closed, 100 is fully open.
|
||||
"""
|
||||
return self._attr_current_cover_tilt_position
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
@final
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the cover."""
|
||||
if self.is_opening:
|
||||
return STATE_OPENING
|
||||
@ -213,8 +225,11 @@ class CoverEntity(Entity):
|
||||
return data
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
if self._attr_supported_features is not None:
|
||||
return self._attr_supported_features
|
||||
|
||||
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
||||
|
||||
if self.current_cover_position is not None:
|
||||
@ -231,17 +246,19 @@ class CoverEntity(Entity):
|
||||
return supported_features
|
||||
|
||||
@property
|
||||
def is_opening(self):
|
||||
def is_opening(self) -> bool | None:
|
||||
"""Return if the cover is opening or not."""
|
||||
return self._attr_is_opening
|
||||
|
||||
@property
|
||||
def is_closing(self):
|
||||
def is_closing(self) -> bool | None:
|
||||
"""Return if the cover is closing or not."""
|
||||
return self._attr_is_closing
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
def is_closed(self) -> bool | None:
|
||||
"""Return if the cover is closed or not."""
|
||||
raise NotImplementedError()
|
||||
return self._attr_is_closed
|
||||
|
||||
def open_cover(self, **kwargs: Any) -> None:
|
||||
"""Open the cover."""
|
||||
|
@ -147,7 +147,7 @@ class ZwaveMotorizedBarrier(ZWaveBaseEntity, CoverEntity):
|
||||
)
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int | None:
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_OPEN | SUPPORT_CLOSE
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user