battery_percentage fix (#437)

This commit is contained in:
BowDown097 2022-09-25 09:50:53 -07:00 committed by GitHub
parent 00a6ab2d27
commit 43b33be51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -259,7 +259,11 @@ def battery_percentage():
"""
get batery percentage
"""
return round(psutil.sensors_battery().percent)
sensors_battery = psutil.sensors_battery()
if sensors_battery:
return round(sensors_battery.percent)
else:
return None
def get_avail_gov():
@ -998,11 +1002,14 @@ def set_autofreq():
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
# determine which governor should be used
battery_percent = battery_percentage()
if charging():
print("Battery is: charging (" + str(battery_percentage()) + "%)\n")
if battery_percent:
print("Battery is: charging (" + str(battery_percent) + "%)\n")
set_performance()
else:
print("Battery is: discharging (" + str(battery_percentage()) + "%)\n")
if battery_percent:
print("Battery is: discharging (" + str(battery_percent) + "%)\n")
set_powersave()
@ -1014,13 +1021,16 @@ def mon_autofreq():
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
# determine which governor should be used
battery_percent = battery_percentage()
if charging():
print("Battery is: charging (" + str(battery_percentage()) + "%)\n")
if battery_percent:
print("Battery is: charging (" + str(battery_percent) + "%)\n")
get_current_gov()
print(f'Suggesting use of "{get_avail_performance()}" governor')
mon_performance()
else:
print("Battery is: discharging (" + str(battery_percentage()) + "%)\n")
if battery_percent:
print("Battery is: discharging (" + str(battery_percent) + "%)\n")
get_current_gov()
print(f'Suggesting use of "{get_avail_powersave()}" governor')
mon_powersave()