1 """Scaling util functions."""
3 from __future__
import annotations
7 source_low_high_range: tuple[float, float],
8 target_low_high_range: tuple[float, float],
11 """Given a range of low and high values convert a single value to another range.
13 Given a source low value of 1 and a high value of 255 and
14 a target range from 1 to 100 this function
17 (1,255), (1,100), 255: 100
18 (1,255), (1,100), 127: 49
19 (1,255), (1,100), 10: 3
21 source_offset = source_low_high_range[0] - 1
22 target_offset = target_low_high_range[0] - 1
24 (value - source_offset)
32 source_low_high_range: tuple[float, float],
33 target_low_high_range: tuple[float, float],
36 """Given a range of low and high values convert a single value to another range.
38 Do not include 0 in a range if 0 means off,
39 e.g. for brightness or fan speed.
41 Given a source low value of 1 and a high value of 255 and
42 a target range from 1 to 100 this function
46 (1,255), 127: ~49.8039
49 source_offset = source_low_high_range[0] - 1
50 target_offset = target_low_high_range[0] - 1
51 return (value - source_offset) * (
57 """Given a range of low and high values return how many states exist."""
58 return low_high_range[1] - low_high_range[0] + 1
62 """Given a range of low and high values return how many integer states exist."""
int scale_ranged_value_to_int_range(tuple[float, float] source_low_high_range, tuple[float, float] target_low_high_range, float value)
int int_states_in_range(tuple[float, float] low_high_range)
float scale_to_ranged_value(tuple[float, float] source_low_high_range, tuple[float, float] target_low_high_range, float value)
float states_in_range(tuple[float, float] low_high_range)