From cc814e2918631c773a0f82848214123616c5e6d4 Mon Sep 17 00:00:00 2001 From: Zuz666 <109312+Zuz666@users.noreply.github.com> Date: Fri, 28 Jan 2022 05:44:41 +0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=81=20add=20target2current=5Fposition?= =?UTF-8?q?=20for=20lumi.airer.acn01=20(#390)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiaomi_miot/core/device_customizes.py | 3 +++ custom_components/xiaomi_miot/cover.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/custom_components/xiaomi_miot/core/device_customizes.py b/custom_components/xiaomi_miot/core/device_customizes.py index 465945c3a..b21b65156 100644 --- a/custom_components/xiaomi_miot/core/device_customizes.py +++ b/custom_components/xiaomi_miot/core/device_customizes.py @@ -304,6 +304,9 @@ }, ], 'select_properties': 'dry_mode', + 'motor_reverse': False, + 'position_reverse': True, + 'target2current_position': True, }, 'lumi.ctrl_neutral1.*': { 'cloud_delay_update': 10, diff --git a/custom_components/xiaomi_miot/cover.py b/custom_components/xiaomi_miot/cover.py index 9b402ccde..c6a2849a2 100644 --- a/custom_components/xiaomi_miot/cover.py +++ b/custom_components/xiaomi_miot/cover.py @@ -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 = [] @@ -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 = [ @@ -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: @@ -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