diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-08-31 20:02:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-31 20:02:48 -0400 |
commit | 5ed573157c00a0617c786edde0a241bd75e81666 (patch) | |
tree | 93d3ba0e6d5e5ed8761749ef3cd902befcc7436d /src | |
parent | 5aa7b4df082bce4d029757c911893a93347d0d61 (diff) |
bug: Use correct labels for sensors in Linux (#215)
Update temperature sensors in Linux to use labels + names rather than just names.
Diffstat (limited to 'src')
-rw-r--r-- | src/app/data_harvester/temperature.rs | 14 | ||||
-rw-r--r-- | src/data_conversion.rs | 7 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/app/data_harvester/temperature.rs b/src/app/data_harvester/temperature.rs index b0a39e3d..337ed7b2 100644 --- a/src/app/data_harvester/temperature.rs +++ b/src/app/data_harvester/temperature.rs @@ -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) { diff --git a/src/data_conversion.rs b/src/data_conversion.rs index cada6cb6..dfa2290e 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -93,7 +93,12 @@ pub fn convert_temp_row(app: &App) -> Vec<Vec<String>> { } else { for sensor in ¤t_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", |