This repository was archived by the owner on Apr 3, 2020. It is now read-only.
Improved support for multiple batteries#4
Open
jceb wants to merge 19 commits into
Open
Conversation
This fixes an issue where the battery constantly reads at 0%. It's because (at least on my system) the naming conventions for the special files inside the sysfs tree are different from what the script expects. The script expects: /sys/class/power_supply/BAT*/energy_full /sys/class/power_supply/BAT*/energy_now /sys/class/power_supply/BAT*/power_now My sysfs has: /sys/class/power_supply/BAT*/charge_full /sys/class/power_supply/BAT*/charge_now /sys/class/power_supply/BAT*/current_now Unfortunately I am unable to find the exact commit log where this naming convention changed, but now the script will support both and everyone will be happy. This bug was also observed in kernel 2.6.38.7. * Evidence * $ uname -a Linux delicious 3.2.2 denilsonsa#1 SMP Fri Jan 27 15:19:49 CST 2012 x86_64 Intel(R) Atom(TM) CPU N455 @ 1.66GHz GenuineIntel GNU/Linux $ ls -la /sys/class/power_supply/BAT1/ total 0 drwxr-xr-x 3 root root 0 Feb 8 15:20 . drwxr-xr-x 3 root root 0 Feb 8 15:20 .. -rw-r--r-- 1 root root 4096 Feb 13 10:44 alarm -r--r--r-- 1 root root 4096 Feb 8 15:20 charge_full -r--r--r-- 1 root root 4096 Feb 13 10:44 charge_full_design -r--r--r-- 1 root root 4096 Feb 8 15:20 charge_now -r--r--r-- 1 root root 4096 Feb 8 15:20 current_now -r--r--r-- 1 root root 4096 Feb 13 10:44 cycle_count lrwxrwxrwx 1 root root 0 Feb 13 10:44 device -> ../../../PNP0C0A:00 -r--r--r-- 1 root root 4096 Feb 13 10:44 manufacturer -r--r--r-- 1 root root 4096 Feb 13 10:44 model_name drwxr-xr-x 2 root root 0 Feb 13 10:44 power -r--r--r-- 1 root root 4096 Feb 8 15:20 present -r--r--r-- 1 root root 4096 Feb 13 10:44 serial_number -r--r--r-- 1 root root 4096 Feb 8 15:20 status lrwxrwxrwx 1 root root 0 Feb 8 16:01 subsystem -> ../../../../../../class/power_supply -r--r--r-- 1 root root 4096 Feb 13 10:44 technology -r--r--r-- 1 root root 4096 Feb 13 10:33 type -rw-r--r-- 1 root root 4096 Feb 8 16:01 uevent -r--r--r-- 1 root root 4096 Feb 13 10:44 voltage_min_design -r--r--r-- 1 root root 4096 Feb 8 15:20 voltage_now
Caveats: `'0' or 2` will return `'0'`
{power,current}_now can contain a 0 when charging. This is normal.
I don't have DistUtilsExtra on my system, it's not part of vanilla python packaging.
This is a simple script I wrote that will hopefully work on most distros for: A) Warning the user that the battery level is critical. B) Automating the power state change process (optional, on by default). Tested on Slackware 13.37 x86_64 with 3.2.7 vanilla kernel. Tested with Xdialog 2.3.1 and xmessage 1.0.3. To use with batterymon, start batterymon with the `--on-critical' option pointed at this script.
Add -W flag for display-only operation. Hopefully this script will serve as many needs as possible.
'Nuff said.
Saves 5995 bytes, or 5.8 KB.
Replace with `which' which is not a built-in.
Owner
|
Just to let you know, it might take a while until I review and accept this pull request. Feel free to message me again in case it takes too long. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation of batterymon lets every Battery object send updates to the UI. I changed this behavior and let the PowerManagement collect the information from all batteries and ac adapters. The power management than computes the battery lifetime based on all the available devices.
I also implemented a reinitialization of ac adapters and batteries to detect newly added / removed devices.