diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index 9ae3902..9b117fc 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -77,6 +77,7 @@ CONF_FAN_ORDERED_LIST = "fan_speed_ordered_list" CONF_FAN_DIRECTION = "fan_direction" CONF_FAN_DIRECTION_FWD = "fan_direction_forward" CONF_FAN_DIRECTION_REV = "fan_direction_reverse" +CONF_FAN_DPS_TYPE = "fan_dps_type" # sensor CONF_SCALING = "scaling" diff --git a/custom_components/localtuya/fan.py b/custom_components/localtuya/fan.py index d2b4583..584ea84 100644 --- a/custom_components/localtuya/fan.py +++ b/custom_components/localtuya/fan.py @@ -32,6 +32,7 @@ from .const import ( CONF_FAN_SPEED_CONTROL, CONF_FAN_SPEED_MAX, CONF_FAN_SPEED_MIN, + CONF_FAN_DPS_TYPE, ) _LOGGER = logging.getLogger(__name__) @@ -48,6 +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"]), } @@ -73,6 +75,7 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity): ) 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 @@ -138,7 +141,7 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity): await self.async_turn_on() if self._use_ordered_list: await self._device.set_dp( - str( + self._dps_type( percentage_to_ordered_list_item(self._ordered_list, percentage) ), self._config.get(CONF_FAN_SPEED_CONTROL), @@ -151,7 +154,7 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity): else: await self._device.set_dp( - str( + self._dps_type( math.ceil( percentage_to_ranged_value(self._speed_range, percentage) ) @@ -221,7 +224,7 @@ class LocaltuyaFan(LocalTuyaEntity, FanEntity): ) if current_speed is not None: self._percentage = ordered_list_item_to_percentage( - self._ordered_list, current_speed + self._ordered_list, str(current_speed) ) else: diff --git a/custom_components/localtuya/strings.json b/custom_components/localtuya/strings.json index a669d56..25d09fe 100644 --- a/custom_components/localtuya/strings.json +++ b/custom_components/localtuya/strings.json @@ -104,6 +104,7 @@ "fan_direction":"fan direction dps", "fan_direction_forward": "forward dps string", "fan_direction_reverse": "reverse dps string", + "fan_dps_type": "DP value type", "current_temperature_dp": "Current Temperature", "target_temperature_dp": "Target Temperature", "temperature_step": "Temperature Step (optional)", diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index d1da446..2fa8141 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -167,6 +167,7 @@ "fan_direction":"fan direction dps", "fan_direction_forward": "forward dps string", "fan_direction_reverse": "reverse dps string", + "fan_dps_type": "DP value type", "current_temperature_dp": "Current Temperature", "target_temperature_dp": "Target Temperature", "temperature_step": "Temperature Step (optional)",