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
This commit is contained in:
1 parent
01b6a7fd4e
commit
c6c2437732
1 file changed
+5
-2
@@ -362,10 +362,13 @@ def smart_temperature(device):
|
|||||||
# Seagate and similar drives often expose both Airflow_Temperature
|
# Seagate and similar drives often expose both Airflow_Temperature
|
||||||
# and Temperature_Celsius. Prefer the latter because it is the
|
# and Temperature_Celsius. Prefer the latter because it is the
|
||||||
# physical drive temperature shown by the usual terminal command.
|
# 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 re.search(r"Temperature_Celsius", 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 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)]
|
ordered += [line for line in lines if line not in ordered and re.search(r"temperature|airflow", line, re.IGNORECASE)]
|
||||||
for line in ordered:
|
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)
|
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:
|
if explicit and 0 < int(explicit.group(1)) < 150:
|
||||||
return f"{int(explicit.group(1))} °C"
|
return f"{int(explicit.group(1))} °C"
|
||||||
|
|||||||
Reference in new issue
Block a user