aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-11-03 01:49:03 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-11-03 01:49:03 +0000
commite827b179836ce21ac2afcbe158c4de3d6965b329 (patch)
tree991844b30327f788364d92b538c046ef7da62fc0 /main.py
parentbe6cd32fbe911255764bf0d5dffaf7f5d7d8c1dd (diff)
downloaduni-sync-temp-timer-master.tar.gz
uni-sync-temp-timer-master.tar.bz2
uni-sync-temp-timer-master.zip
v2.1.1: Code cleanupmaster
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/main.py b/main.py
index 93f85f0..fd5c783 100755
--- a/main.py
+++ b/main.py
@@ -66,21 +66,27 @@ class TempCurve:
(low_temp, low_speed) = self.points[lower]
(high_temp, high_speed) = self.points[lower + 1]
- return floor(low_speed + (((temp - low_temp) / (high_temp - low_temp)) * (high_speed - low_speed)))
+ coefficient = (temp - low_temp) / (high_temp - low_temp)
+ value = low_speed + (coefficient * (high_speed - low_speed))
+
+ return floor(value)
+
def read_curves(path: str) -> [TempCurve]:
+ def read_points(obj):
+ return [(i["temp"], i["speed"]) for i in obj["curve"]]
curves = []
with open(path, "r") as fp:
json = load(fp)
- for obj in json:
- curves.append(TempCurve(obj["sensor"], obj["channel"],
- [(i["temp"], i["speed"])
- for i in obj["curve"]]))
+ curves = [
+ TempCurve(obj["sensor"], obj["channel"], read_points(obj))
+ for obj in json
+ ]
return curves
def compile_unisync(curves: [TempCurve]):
- # Setup the version of curves we want
+ # Compile curves into something to fit into the uni-sync config
indexed_curves = dict()
for curve in curves:
indexed_curves[curve.channel] = curve.current_speed
@@ -93,6 +99,8 @@ def compile_unisync(curves: [TempCurve]):
current_config = None
with open(UNI_SYNC_FILEPATH, "r") as fp:
current_config = load(fp)
+
+ # inject compiled_curves into the configuration
current_config["configs"][0]["channels"] = compiled_curves
return current_config
@@ -102,7 +110,7 @@ def run_unisync():
if __name__ == '__main__':
curves = read_curves(PROFILE_FILEPATH)
for curve in curves:
- print(f"Channel [{curve.channel}]: Sensor={curve.sensor} => Speed={curve.current_speed} based on {curve.current_temp}")
+ print(f"[{curve.channel}] {curve.sensor}: {curve.current_temp}°C => {curve.current_speed}%")
new_config = compile_unisync(curves)
with open(UNI_SYNC_FILEPATH, "w") as fp:
dump(new_config, fp)