mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-09-11 11:46:59 +03:00
feature: use better names for duplicate temp sensors found by /sys/class/thermal
(#1187)
* docs: update changelog * feature: add a counter to duplicate names if using /sys/class/thermal/ * update changelog
This commit is contained in:
parent
358bddf990
commit
086b622c66
@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [0.9.2] - Unreleased
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- [#1186](https://github.com/ClementTsang/bottom/pull/1186): Fix for temperature sensor data gathering on Linux immediately halting if any method failed.
|
||||
|
||||
## Features
|
||||
|
||||
- [#1172](https://github.com/ClementTsang/bottom/pull/1172): Support human times for `time_delta` and `default_time_value`.
|
||||
- [#1187](https://github.com/ClementTsang/bottom/pull/1187): Use better names for duplicate temp sensors found by `/sys/class/thermal`.
|
||||
|
||||
## [0.9.1] - 2023-05-14
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use hashbrown::HashMap;
|
||||
|
||||
use super::{is_temp_filtered, TempHarvest, TemperatureType};
|
||||
use crate::app::{
|
||||
@ -201,6 +202,9 @@ fn get_from_thermal_zone(
|
||||
) -> Result<Vec<TempHarvest>> {
|
||||
let mut temperatures = vec![];
|
||||
let path = Path::new("/sys/class/thermal");
|
||||
|
||||
let mut seen_names: HashMap<String, u32> = HashMap::new();
|
||||
|
||||
for entry in path.read_dir()? {
|
||||
let file = entry?;
|
||||
if file
|
||||
@ -211,9 +215,10 @@ fn get_from_thermal_zone(
|
||||
let file_path = file.path();
|
||||
let name_path = file_path.join("type");
|
||||
|
||||
let name = fs::read_to_string(name_path)?.trim_end().to_string();
|
||||
let name = fs::read_to_string(name_path)?;
|
||||
let name = name.trim_end();
|
||||
|
||||
if is_temp_filtered(filter, &name) {
|
||||
if is_temp_filtered(filter, name) {
|
||||
let temp_path = file_path.join("temp");
|
||||
let temp = fs::read_to_string(temp_path)?
|
||||
.trim_end()
|
||||
@ -222,6 +227,15 @@ fn get_from_thermal_zone(
|
||||
crate::utils::error::BottomError::ConversionError(e.to_string())
|
||||
})?
|
||||
/ 1_000.0;
|
||||
|
||||
let name = if let Some(count) = seen_names.get_mut(name) {
|
||||
*count += 1;
|
||||
format!("{name} ({})", *count)
|
||||
} else {
|
||||
seen_names.insert(name.to_string(), 0);
|
||||
name.to_string()
|
||||
};
|
||||
|
||||
temperatures.push(TempHarvest {
|
||||
name,
|
||||
temperature: match temp_type {
|
||||
@ -245,7 +259,7 @@ pub fn get_temperature_data(
|
||||
get_from_hwmon(temp_type, filter).unwrap_or_default();
|
||||
|
||||
if temperature_vec.is_empty() {
|
||||
// If it's empty, try to fall back to checking `thermal_zone*`.
|
||||
// If it's empty or it fails, try to fall back to checking `thermal_zone*`.
|
||||
temperature_vec = get_from_thermal_zone(temp_type, filter).unwrap_or_default();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user