From c6c243773204dce0b2f541a12ee3b2a0ad047de9 Mon Sep 17 00:00:00 2001 From: nessi Date: Sun, 16 Aug 2026 20:13:34 +0200 Subject: [PATCH] refactor: prioritize Temperature_Celsius raw value extraction before unit-based parsing in SMART temperature detection Swap Temperature_Celsius to first position in ordered list before Current Drive Temperature/Drive Temperature/Temperature: patterns. Add Temperature_Celsius.*-\s*(-?\d{1,3}) regex to extract raw value from attribute line with 0-150 range validation before falling back to explicit unit pattern matching to improve accuracy when both formatted and raw temperature values are present --- app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 64b22c5..7ce4909 100644 --- a/app.py +++ b/app.py @@ -362,10 +362,13 @@ def smart_temperature(device): # Seagate and similar drives often expose both Airflow_Temperature # and Temperature_Celsius. Prefer the latter because it is the # physical drive temperature shown by the usual terminal command. - ordered = [line for line in lines if re.search(r"Current Drive Temperature|Drive Temperature|^\s*Temperature:\s*", line, re.IGNORECASE)] - ordered += [line for line in lines if line not in ordered and re.search(r"Temperature_Celsius", line, re.IGNORECASE)] + ordered = [line for line in lines if re.search(r"Temperature_Celsius", line, re.IGNORECASE)] + ordered += [line for line in lines if line not in ordered and re.search(r"Current Drive Temperature|Drive Temperature|^\s*Temperature:\s*", line, re.IGNORECASE)] ordered += [line for line in lines if line not in ordered and re.search(r"temperature|airflow", line, re.IGNORECASE)] for line in ordered: + raw_temperature = re.search(r"Temperature_Celsius.*-\s*(-?\d{1,3})\s*(?:\([^)]*\))?\s*$", line, re.IGNORECASE) + if raw_temperature and 0 < int(raw_temperature.group(1)) < 150: + return f"{int(raw_temperature.group(1))} °C" explicit = re.search(r"(\d{1,3})\s*(?:°\s*C|Celsius|degrees?\s*C)\b", line, re.IGNORECASE) if explicit and 0 < int(explicit.group(1)) < 150: return f"{int(explicit.group(1))} °C"