1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-20 02:48:57 +00:00

Make min/max/step attributes of Tuya device wrapper (#159116)

This commit is contained in:
epenet
2025-12-15 17:27:13 +01:00
committed by GitHub
parent c09c016299
commit 245d57be1a
6 changed files with 14 additions and 36 deletions

View File

@@ -361,11 +361,9 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
# it to define min, max & step temperatures
if self._set_temperature:
self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
self._attr_max_temp = self._set_temperature.type_information.max_scaled
self._attr_min_temp = self._set_temperature.type_information.min_scaled
self._attr_target_temperature_step = (
self._set_temperature.type_information.step_scaled
)
self._attr_max_temp = self._set_temperature.max_value
self._attr_min_temp = self._set_temperature.min_value
self._attr_target_temperature_step = self._set_temperature.value_step
# Determine HVAC modes
self._attr_hvac_modes: list[HVACMode] = []
@@ -394,12 +392,8 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
# Determine dpcode to use for setting the humidity
if target_humidity_wrapper:
self._attr_supported_features |= ClimateEntityFeature.TARGET_HUMIDITY
self._attr_min_humidity = round(
target_humidity_wrapper.type_information.min_scaled
)
self._attr_max_humidity = round(
target_humidity_wrapper.type_information.max_scaled
)
self._attr_min_humidity = round(target_humidity_wrapper.min_value)
self._attr_max_humidity = round(target_humidity_wrapper.max_value)
# Determine fan modes
if fan_mode_wrapper:

View File

@@ -153,12 +153,8 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
# Determine humidity parameters
if target_humidity_wrapper:
self._attr_min_humidity = round(
target_humidity_wrapper.type_information.min_scaled
)
self._attr_max_humidity = round(
target_humidity_wrapper.type_information.max_scaled
)
self._attr_min_humidity = round(target_humidity_wrapper.min_value)
self._attr_max_humidity = round(target_humidity_wrapper.max_value)
# Determine mode support and provided modes
if mode_wrapper:

View File

@@ -596,7 +596,7 @@ def _get_color_data_wrapper(
elif (
description.fallback_color_data_mode == FallbackColorDataMode.V2
or color_data_wrapper.dpcode == DPCode.COLOUR_DATA_V2
or (brightness_wrapper and brightness_wrapper.type_information.max > 255)
or (brightness_wrapper and brightness_wrapper.max_value > 255)
):
color_data_wrapper.h_type = DEFAULT_H_TYPE_V2
color_data_wrapper.s_type = DEFAULT_S_TYPE_V2

View File

@@ -154,6 +154,9 @@ class DPCodeIntegerWrapper(DPCodeTypeInformationWrapper[IntegerTypeInformation])
"""Init DPCodeIntegerWrapper."""
super().__init__(dpcode, type_information)
self.native_unit = type_information.unit
self.min_value = self.type_information.scale_value(type_information.min)
self.max_value = self.type_information.scale_value(type_information.max)
self.value_step = self.type_information.scale_value(type_information.step)
def _convert_value_to_raw_value(self, device: CustomerDevice, value: Any) -> Any:
"""Convert a Home Assistant value back to a raw device value."""

View File

@@ -496,9 +496,9 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
self._attr_unique_id = f"{super().unique_id}{description.key}"
self._dpcode_wrapper = dpcode_wrapper
self._attr_native_max_value = dpcode_wrapper.type_information.max_scaled
self._attr_native_min_value = dpcode_wrapper.type_information.min_scaled
self._attr_native_step = dpcode_wrapper.type_information.step_scaled
self._attr_native_max_value = dpcode_wrapper.max_value
self._attr_native_min_value = dpcode_wrapper.min_value
self._attr_native_step = dpcode_wrapper.value_step
if description.native_unit_of_measurement is None:
self._attr_native_unit_of_measurement = dpcode_wrapper.native_unit

View File

@@ -200,21 +200,6 @@ class IntegerTypeInformation(TypeInformation[float]):
step: int
unit: str | None = None
@property
def max_scaled(self) -> float:
"""Return the max scaled."""
return self.scale_value(self.max)
@property
def min_scaled(self) -> float:
"""Return the min scaled."""
return self.scale_value(self.min)
@property
def step_scaled(self) -> float:
"""Return the step scaled."""
return self.step / (10**self.scale)
def scale_value(self, value: int) -> float:
"""Scale a value."""
return value / (10**self.scale)