Bugfix in Tuya Number value scaling (#59903)
This commit is contained in:
parent
329904dfbb
commit
a211b8ca8f
2 changed files with 8 additions and 4 deletions
|
@ -46,6 +46,10 @@ class IntegerTypeData:
|
|||
"""Scale a value."""
|
||||
return value * 1.0 / (10 ** self.scale)
|
||||
|
||||
def scale_value_back(self, value: float | int) -> int:
|
||||
"""Return raw value for scaled."""
|
||||
return int(value * (10 ** self.scale))
|
||||
|
||||
def remap_value_to(
|
||||
self,
|
||||
value: float,
|
||||
|
|
|
@ -259,9 +259,9 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
|
|||
# and determine unit of measurement
|
||||
if self._status_range.type == "Integer":
|
||||
self._type_data = IntegerTypeData.from_json(self._status_range.values)
|
||||
self._attr_max_value = self._type_data.max
|
||||
self._attr_min_value = self._type_data.min
|
||||
self._attr_step = self._type_data.step
|
||||
self._attr_max_value = self._type_data.max_scaled
|
||||
self._attr_min_value = self._type_data.min_scaled
|
||||
self._attr_step = self._type_data.step_scaled
|
||||
if description.unit_of_measurement is None:
|
||||
self._attr_unit_of_measurement = self._type_data.unit
|
||||
|
||||
|
@ -290,7 +290,7 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
|
|||
[
|
||||
{
|
||||
"code": self.entity_description.key,
|
||||
"value": self._type_data.scale_value(value),
|
||||
"value": self._type_data.scale_value_back(value),
|
||||
}
|
||||
]
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue