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 %
This commit is contained in:
Tobias 2022-09-10 14:02:17 +02:00 committed by GitHub
parent 620433d78d
commit 98569ad71a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 14 deletions

View File

@ -255,6 +255,12 @@ def charging():
# we cannot determine discharging state, assume we are on powercable # we cannot determine discharging state, assume we are on powercable
return True return True
def battery_percentage():
"""
get batery percentage
"""
return round(psutil.sensors_battery().percent)
def get_avail_gov(): def get_avail_gov():
f = Path("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors") f = Path("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors")
@ -993,10 +999,10 @@ def set_autofreq():
# determine which governor should be used # determine which governor should be used
if charging(): if charging():
print("Battery is: charging\n") print("Battery is: charging (" + str(battery_percentage()) + "%)\n")
set_performance() set_performance()
else: else:
print("Battery is: discharging\n") print("Battery is: discharging (" + str(battery_percentage()) + "%)\n")
set_powersave() set_powersave()
@ -1009,12 +1015,12 @@ def mon_autofreq():
# determine which governor should be used # determine which governor should be used
if charging(): if charging():
print("Battery is: charging\n") print("Battery is: charging (" + str(battery_percentage()) + "%)\n")
get_current_gov() get_current_gov()
print(f'Suggesting use of "{get_avail_performance()}" governor') print(f'Suggesting use of "{get_avail_performance()}" governor')
mon_performance() mon_performance()
else: else:
print("Battery is: discharging\n") print("Battery is: discharging (" + str(battery_percentage()) + "%)\n")
get_current_gov() get_current_gov()
print(f'Suggesting use of "{get_avail_powersave()}" governor') print(f'Suggesting use of "{get_avail_powersave()}" governor')
mon_powersave() mon_powersave()
@ -1119,16 +1125,9 @@ def sysinfo():
core = cpu_core[cpu] core = cpu_core[cpu]
cpu_temp_index = core_temp_labels.index(f"Core {core}") cpu_temp_index = core_temp_labels.index(f"Core {core}")
temp_per_cpu[i] = core_temp["coretemp"][cpu_temp_index].current temp_per_cpu[i] = core_temp["coretemp"][cpu_temp_index].current
elif "k10temp" in core_temp: else:
# https://www.kernel.org/doc/Documentation/hwmon/k10temp temp = list(psutil.sensors_temperatures())
temp_per_cpu = [core_temp["k10temp"][0].current] * online_cpu_count temp_per_cpu = [core_temp[temp[0]][0].current] * online_cpu_count
elif "zenpower" in core_temp:
# https://github.com/AdnanHodzic/auto-cpufreq/issues/145#issuecomment-763294009
temp_per_cpu = [core_temp["zenpower"][0].current] * online_cpu_count
elif "acpitz" in core_temp:
temp_per_cpu = [core_temp["acpitz"][0].current] * online_cpu_count
elif "thinkpad" in core_temp:
temp_per_cpu = [core_temp["thinkpad"][0].current] * online_cpu_count
except Exception as e: except Exception as e:
print(repr(e)) print(repr(e))
pass pass