2021-10-22 18:28:16 +00:00
|
|
|
"""Utility methods for the Tuya integration."""
|
2024-03-08 15:35:23 +00:00
|
|
|
|
2021-10-22 18:28:16 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
def remap_value(
|
2024-04-08 19:29:05 +00:00
|
|
|
value: float,
|
|
|
|
from_min: float = 0,
|
|
|
|
from_max: float = 255,
|
|
|
|
to_min: float = 0,
|
|
|
|
to_max: float = 255,
|
2021-10-22 18:28:16 +00:00
|
|
|
reverse: bool = False,
|
|
|
|
) -> float:
|
|
|
|
"""Remap a value from its current range, to a new range."""
|
|
|
|
if reverse:
|
|
|
|
value = from_max - value + from_min
|
|
|
|
return ((value - from_min) / (from_max - from_min)) * (to_max - to_min) + to_min
|