Compare commits

...

4 Commits

Author SHA1 Message Date
Li Shuzhen
f7c7754f1f
Merge cfb7c01a44 into 2e60962e94 2025-01-23 11:27:16 +00:00
LiShuzhen
cfb7c01a44 feat: use the closed status to be is_closed property as a backup 2025-01-23 19:26:55 +08:00
LiShuzhen
c40db6608c feat: add airer as cover blind 2025-01-22 16:57:43 +08:00
LiShuzhen
057b7a4ffb feat: add motor-controller as cover shutter 2025-01-22 14:53:59 +08:00
2 changed files with 31 additions and 12 deletions

View File

@ -60,16 +60,16 @@ from homeassistant.components.cover import (
)
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
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback
) -> None:
"""Set up a config entry."""
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
@ -82,6 +82,10 @@ async def async_setup_entry(
data.spec.device_class = CoverDeviceClass.CURTAIN
elif data.spec.name == 'window-opener':
data.spec.device_class = CoverDeviceClass.WINDOW
elif data.spec.name == 'motor-controller':
data.spec.device_class = CoverDeviceClass.SHUTTER
elif data.spec.name == 'airer':
data.spec.device_class = CoverDeviceClass.BLIND
new_entities.append(
Cover(miot_device=miot_device, entity_data=data))
@ -100,6 +104,7 @@ class Cover(MIoTServiceEntity, CoverEntity):
_prop_status_opening: Optional[int]
_prop_status_closing: Optional[int]
_prop_status_stop: Optional[int]
_prop_status_closed: Optional[int]
_prop_current_position: Optional[MIoTSpecProperty]
_prop_target_position: Optional[MIoTSpecProperty]
_prop_position_value_min: Optional[int]
@ -123,6 +128,7 @@ class Cover(MIoTServiceEntity, CoverEntity):
self._prop_status_opening = None
self._prop_status_closing = None
self._prop_status_stop = None
self._prop_status_closed = None
self._prop_current_position = None
self._prop_target_position = None
self._prop_position_value_min = None
@ -137,15 +143,15 @@ class Cover(MIoTServiceEntity, CoverEntity):
'motor-control value_list is None, %s', self.entity_id)
continue
for item in prop.value_list.items:
if item.name in {'open'}:
if item.name in {'open', 'up'}:
self._attr_supported_features |= (
CoverEntityFeature.OPEN)
self._prop_motor_value_open = item.value
elif item.name in {'close'}:
elif item.name in {'close', 'down'}:
self._attr_supported_features |= (
CoverEntityFeature.CLOSE)
self._prop_motor_value_close = item.value
elif item.name in {'pause'}:
elif item.name in {'pause', 'stop'}:
self._attr_supported_features |= (
CoverEntityFeature.STOP)
self._prop_motor_value_pause = item.value
@ -156,12 +162,14 @@ class Cover(MIoTServiceEntity, CoverEntity):
'status value_list is None, %s', self.entity_id)
continue
for item in prop.value_list.items:
if item.name in {'opening', 'open'}:
if item.name in {'opening', 'open', 'up'}:
self._prop_status_opening = item.value
elif item.name in {'closing', 'close'}:
elif item.name in {'closing', 'close', 'down'}:
self._prop_status_closing = item.value
elif item.name in {'stop', 'pause'}:
self._prop_status_stop = item.value
elif item.name in {'closed'}:
self._prop_status_closed = item.value
self._prop_status = prop
elif prop.name == 'current-position':
self._prop_current_position = prop
@ -209,8 +217,10 @@ class Cover(MIoTServiceEntity, CoverEntity):
0: the cover is closed, 100: the cover is fully opened, None: unknown.
"""
if self._prop_current_position is None:
return None
pos = self.get_prop_value(prop=self._prop_current_position)
if pos is None:
if pos is None or self._prop_position_value_range is None:
return None
return round(pos*100/self._prop_position_value_range)
@ -233,4 +243,11 @@ class Cover(MIoTServiceEntity, CoverEntity):
@property
def is_closed(self) -> Optional[bool]:
"""Return if the cover is closed."""
return self.get_prop_value(prop=self._prop_current_position) == 0
if self._prop_current_position:
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

View File

@ -324,7 +324,9 @@ SPEC_SERVICE_TRANS_MAP: dict = {
},
'entity': 'cover'
},
'window-opener': 'curtain'
'window-opener': 'curtain',
'motor-controller': 'curtain',
'airer': 'curtain'
}
"""SPEC_PROP_TRANS_MAP