From 980e9fa0c12243fb391df66708b9ddfe366185f0 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Tue, 19 Dec 2023 22:51:35 -0500 Subject: [PATCH] add back an empty name and value --- CHANGELOG.md | 1 + src/app/data_harvester/nvidia.rs | 2 +- src/app/data_harvester/temperature.rs | 2 +- src/app/data_harvester/temperature/linux.rs | 14 ++++++++++---- src/data_conversion.rs | 2 +- src/widgets/temperature_table.rs | 20 ++++++++++++-------- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ad825dc9..2227e9d61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug Fixes - [#1314](https://github.com/ClementTsang/bottom/pull/1314): Fix fat32 mounts not showing up in macOS. +- [#1355](https://github.com/ClementTsang/bottom/pull/1355): Reduce chances of non-D0 devices waking up due to temperature checks on Linux. ## [0.9.6] - 2023-08-26 diff --git a/src/app/data_harvester/nvidia.rs b/src/app/data_harvester/nvidia.rs index 848a18f7e..964ccc5a7 100644 --- a/src/app/data_harvester/nvidia.rs +++ b/src/app/data_harvester/nvidia.rs @@ -54,7 +54,7 @@ pub fn get_nvidia_vecs( temp_vec.push(TempHarvest { name: name.clone(), - temperature, + temperature: Some(temperature), }); } } diff --git a/src/app/data_harvester/temperature.rs b/src/app/data_harvester/temperature.rs index a15eb26a5..220190e66 100644 --- a/src/app/data_harvester/temperature.rs +++ b/src/app/data_harvester/temperature.rs @@ -18,7 +18,7 @@ use crate::app::Filter; #[derive(Default, Debug, Clone)] pub struct TempHarvest { pub name: String, - pub temperature: f32, + pub temperature: Option, } #[derive(Clone, Debug, Copy, PartialEq, Eq, Default)] diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index 2070c9a78..a25dc3524 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -131,8 +131,8 @@ fn finalize_name( None => label, }, (Some(name), None) => name, - (None, None) => match &fallback_sensor_name { - Some(sensor_name) => sensor_name.clone(), + (None, None) => match fallback_sensor_name { + Some(sensor_name) => sensor_name.to_owned(), None => EMPTY_NAME.to_string(), }, }; @@ -204,6 +204,12 @@ fn hwmon_temperatures(temp_type: &TemperatureType, filter: &Option) -> H let sensor_name = read_to_string_lossy(file_path.join("name")); if !is_device_awake(&file_path) { + if let Some(sensor_name) = sensor_name { + temperatures.push(TempHarvest { + name: sensor_name, + temperature: None, + }); + } continue; } @@ -285,7 +291,7 @@ fn hwmon_temperatures(temp_type: &TemperatureType, filter: &Option) -> H temperatures.push(TempHarvest { name, - temperature: temp_type.convert_temp_unit(temp_celsius), + temperature: Some(temp_type.convert_temp_unit(temp_celsius)), }); } } @@ -330,7 +336,7 @@ fn add_thermal_zone_temperatures( temperatures.push(TempHarvest { name, - temperature: temp_type.convert_temp_unit(temp_celsius), + temperature: Some(temp_type.convert_temp_unit(temp_celsius)), }); } } diff --git a/src/data_conversion.rs b/src/data_conversion.rs index 645e70f3e..f7f62eacc 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -132,7 +132,7 @@ impl ConvertedData { data.temp_harvest.iter().for_each(|temp_harvest| { self.temp_data.push(TempWidgetData { sensor: KString::from_ref(&temp_harvest.name), - temperature_value: temp_harvest.temperature.ceil() as u64, + temperature_value: temp_harvest.temperature.map(|temp| temp.ceil() as u64), temperature_type, }); }); diff --git a/src/widgets/temperature_table.rs b/src/widgets/temperature_table.rs index 1c8fe67c0..3f570c0bd 100644 --- a/src/widgets/temperature_table.rs +++ b/src/widgets/temperature_table.rs @@ -17,7 +17,7 @@ use crate::{ #[derive(Clone, Debug)] pub struct TempWidgetData { pub sensor: KString, - pub temperature_value: u64, + pub temperature_value: Option, pub temperature_type: TemperatureType, } @@ -37,13 +37,17 @@ impl ColumnHeader for TempWidgetColumn { impl TempWidgetData { pub fn temperature(&self) -> KString { - let temp_val = self.temperature_value.to_string(); - let temp_type = match self.temperature_type { - TemperatureType::Celsius => "°C", - TemperatureType::Kelvin => "K", - TemperatureType::Fahrenheit => "°F", - }; - concat_string!(temp_val, temp_type).into() + match self.temperature_value { + Some(temp_val) => { + let temp_type = match self.temperature_type { + TemperatureType::Celsius => "°C", + TemperatureType::Kelvin => "K", + TemperatureType::Fahrenheit => "°F", + }; + concat_string!(temp_val.to_string(), temp_type).into() + } + None => "N/A".to_string().into(), + } } }