Skip to content

Commit 0c7c9b2

Browse files
committed
back to running thermal zone if no hwmon
1 parent 32f9a5c commit 0c7c9b2

File tree

1 file changed

+13
-2
lines changed
  • src/app/data_harvester/temperature

1 file changed

+13
-2
lines changed

src/app/data_harvester/temperature/linux.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::app::{
1717
#[derive(Default)]
1818
struct HwmonResults {
1919
temperatures: Vec<TempHarvest>,
20+
num_hwmon: usize,
2021
}
2122

2223
/// Parses and reads temperatures that were in millidegree Celsius, and if successful, returns a temperature in Celsius.
@@ -94,6 +95,8 @@ fn get_from_hwmon(temp_type: &TemperatureType, filter: &Option<Filter>) -> Resul
9495
// It's possible that there are dupes (represented by symlinks) - the easy
9596
// way is to just substitute the parent directory and check if the hwmon
9697
// variant exists already in a set.
98+
//
99+
// For more info, see https://github.com/giampaolo/psutil/pull/1822/files
97100
if let Some(child) = path.file_name() {
98101
let to_check_path = Path::new("/sys/class/hwmon").join(child);
99102

@@ -111,8 +114,11 @@ fn get_from_hwmon(temp_type: &TemperatureType, filter: &Option<Filter>) -> Resul
111114

112115
let mut dirs = HashSet::default();
113116
add_hwmon(&mut dirs);
117+
let num_hwmon = dirs.len();
114118
add_coretemp(&mut dirs);
115119

120+
// let mut thermal_types = HashSet::default();
121+
116122
// Note that none of this is async if we ever go back to it, but sysfs is in
117123
// memory, so in theory none of this should block if we're slightly careful.
118124
// Of note is that reading the temperature sensors of a device that has
@@ -236,7 +242,10 @@ fn get_from_hwmon(temp_type: &TemperatureType, filter: &Option<Filter>) -> Resul
236242
}
237243
}
238244

239-
Ok(HwmonResults { temperatures })
245+
Ok(HwmonResults {
246+
temperatures,
247+
num_hwmon,
248+
})
240249
}
241250

242251
/// Gets data from `/sys/class/thermal/thermal_zone*`. This should only be used if
@@ -294,7 +303,9 @@ pub fn get_temperature_data(
294303
) -> Result<Option<Vec<TempHarvest>>> {
295304
let mut results = get_from_hwmon(temp_type, filter).unwrap_or_default();
296305

297-
get_from_thermal_zone(&mut results.temperatures, temp_type, filter);
306+
if results.num_hwmon == 0 {
307+
get_from_thermal_zone(&mut results.temperatures, temp_type, filter);
308+
}
298309

299310
#[cfg(feature = "nvidia")]
300311
{

0 commit comments

Comments
 (0)