Skip to content

Commit

Permalink
🕹️ add option descriptions_for_off (#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Mar 15, 2024
1 parent cfa696c commit 5f51e9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ def get_customize_options(hass, options={}, bool2selects=[], entity_id='', model
bool2selects.extend(['reverse_state'])
options.update({
'descriptions_for_on': cv.string,
'descriptions_for_off': cv.string,
'stat_power_cost_key': cv.string,
'stat_power_cost_type': cv.string,
})
Expand Down
10 changes: 5 additions & 5 deletions custom_components/xiaomi_miot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def turn_on(self, **kwargs):
val = self._miot_property.range_max()
if self._miot_property.value_list:
ret = self._miot_property.list_first(*self._on_descriptions)
if ret is not None:
val = ret
val = 1 if ret is None else ret
elif self._miot_property.value_range:
val = self._miot_property.range_max()
if self._reverse_state:
Expand All @@ -175,9 +174,10 @@ def turn_off(self, **kwargs):
if self._miot_property.value_range:
val = self._miot_property.range_min()
if self._miot_property.value_list:
ret = self._miot_property.list_first('Off', 'Close', 'Closed', '关')
if ret is not None:
val = ret
if not (des := self.custom_config_list('descriptions_for_off')):
des = ['Off', 'Close', 'Closed', '关', '关闭']
ret = self._miot_property.list_first(*des)
val = 0 if ret is None else ret
elif self._miot_property.value_range:
val = self._miot_property.range_min()
if self._reverse_state:
Expand Down
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"cover_properties": "cover_properties",
"current_temp_property": "current_temp_property",
"descriptions_for_on": "descriptions_for_on",
"descriptions_for_off": "descriptions_for_off",
"deviated_position": "deviated_position",
"device_class": "device_class",
"disable_location_name": "disable_location_name",
Expand Down

0 comments on commit 5f51e9d

Please sign in to comment.