Skip to content

Commit

Permalink
🔁 add target2current_position for lumi.airer.acn01 (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuz666 authored Jan 28, 2022
1 parent 993fd7d commit cc814e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/xiaomi_miot/core/device_customizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@
},
],
'select_properties': 'dry_mode',
'motor_reverse': False,
'position_reverse': True,
'target2current_position': True,
},
'lumi.ctrl_neutral1.*': {
'cloud_delay_update': 10,
Expand Down
11 changes: 11 additions & 0 deletions custom_components/xiaomi_miot/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __init__(self, config: dict, miot_service: MiotService):

self._motor_reverse = False
self._position_reverse = False
self._target2current = False
self._open_texts = []
self._close_texts = []

Expand All @@ -100,6 +101,11 @@ async def async_added_to_hass(self):
self._prop_target_position = None
if self._prop_motor_control.list_first('Pause', 'Stop') is not None:
self._supported_features |= SUPPORT_STOP

self._target2current = self.custom_config('target2current_position')
if self._target2current:
self._prop_current_position = self._prop_target_position

self._motor_reverse = self.custom_config_bool('motor_reverse', False)
self._position_reverse = self.custom_config_bool('position_reverse', self._motor_reverse)
self._open_texts = [
Expand Down Expand Up @@ -187,6 +193,8 @@ def target_cover_position(self):

def set_cover_position(self, **kwargs):
pos = round(kwargs.get(ATTR_POSITION) or 0)
if self._position_reverse and self._target2current:
pos = 100 - pos
srv = self._miot_service
for p in srv.get_properties('target_position'):
if not p.value_range:
Expand Down Expand Up @@ -279,7 +287,10 @@ def current_cover_position(self):
val = round(self._miot_property.from_dict(self._state_attrs) or -1, 2)
top = self._miot_property.range_max()
return round(val / top * 100)

prop = self._miot_service.get_property('current_position')
if self.custom_config('target2current_position'):
prop = self._miot_service.get_property('target_position') or prop
if prop:
return round(prop.from_dict(self._state_attrs) or -1)
return None
Expand Down

0 comments on commit cc814e2

Please sign in to comment.