bug: fix reading temperature from disabled devices (#911)

This commit is contained in:
database64128 2022-11-22 04:36:06 +08:00 committed by GitHub
parent 4f00434210
commit a0eebf3acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -161,11 +161,16 @@ fn get_from_hwmon(
if is_temp_filtered(filter, &name) {
let temp = if should_read_temp {
let temp = fs::read_to_string(temp)?;
let temp = temp.trim_end().parse::<f32>().map_err(|e| {
crate::utils::error::BottomError::ConversionError(e.to_string())
})?;
temp / 1_000.0
if let Ok(temp) = fs::read_to_string(temp) {
let temp = temp.trim_end().parse::<f32>().map_err(|e| {
crate::utils::error::BottomError::ConversionError(e.to_string())
})?;
temp / 1_000.0
} else {
// For some devices (e.g. iwlwifi), this file becomes empty when the device
// is disabled. In this case we skip the device.
continue;
}
} else {
0.0
};