add power package for better power source control (#25)

* temp fix for https://github.com/giampaolo/psutil/issues/1658

* fix for missing set_performance()

* add power package for better power source status detecting

* remove redundant spaces

Co-authored-by: Adnan Hodzic <adnan@hodzic.org>
This commit is contained in:
Mert Demir 2020-01-12 09:07:22 +03:00 committed by Adnan Hodzic
parent bdf37210c5
commit 5734162a7d
2 changed files with 14 additions and 13 deletions

View File

@ -49,10 +49,10 @@ Please note: this tool doesn't conflict and [works great in tandem with TLP](htt
All requirements can be installed by running: All requirements can be installed by running:
`sudo apt install python3-dev python3-pip python3-distro python3-psutil python3-click -y` `sudo apt install python3-dev python3-pip python3-distro python3-psutil python3-click python3-power -y`
Since APT packages may contain older version of necessary Python packages, please make sure to have latest version by running: Since APT packages may contain older version of necessary Python packages, please make sure to have latest version by running:
`sudo pip3 install --upgrade psutil click distro` `sudo pip3 install --upgrade psutil click distro power`
##### Requirements installation for Redhat/Fedora and its derivatives ##### Requirements installation for Redhat/Fedora and its derivatives
@ -66,7 +66,7 @@ After which you need to[ need to install rest of the requirements](https://githu
If you have python3 and pip3 installed simply run: If you have python3 and pip3 installed simply run:
`sudo pip3 install psutil click distro` `sudo pip3 install psutil click distro power`
Note: libraries must be installed using root user as tool will be run as root. Note: libraries must be installed using root user as tool will be run as root.

View File

@ -11,6 +11,7 @@ import time
import psutil import psutil
import platform import platform
import click import click
import power
# ToDo: # ToDo:
# - re-enable CPU fan speed display and make more generic and not only for thinkpad # - re-enable CPU fan speed display and make more generic and not only for thinkpad
@ -30,7 +31,7 @@ get_cur_gov = s.getoutput("cpufreqctl --governor")
gov_state = get_cur_gov.split()[0] gov_state = get_cur_gov.split()[0]
# get battery state # get battery state
bat_state = p.sensors_battery().power_plugged bat_state = power.PowerManagement().get_providing_power_source_type()
# auto-cpufreq log file # auto-cpufreq log file
auto_cpufreq_log_file = "/var/log/auto-cpufreq.log" auto_cpufreq_log_file = "/var/log/auto-cpufreq.log"
@ -249,36 +250,36 @@ def set_autofreq():
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n") print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
# get battery state # get battery state
bat_state = p.sensors_battery().power_plugged bat_state = power.PowerManagement().get_providing_power_source_type()
# determine which governor should be used # determine which governor should be used
if bat_state == True: if bat_state == power.POWER_TYPE_AC:
print("Battery is: charging") print("Battery is: charging")
set_performance() set_performance()
elif bat_state == False: elif bat_state == power.POWER_TYPE_BATTERY:
print("Battery is: discharging") print("Battery is: discharging")
set_powersave() set_powersave()
else: else:
print("Couldn't detrmine battery status. Please report this issue.") print("Couldn't determine battery status. Please report this issue.")
# make cpufreq suggestions # make cpufreq suggestions
def mon_autofreq(): def mon_autofreq():
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n") print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
# get battery state # get battery state
bat_state = p.sensors_battery().power_plugged bat_state = power.PowerManagement().get_providing_power_source_type()
# determine which governor should be used # determine which governor should be used
if bat_state == True: if bat_state == power.POWER_TYPE_AC:
print("Battery is: charging") print("Battery is: charging")
print("Suggesting use of \"performance\" governor\nCurrently using:", gov_state) print("Suggesting use of \"performance\" governor\nCurrently using:", gov_state)
mon_performance() mon_performance()
elif bat_state == False: elif bat_state == power.POWER_TYPE_BATTERY:
print("Battery is: discharging") print("Battery is: discharging")
print("Suggesting use of \"powersave\" governor\nCurrently using:", gov_state) print("Suggesting use of \"powersave\" governor\nCurrently using:", gov_state)
mon_powersave() mon_powersave()
else: else:
print("Couldn't detrmine battery status. Please report this issue.") print("Couldn't determine battery status. Please report this issue.")
# get system information # get system information
def sysinfo(): def sysinfo():