diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index c940304..5dea150 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -73,6 +73,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..80743df 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 4db7e70..0de4543 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 82f4064..909a69c 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -165,6 +165,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)",