mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-18 08:00:42 +08:00
style: code style
This commit is contained in:
parent
6d63975eba
commit
7777c4f596
@ -69,9 +69,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry,
|
|||||||
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
|
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
|
||||||
config_entry.entry_id]
|
config_entry.entry_id]
|
||||||
|
|
||||||
# 读取配置参数
|
# Get the cover config params
|
||||||
close_threshold = config_entry.options.get('close_threshold', 3)
|
close_threshold = config_entry.options.get('close_threshold', None)
|
||||||
open_threshold = config_entry.options.get('open_threshold', 95)
|
open_threshold = config_entry.options.get('open_threshold', None)
|
||||||
|
|
||||||
new_entities = []
|
new_entities = []
|
||||||
for miot_device in device_list:
|
for miot_device in device_list:
|
||||||
@ -84,10 +84,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry,
|
|||||||
data.spec.device_class = CoverDeviceClass.SHUTTER
|
data.spec.device_class = CoverDeviceClass.SHUTTER
|
||||||
elif data.spec.name == 'airer':
|
elif data.spec.name == 'airer':
|
||||||
data.spec.device_class = CoverDeviceClass.BLIND
|
data.spec.device_class = CoverDeviceClass.BLIND
|
||||||
new_entities.append(Cover(miot_device=miot_device,
|
new_entities.append(
|
||||||
entity_data=data,
|
Cover(miot_device=miot_device,
|
||||||
close_threshold=close_threshold,
|
entity_data=data,
|
||||||
open_threshold=open_threshold))
|
close_threshold=close_threshold,
|
||||||
|
open_threshold=open_threshold))
|
||||||
|
|
||||||
if new_entities:
|
if new_entities:
|
||||||
async_add_entities(new_entities)
|
async_add_entities(new_entities)
|
||||||
@ -112,11 +113,13 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
_prop_position_value_range: Optional[int]
|
_prop_position_value_range: Optional[int]
|
||||||
_prop_pos_closing: bool
|
_prop_pos_closing: bool
|
||||||
_prop_pos_opening: bool
|
_prop_pos_opening: bool
|
||||||
|
_close_threshold: Optional[int]
|
||||||
|
_open_threshold: Optional[int]
|
||||||
|
|
||||||
def __init__(self, miot_device: MIoTDevice,
|
def __init__(self, miot_device: MIoTDevice,
|
||||||
entity_data: MIoTEntityData,
|
entity_data: MIoTEntityData,
|
||||||
close_threshold: int = 3,
|
close_threshold: int,
|
||||||
open_threshold: int = 95) -> None:
|
open_threshold: int) -> None:
|
||||||
"""Initialize the Cover."""
|
"""Initialize the Cover."""
|
||||||
super().__init__(miot_device=miot_device, entity_data=entity_data)
|
super().__init__(miot_device=miot_device, entity_data=entity_data)
|
||||||
self._attr_device_class = entity_data.spec.device_class
|
self._attr_device_class = entity_data.spec.device_class
|
||||||
@ -140,6 +143,11 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
self._prop_pos_closing = False
|
self._prop_pos_closing = False
|
||||||
self._prop_pos_opening = False
|
self._prop_pos_opening = False
|
||||||
|
|
||||||
|
# Check the validity of the input parameters.
|
||||||
|
if close_threshold is not None and open_threshold is not None:
|
||||||
|
if close_threshold >= open_threshold:
|
||||||
|
close_threshold = None
|
||||||
|
open_threshold = None
|
||||||
self._close_threshold = close_threshold
|
self._close_threshold = close_threshold
|
||||||
self._open_threshold = open_threshold
|
self._open_threshold = open_threshold
|
||||||
|
|
||||||
@ -274,8 +282,16 @@ class Cover(MIoTServiceEntity, CoverEntity):
|
|||||||
self._prop_pos_closing = False
|
self._prop_pos_closing = False
|
||||||
return self.get_prop_value(prop=self._prop_target_position)
|
return self.get_prop_value(prop=self._prop_target_position)
|
||||||
pos = self.get_prop_value(prop=self._prop_current_position)
|
pos = self.get_prop_value(prop=self._prop_current_position)
|
||||||
return None if pos is None else round(pos * 100 /
|
if pos is None:
|
||||||
self._prop_position_value_range)
|
return None
|
||||||
|
percentage = round(pos * 100 / self._prop_position_value_range)
|
||||||
|
if (self._close_threshold is not None) and (percentage
|
||||||
|
<= self._close_threshold):
|
||||||
|
return 0
|
||||||
|
if (self._open_threshold is not None) and (percentage
|
||||||
|
>= self._open_threshold):
|
||||||
|
return 100
|
||||||
|
return percentage
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_opening(self) -> Optional[bool]:
|
def is_opening(self) -> Optional[bool]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user