Skip to content

Commit

Permalink
Remove fan dps type
Browse files Browse the repository at this point in the history
The order list should be always a list of speeds which will always will be sent as string, otherwise set rely on min/max and send as intgeer.
  • Loading branch information
xZetsubou committed Aug 30, 2024
1 parent 5917d34 commit 8394bb5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions custom_components/localtuya/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def flow_schema(dps):
vol.Optional(CONF_FAN_SPEED_MIN, default=1): cv.positive_int,
vol.Optional(CONF_FAN_SPEED_MAX, default=9): cv.positive_int,
vol.Optional(CONF_FAN_ORDERED_LIST, default="disabled"): cv.string,
vol.Optional(CONF_FAN_DPS_TYPE, default="str"): vol.In(["str", "int"]),
# vol.Optional(CONF_FAN_DPS_TYPE, default="str"): vol.In(["str", "int"]),
}


Expand All @@ -74,21 +74,11 @@ def __init__(
self._config.get(CONF_FAN_SPEED_MAX),
)
self._ordered_list = self._config.get(CONF_FAN_ORDERED_LIST).split(",")
self._ordered_list_mode = None
self._dps_type = int if self._config.get(CONF_FAN_DPS_TYPE) == "int" else str

if isinstance(self._ordered_list, list) and len(self._ordered_list) > 1:
self._use_ordered_list = True
# Assuming that the ordered list cannot be "int" type.
self._dps_type = str
_LOGGER.debug(
"Fan _use_ordered_list: %s > %s",
self._use_ordered_list,
self._ordered_list,
)
else:
self._use_ordered_list = False
_LOGGER.debug("Fan _use_ordered_list: %s", self._use_ordered_list)

@property
def oscillating(self):
Expand Down Expand Up @@ -141,9 +131,10 @@ async def async_set_percentage(self, percentage):
return await self.async_turn_off()
if not self.is_on:
await self.async_turn_on()

if self._use_ordered_list:
await self._device.set_dp(
self._dps_type(
str(
percentage_to_ordered_list_item(self._ordered_list, percentage)
),
self._config.get(CONF_FAN_SPEED_CONTROL),
Expand All @@ -153,10 +144,9 @@ async def async_set_percentage(self, percentage):
percentage,
percentage_to_ordered_list_item(self._ordered_list, percentage),
)

else:
await self._device.set_dp(
self._dps_type(
int(
math.ceil(
percentage_to_ranged_value(self._speed_range, percentage)
)
Expand Down

0 comments on commit 8394bb5

Please sign in to comment.