Skip to content

Commit

Permalink
Handle empty range for tuya fan (#341)
Browse files Browse the repository at this point in the history
* Handle empty range for tuya fan

* Update custom_components/localtuya/core/ha_entities/__init__.py

Co-authored-by: Bander <[email protected]>

* return empty list instead of empty string

---------

Co-authored-by: Bander <[email protected]>
  • Loading branch information
chpeck and xZetsubou authored Aug 28, 2024
1 parent 13f0af8 commit 14787e2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custom_components/localtuya/core/ha_entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ def get_dp_values(dp: str, dps_data: dict, req_info: CLOUD_VALUE = None) -> dict

# ENUM Values: range: list of values.
if dp_values and dp_type == DPType.ENUM:
dp_values["min"] = dp_values.get("range", [])[0] # first value
dp_values["max"] = dp_values.get("range", [])[-1] # Last value
dp_values["range"] = convert_list(dp_values.get("range"), req_info)
range_values = dp_values.get("range", [])

dp_values["min"] = range_values[0] if range_values else 0 # first value
dp_values["max"] = range_values[-1] if range_values else 0 # Last value
dp_values["range"] = convert_list(range_values, req_info)
return dp_values

# Sensors don't have type
Expand All @@ -251,7 +253,7 @@ def scale(value: int, scale: int, _type: type = int) -> float:
def convert_list(_list: list, req_info: CLOUD_VALUE = str):
"""Return list to dict values."""
if not _list:
return ""
return []

prefer_type = req_info.prefer_type

Expand Down

0 comments on commit 14787e2

Please sign in to comment.