bug: Use correct labels for sensors in Linux (#215)

Update temperature sensors in Linux to use labels + names rather than just names.
This commit is contained in:
Clement Tsang 2020-08-31 20:02:48 -04:00 committed by GitHub
parent 5aa7b4df08
commit 5ed573157c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#211](https://github.com/ClementTsang/bottom/pull/211): Fixes a bug where you could move down in the process widget even if the process widget search was closed.
- [#215](https://github.com/ClementTsang/bottom/pull/215): Add labels to Linux temperature values.
## [0.4.7] - 2020-08-26
### Bug Fixes

View File

@ -6,7 +6,8 @@ use sysinfo::{ComponentExt, System, SystemExt};
#[derive(Default, Debug, Clone)]
pub struct TempHarvest {
pub component_name: String,
pub component_name: Option<String>,
pub component_label: Option<String>,
pub temperature: f32,
}
@ -37,7 +38,12 @@ pub async fn get_temperature_data(
while let Some(sensor) = sensor_data.next().await {
if let Ok(sensor) = sensor {
temperature_vec.push(TempHarvest {
component_name: sensor.unit().to_string(),
component_name: Some(sensor.unit().to_string()),
component_label: if let Some(label) = sensor.label() {
Some(label.to_string())
} else {
None
},
temperature: match temp_type {
TemperatureType::Celsius => sensor
.current()
@ -58,7 +64,8 @@ pub async fn get_temperature_data(
let sensor_data = sys.get_components();
for component in sensor_data {
temperature_vec.push(TempHarvest {
component_name: component.get_label().to_string(),
component_name: None,
component_label: Some(component.get_label().to_string()),
temperature: match temp_type {
TemperatureType::Celsius => component.get_temperature(),
TemperatureType::Kelvin => {
@ -73,6 +80,7 @@ pub async fn get_temperature_data(
}
// By default, sort temperature, then by alphabetically!
// TODO: [TEMPS] Allow users to control this.
// Note we sort in reverse here; we want greater temps to be higher priority.
temperature_vec.sort_by(|a, b| match a.temperature.partial_cmp(&b.temperature) {

View File

@ -93,7 +93,12 @@ pub fn convert_temp_row(app: &App) -> Vec<Vec<String>> {
} else {
for sensor in &current_data.temp_harvest {
sensor_vector.push(vec![
sensor.component_name.to_string(),
match (&sensor.component_name, &sensor.component_label) {
(Some(name), Some(label)) => format!("{}: {}", name, label),
(None, Some(label)) => label.to_string(),
(Some(name), None) => name.to_string(),
(None, None) => String::default(),
},
(sensor.temperature.ceil() as u64).to_string()
+ match temp_type {
data_harvester::temperature::TemperatureType::Celsius => "C",