Move Tuya value scaling into IntegerTypeData (#57757)
This commit is contained in:
parent
19d812602e
commit
6e6313272d
4 changed files with 33 additions and 23 deletions
|
@ -26,6 +26,25 @@ class IntegerTypeData:
|
|||
scale: float
|
||||
step: float
|
||||
|
||||
@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.scale_value(self.step)
|
||||
|
||||
def scale_value(self, value: float | int) -> float:
|
||||
"""Scale a value."""
|
||||
return value * 1.0 / (10 ** self.scale)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, data: str) -> IntegerTypeData:
|
||||
"""Load JSON string and return a IntegerTypeData object."""
|
||||
|
@ -96,8 +115,3 @@ class TuyaEntity(Entity):
|
|||
"Sending commands for device %s: %s", self.tuya_device.id, commands
|
||||
)
|
||||
self.tuya_device_manager.send_commands(self.tuya_device.id, commands)
|
||||
|
||||
@staticmethod
|
||||
def scale(value: float | int, scale: float | int) -> float:
|
||||
"""Scale a value."""
|
||||
return value * 1.0 / (10 ** scale)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue