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:
parent
bdf37210c5
commit
5734162a7d
|
@ -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:
|
||||
|
||||
`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:
|
||||
`sudo pip3 install --upgrade psutil click distro`
|
||||
`sudo pip3 install --upgrade psutil click distro power`
|
||||
|
||||
##### 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:
|
||||
|
||||
`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.
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import time
|
|||
import psutil
|
||||
import platform
|
||||
import click
|
||||
import power
|
||||
|
||||
# ToDo:
|
||||
# - 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]
|
||||
|
||||
# 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 = "/var/log/auto-cpufreq.log"
|
||||
|
@ -249,36 +250,36 @@ def set_autofreq():
|
|||
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
|
||||
|
||||
# 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
|
||||
if bat_state == True:
|
||||
if bat_state == power.POWER_TYPE_AC:
|
||||
print("Battery is: charging")
|
||||
set_performance()
|
||||
elif bat_state == False:
|
||||
elif bat_state == power.POWER_TYPE_BATTERY:
|
||||
print("Battery is: discharging")
|
||||
set_powersave()
|
||||
else:
|
||||
print("Couldn't detrmine battery status. Please report this issue.")
|
||||
else:
|
||||
print("Couldn't determine battery status. Please report this issue.")
|
||||
|
||||
# make cpufreq suggestions
|
||||
def mon_autofreq():
|
||||
print("\n" + "-" * 28 + " CPU frequency scaling " + "-" * 28 + "\n")
|
||||
|
||||
# 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
|
||||
if bat_state == True:
|
||||
if bat_state == power.POWER_TYPE_AC:
|
||||
print("Battery is: charging")
|
||||
print("Suggesting use of \"performance\" governor\nCurrently using:", gov_state)
|
||||
mon_performance()
|
||||
elif bat_state == False:
|
||||
elif bat_state == power.POWER_TYPE_BATTERY:
|
||||
print("Battery is: discharging")
|
||||
print("Suggesting use of \"powersave\" governor\nCurrently using:", gov_state)
|
||||
mon_powersave()
|
||||
else:
|
||||
print("Couldn't detrmine battery status. Please report this issue.")
|
||||
print("Couldn't determine battery status. Please report this issue.")
|
||||
|
||||
# get system information
|
||||
def sysinfo():
|
||||
|
|
Loading…
Reference in New Issue