Skip to content

Commit

Permalink
Fix thermal_zone temperature calculations
Browse files Browse the repository at this point in the history
Fix a bug in how high and critical temperatures are calculated when
using thermal zones. Clear high and critical values each iteration so
they are not divided by 1000 on subsequent iterations. Take the max
value if multiple temperature trips target either high or critical.

Signed-off-by: Siena Richard <sienarichard@samotics.com>
  • Loading branch information
siena-sam committed Sep 4, 2024
1 parent 8d94301 commit c0d087b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,23 +1467,27 @@ def sensors_temperatures():
for trip_point in trip_points:
path = os.path.join(base, trip_point + "_type")
trip_type = cat(path, fallback='').strip()
current_critical = None
current_high = None
if trip_type == 'critical':
critical = bcat(
current_critical = bcat(
os.path.join(base, trip_point + "_temp"), fallback=None
)
elif trip_type == 'high':
high = bcat(
current_high = bcat(
os.path.join(base, trip_point + "_temp"), fallback=None
)

if high is not None:
if current_high is not None:
try:
high = float(high) / 1000.0
current_high = float(current_high) / 1000.0
high = max(high, current_high) if high else current_high
except ValueError:
high = None
if critical is not None:
if current_critical is not None:
try:
critical = float(critical) / 1000.0
current_critical = float(current_critical) / 1000.0
critical = max(critical, current_critical) if critical else current_critical
except ValueError:
critical = None

Expand Down
2 changes: 2 additions & 0 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,8 @@ def glob_mock(path):
return [
'/sys/class/thermal/thermal_zone1/trip_point_0_type',
'/sys/class/thermal/thermal_zone1/trip_point_0_temp',
'/sys/class/thermal/thermal_zone1/trip_point_1_type',
'/sys/class/thermal/thermal_zone1/trip_point_1_temp',
]
return []

Expand Down

0 comments on commit c0d087b

Please sign in to comment.