Move Tuya value scaling into IntegerTypeData (#57757)

This commit is contained in:
Franck Nijhof 2021-10-15 10:33:20 +02:00 committed by GitHub
parent 19d812602e
commit 6e6313272d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 23 deletions

View file

@ -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)