Skip to content

Commit 5f51e9d

Browse files
committed
🕹️ add option descriptions_for_off (#1503)
1 parent cfa696c commit 5f51e9d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

custom_components/xiaomi_miot/config_flow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ def get_customize_options(hass, options={}, bool2selects=[], entity_id='', model
713713
bool2selects.extend(['reverse_state'])
714714
options.update({
715715
'descriptions_for_on': cv.string,
716+
'descriptions_for_off': cv.string,
716717
'stat_power_cost_key': cv.string,
717718
'stat_power_cost_type': cv.string,
718719
})

custom_components/xiaomi_miot/switch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ def turn_on(self, **kwargs):
162162
val = self._miot_property.range_max()
163163
if self._miot_property.value_list:
164164
ret = self._miot_property.list_first(*self._on_descriptions)
165-
if ret is not None:
166-
val = ret
165+
val = 1 if ret is None else ret
167166
elif self._miot_property.value_range:
168167
val = self._miot_property.range_max()
169168
if self._reverse_state:
@@ -175,9 +174,10 @@ def turn_off(self, **kwargs):
175174
if self._miot_property.value_range:
176175
val = self._miot_property.range_min()
177176
if self._miot_property.value_list:
178-
ret = self._miot_property.list_first('Off', 'Close', 'Closed', '关')
179-
if ret is not None:
180-
val = ret
177+
if not (des := self.custom_config_list('descriptions_for_off')):
178+
des = ['Off', 'Close', 'Closed', '关', '关闭']
179+
ret = self._miot_property.list_first(*des)
180+
val = 0 if ret is None else ret
181181
elif self._miot_property.value_range:
182182
val = self._miot_property.range_min()
183183
if self._reverse_state:

custom_components/xiaomi_miot/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"cover_properties": "cover_properties",
7272
"current_temp_property": "current_temp_property",
7373
"descriptions_for_on": "descriptions_for_on",
74+
"descriptions_for_off": "descriptions_for_off",
7475
"deviated_position": "deviated_position",
7576
"device_class": "device_class",
7677
"disable_location_name": "disable_location_name",

0 commit comments

Comments
 (0)