feat: set the cover closed position (#1242)

* feat: add the cover closed position configure option

* feat: estimate the cover entity's is_closed property by the cover closed position (#944)

* fix: translations

* feat: set max cover closed position as 5

* docs: modify README

* fix: remove useless spaces
This commit is contained in:
Li Shuzhen
2025-07-14 09:03:54 +08:00
committed by GitHub
parent e09676661c
commit df3faea257
17 changed files with 78 additions and 29 deletions

View File

@ -91,6 +91,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry,
class Cover(MIoTServiceEntity, CoverEntity):
"""Cover entities for Xiaomi Home."""
# pylint: disable=unused-argument
_cover_closed_position: int
_prop_motor_control: Optional[MIoTSpecProperty]
_prop_motor_value_open: Optional[int]
_prop_motor_value_close: Optional[int]
@ -115,6 +116,9 @@ class Cover(MIoTServiceEntity, CoverEntity):
self._attr_supported_color_modes = set()
self._attr_supported_features = CoverEntityFeature(0)
self._cover_closed_position = (
miot_device.miot_client.cover_closed_position)
self._prop_motor_control = None
self._prop_motor_value_open = None
self._prop_motor_value_close = None
@ -297,7 +301,7 @@ class Cover(MIoTServiceEntity, CoverEntity):
def is_closed(self) -> Optional[bool]:
"""Return if the cover is closed."""
if self.current_cover_position is not None:
return self.current_cover_position == 0
return self.current_cover_position <= self._cover_closed_position
# The current position is prior to the status when determining
# whether the cover is closed.
if self._prop_status and self._prop_status_closed: