Skip to content

Commit 98569ad

Browse files
authored
SunkenHero Code optimization & addition of battery percentage (#432)
* Added fan speed display * optimizations in temperatures * Simplified charging function and added percentage display * change print battery status * Fixed charging not returning boolean * battery_percentage returns now rounded value insead of 10 decimals * changed charging function back * changed charging back and some display changes * little fix at display battery percentage * battery percentage not showing %
1 parent 620433d commit 98569ad

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

auto_cpufreq/core.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ def charging():
255255
# we cannot determine discharging state, assume we are on powercable
256256
return True
257257

258+
def battery_percentage():
259+
"""
260+
get batery percentage
261+
"""
262+
return round(psutil.sensors_battery().percent)
263+
258264

259265
def get_avail_gov():
260266
f = Path("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors")
@@ -993,10 +999,10 @@ def set_autofreq():
993999

9941000
# determine which governor should be used
9951001
if charging():
996-
print("Battery is: charging\n")
1002+
print("Battery is: charging (" + str(battery_percentage()) + "%)\n")
9971003
set_performance()
9981004
else:
999-
print("Battery is: discharging\n")
1005+
print("Battery is: discharging (" + str(battery_percentage()) + "%)\n")
10001006
set_powersave()
10011007

10021008

@@ -1009,12 +1015,12 @@ def mon_autofreq():
10091015

10101016
# determine which governor should be used
10111017
if charging():
1012-
print("Battery is: charging\n")
1018+
print("Battery is: charging (" + str(battery_percentage()) + "%)\n")
10131019
get_current_gov()
10141020
print(f'Suggesting use of "{get_avail_performance()}" governor')
10151021
mon_performance()
10161022
else:
1017-
print("Battery is: discharging\n")
1023+
print("Battery is: discharging (" + str(battery_percentage()) + "%)\n")
10181024
get_current_gov()
10191025
print(f'Suggesting use of "{get_avail_powersave()}" governor')
10201026
mon_powersave()
@@ -1119,16 +1125,9 @@ def sysinfo():
11191125
core = cpu_core[cpu]
11201126
cpu_temp_index = core_temp_labels.index(f"Core {core}")
11211127
temp_per_cpu[i] = core_temp["coretemp"][cpu_temp_index].current
1122-
elif "k10temp" in core_temp:
1123-
# https://www.kernel.org/doc/Documentation/hwmon/k10temp
1124-
temp_per_cpu = [core_temp["k10temp"][0].current] * online_cpu_count
1125-
elif "zenpower" in core_temp:
1126-
# https://github.com/AdnanHodzic/auto-cpufreq/issues/145#issuecomment-763294009
1127-
temp_per_cpu = [core_temp["zenpower"][0].current] * online_cpu_count
1128-
elif "acpitz" in core_temp:
1129-
temp_per_cpu = [core_temp["acpitz"][0].current] * online_cpu_count
1130-
elif "thinkpad" in core_temp:
1131-
temp_per_cpu = [core_temp["thinkpad"][0].current] * online_cpu_count
1128+
else:
1129+
temp = list(psutil.sensors_temperatures())
1130+
temp_per_cpu = [core_temp[temp[0]][0].current] * online_cpu_count
11321131
except Exception as e:
11331132
print(repr(e))
11341133
pass

0 commit comments

Comments
 (0)