From 38129f8f5815f91308f384e4318d2bb1d2e2fcdc Mon Sep 17 00:00:00 2001 From: billsq Date: Sat, 30 Sep 2023 22:54:59 +0800 Subject: [PATCH] Fully customize opening/closing texts. The default open/close texts can't differentiate between open/close and opening/closing. Generate a fake middle position when the motor controller is "stopped", to allow Home Assistant GUI to show both open and close buttons. --- custom_components/xiaomi_miot/cover.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/custom_components/xiaomi_miot/cover.py b/custom_components/xiaomi_miot/cover.py index 31ea8541e..515291c47 100644 --- a/custom_components/xiaomi_miot/cover.py +++ b/custom_components/xiaomi_miot/cover.py @@ -108,14 +108,8 @@ async def async_added_to_hass(self): 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 = [ - *(self.custom_config_list('open_texts') or []), - 'Opening', 'Opened', 'Open', 'Up', 'Rising', 'Risen', 'Rise', - ] - self._close_texts = [ - *(self.custom_config_list('close_texts') or []), - 'Closing', 'Closed', 'Close', 'Down', 'Falling', 'Descent', - ] + self._open_texts = self.custom_config_list(key='open_texts', default=['Opening', 'Opened', 'Open', 'Up', 'Rising', 'Risen', 'Rise']) + self._close_texts = self.custom_config_list(key='close_texts', default=['Closing', 'Closed', 'Close', 'Down', 'Falling', 'Descent']) if self._motor_reverse: self._open_texts, self._close_texts = self._close_texts, self._open_texts @@ -170,6 +164,11 @@ def current_cover_position(self): elif range_max != 100: pos = cur / range_max * 100 if pos < 0: + # If the motor controller is stopped, generate fake middle position + if self._prop_status: + sta = int(self._prop_status.from_dict(self._state_attrs) or -1) + if sta in self._prop_status.list_search("Stopped"): + return 50 return None dev = int(self.custom_config_integer('deviated_position', 1) or 0) if pos <= dev: