mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 15:41:15 +08:00
feat: use the closed status to be is_closed property as a backup
This commit is contained in:
parent
c40db6608c
commit
cfb7c01a44
@ -60,16 +60,16 @@ from homeassistant.components.cover import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .miot.miot_spec import MIoTSpecProperty
|
from .miot.miot_spec import MIoTSpecProperty
|
||||||
from .miot.miot_device import MIoTDevice, MIoTEntityData, MIoTServiceEntity
|
from .miot.miot_device import MIoTDevice, MIoTEntityData, MIoTServiceEntity
|
||||||
from .miot.const import DOMAIN
|
from .miot.const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
|
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
|
||||||
@ -104,6 +104,7 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
_prop_status_opening: Optional[int]
|
_prop_status_opening: Optional[int]
|
||||||
_prop_status_closing: Optional[int]
|
_prop_status_closing: Optional[int]
|
||||||
_prop_status_stop: Optional[int]
|
_prop_status_stop: Optional[int]
|
||||||
|
_prop_status_closed: Optional[int]
|
||||||
_prop_current_position: Optional[MIoTSpecProperty]
|
_prop_current_position: Optional[MIoTSpecProperty]
|
||||||
_prop_target_position: Optional[MIoTSpecProperty]
|
_prop_target_position: Optional[MIoTSpecProperty]
|
||||||
_prop_position_value_min: Optional[int]
|
_prop_position_value_min: Optional[int]
|
||||||
@ -127,6 +128,7 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
self._prop_status_opening = None
|
self._prop_status_opening = None
|
||||||
self._prop_status_closing = None
|
self._prop_status_closing = None
|
||||||
self._prop_status_stop = None
|
self._prop_status_stop = None
|
||||||
|
self._prop_status_closed = None
|
||||||
self._prop_current_position = None
|
self._prop_current_position = None
|
||||||
self._prop_target_position = None
|
self._prop_target_position = None
|
||||||
self._prop_position_value_min = None
|
self._prop_position_value_min = None
|
||||||
@ -166,6 +168,8 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
self._prop_status_closing = item.value
|
self._prop_status_closing = item.value
|
||||||
elif item.name in {'stop', 'pause'}:
|
elif item.name in {'stop', 'pause'}:
|
||||||
self._prop_status_stop = item.value
|
self._prop_status_stop = item.value
|
||||||
|
elif item.name in {'closed'}:
|
||||||
|
self._prop_status_closed = item.value
|
||||||
self._prop_status = prop
|
self._prop_status = prop
|
||||||
elif prop.name == 'current-position':
|
elif prop.name == 'current-position':
|
||||||
self._prop_current_position = prop
|
self._prop_current_position = prop
|
||||||
@ -239,6 +243,11 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
@property
|
@property
|
||||||
def is_closed(self) -> Optional[bool]:
|
def is_closed(self) -> Optional[bool]:
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
if self._prop_current_position is None:
|
if self._prop_current_position:
|
||||||
return None
|
return self.get_prop_value(prop=self._prop_current_position) == 0
|
||||||
return self.get_prop_value(prop=self._prop_current_position) == 0
|
# The current position is prior to the status when determining
|
||||||
|
# whether the cover is closed.
|
||||||
|
return (self.get_prop_value(
|
||||||
|
prop=self._prop_status) == self._prop_status_closed) if (
|
||||||
|
self._prop_status
|
||||||
|
and self._prop_status_closed is not None) else None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user