mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Bugfix in Tuya Number value scaling (#59903)
This commit is contained in:
parent
329904dfbb
commit
a211b8ca8f
@ -46,6 +46,10 @@ class IntegerTypeData:
|
|||||||
"""Scale a value."""
|
"""Scale a value."""
|
||||||
return value * 1.0 / (10 ** self.scale)
|
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(
|
def remap_value_to(
|
||||||
self,
|
self,
|
||||||
value: float,
|
value: float,
|
||||||
|
@ -259,9 +259,9 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
|
|||||||
# and determine unit of measurement
|
# and determine unit of measurement
|
||||||
if self._status_range.type == "Integer":
|
if self._status_range.type == "Integer":
|
||||||
self._type_data = IntegerTypeData.from_json(self._status_range.values)
|
self._type_data = IntegerTypeData.from_json(self._status_range.values)
|
||||||
self._attr_max_value = self._type_data.max
|
self._attr_max_value = self._type_data.max_scaled
|
||||||
self._attr_min_value = self._type_data.min
|
self._attr_min_value = self._type_data.min_scaled
|
||||||
self._attr_step = self._type_data.step
|
self._attr_step = self._type_data.step_scaled
|
||||||
if description.unit_of_measurement is None:
|
if description.unit_of_measurement is None:
|
||||||
self._attr_unit_of_measurement = self._type_data.unit
|
self._attr_unit_of_measurement = self._type_data.unit
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ class TuyaNumberEntity(TuyaEntity, NumberEntity):
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"code": self.entity_description.key,
|
"code": self.entity_description.key,
|
||||||
"value": self._type_data.scale_value(value),
|
"value": self._type_data.scale_value_back(value),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user