mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Fix scaling of numeric Tuya values (#66644)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
4051e2f518
commit
dbc445c2fa
@ -41,15 +41,15 @@ class IntegerTypeData:
|
|||||||
@property
|
@property
|
||||||
def step_scaled(self) -> float:
|
def step_scaled(self) -> float:
|
||||||
"""Return the step scaled."""
|
"""Return the step scaled."""
|
||||||
return self.scale_value(self.step)
|
return self.step / (10**self.scale)
|
||||||
|
|
||||||
def scale_value(self, value: float | int) -> float:
|
def scale_value(self, value: float | int) -> float:
|
||||||
"""Scale a value."""
|
"""Scale a value."""
|
||||||
return value * 1.0 / (10**self.scale)
|
return value * self.step / (10**self.scale)
|
||||||
|
|
||||||
def scale_value_back(self, value: float | int) -> int:
|
def scale_value_back(self, value: float | int) -> int:
|
||||||
"""Return raw value for scaled."""
|
"""Return raw value for scaled."""
|
||||||
return int(value * (10**self.scale))
|
return int((value * (10**self.scale)) / self.step)
|
||||||
|
|
||||||
def remap_value_to(
|
def remap_value_to(
|
||||||
self,
|
self,
|
||||||
@ -82,7 +82,7 @@ class IntegerTypeData:
|
|||||||
min=int(parsed["min"]),
|
min=int(parsed["min"]),
|
||||||
max=int(parsed["max"]),
|
max=int(parsed["max"]),
|
||||||
scale=float(parsed["scale"]),
|
scale=float(parsed["scale"]),
|
||||||
step=float(parsed["step"]),
|
step=max(float(parsed["step"]), 1),
|
||||||
unit=parsed.get("unit"),
|
unit=parsed.get("unit"),
|
||||||
type=parsed.get("type"),
|
type=parsed.get("type"),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user