-
-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(temperature): Add zone-type
setting
#2752
feat(temperature): Add zone-type
setting
#2752
Conversation
polite reminder @patrick96 , can we merge this? |
I'm not around right now, so can't really review this. Will review once I'm back and have time. But general idea looks good. Except that you just try the first 10 zones instead of listing files in the folder and iterating through those. |
eb369e4
to
5b96d0f
Compare
Okay, cool. Re iterations, rewrote it to use I have a few useful contributions which I can open PR for once this is merged. |
I'm not the biggest fan of iterating until no file is found. Is it guaranteed that all Also, the error message for when no zone is found is very confusing:
The error message should tell the user which zone type it failed to find (and maybe even list all available zone types).
Please open a discussion topic for those. That way we can see how those will fit into polybar. |
5b96d0f
to
6ced7ce
Compare
There's this in kernel, but still not sure about gaps as there are ways to unregister sensors. I suppose you've seen this issue before so I implemented what you suggested, check the diff please. |
6ced7ce
to
379499a
Compare
reminder |
Codecov Report
@@ Coverage Diff @@
## master #2752 +/- ##
==========================================
- Coverage 13.52% 13.49% -0.03%
==========================================
Files 152 152
Lines 11396 11417 +21
==========================================
Hits 1541 1541
- Misses 9855 9876 +21
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also mention this feature in the ¢hangelog.
src/modules/temperature.cpp
Outdated
} | ||
|
||
if (!zone_found) { | ||
throw module_error("zone-type '" + m_zone_type + "' was not found, available zone types:" + available_zones); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw module_error("zone-type '" + m_zone_type + "' was not found, available zone types:" + available_zones); | |
throw module_error("zone-type '" + m_zone_type + "' was not found, available zone types: " + available_zones); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/modules/temperature.cpp
Outdated
for (auto &z: zone_list) { | ||
string zone_file = string_util::replace(PATH_THERMAL_ZONE_TYPE, "%zone%", to_string(z)); | ||
string z_zone_type = string_util::strip_trailing_newline(file_util::contents(zone_file)); | ||
available_zones += " " + z_zone_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Instead of manually constructing the string, we could store the types in a vector and finally construct the string using. string_util::join(available_zones, ", ")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/modules/temperature.cpp
Outdated
vector<string> thermal_list = file_util::list_files("/sys/class/thermal/"); | ||
for (auto &thermal: thermal_list) { | ||
string zone_str = regex_replace(thermal, std::regex("thermal_zone([0-9]+)"), string("$1"), std::regex_constants::format_no_copy); | ||
if (!zone_str.empty()) { | ||
zone_list.push_back(stoi(zone_str)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional, but could make this code cleaner: Instead of extracting the zone number, we could file_util::glob
for /sys/class/thermal/thermal_zone*
and just add /type
for getting the type and /temp
to get m_path
, the zone number isn't really needed for the module itself.
Pick whatever solution you like better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the zone number as an effort to keep behavior consistent for when there are multiple sensors with the same name. We know we'll always pick the one with lowest number, which depending on hardware and kernel may or may not be random.
Do you still want me to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a good point. I think sorting the paths should be sufficient to keep consistency (even if it doesn't guarantee that the lowest number is picked).
It's up to you, whichever solution you like better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
379499a
to
0ba3557
Compare
|
Looks very good now. I'll not be at my computer for a few weeks, so I'll have to do the final review + testing once I get back. |
bump to keep the PR in my Recent activity |
Thanks! |
What type of PR is this? (check all applicable)
Description
CPU's
thermal-zone
changes on every boot on my machine, sometimes it's1
and other times it's2
. Others also have had this issue and resorted to scripts updating thethermal-zone
before startingpolybar
.This can simply be fixed using a
zone-type
config option:If you look at the content in
/sys/class/thermal/thermal_zone%zone%/type
, you'll get the name of the sensor and you can easily deduct zone from that. For example for Intel CPUs, you should setzone-type = x86_pkg_temp
and you'll be set.Related Issues & Documents
Ref #2572
Documentation (check all applicable)