Fix scaling of numeric Tuya values (#66644)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
4051e2f518
commit
dbc445c2fa
1 changed files with 4 additions and 4 deletions
|
@ -41,15 +41,15 @@ class IntegerTypeData:
|
|||
@property
|
||||
def step_scaled(self) -> float:
|
||||
"""Return the step scaled."""
|
||||
return self.scale_value(self.step)
|
||||
return self.step / (10**self.scale)
|
||||
|
||||
def scale_value(self, value: float | int) -> float:
|
||||
"""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:
|
||||
"""Return raw value for scaled."""
|
||||
return int(value * (10**self.scale))
|
||||
return int((value * (10**self.scale)) / self.step)
|
||||
|
||||
def remap_value_to(
|
||||
self,
|
||||
|
@ -82,7 +82,7 @@ class IntegerTypeData:
|
|||
min=int(parsed["min"]),
|
||||
max=int(parsed["max"]),
|
||||
scale=float(parsed["scale"]),
|
||||
step=float(parsed["step"]),
|
||||
step=max(float(parsed["step"]), 1),
|
||||
unit=parsed.get("unit"),
|
||||
type=parsed.get("type"),
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue