nicolargo / batinfo Goto Github PK
View Code? Open in Web Editor NEWA Python lib to grab batteries' informations on Linux operating system
License: GNU Lesser General Public License v3.0
A Python lib to grab batteries' informations on Linux operating system
License: GNU Lesser General Public License v3.0
I know GitHub shows changes tagged for 0.1.9, and I know the version number's been updated at least one place:
localhost /usr/src/batinfo [0]# grep -ir '0\.1\.9' *
__init__.py:__version__ = "0.1.9"
Installing either direct from GitHub or from a local Zip created from a "git clone" operation results in pip claiming 0.1.8's installed. Whichever version's really installed, I still can't get battery info from Glances.
Does Glances have some undocumented cmdline flag or hotkey I'm supposed to use to enable battery info? Or is there some problem with the batinfo code on GitHub?
See config and log https://travis-ci.org/nicolargo/batinfo/jobs/176826522
{
"language": "ruby",
"group": "stable",
"dist": "precise",
"os": "linux"
}
Traceback (most recent call last):
File "/home/djipey/conky/scripts/bat.py", line 6, in <module>
import batinfo
File "/usr/lib/python3.3/site-packages/batinfo/__init__.py", line 29, in <module>
from battery import battery, batteries
ImportError: No module named 'battery'
See ==> nicolargo/glances#1921
Hello,
I really appreciate Glances as a lightweight system monitor, I was looking for smthg like this for a long time. Thx a lot !
Strangely, on my system and maybe because of the battery linux driver, the battery object behaves like this :
$import batinfo
$a=batinfo.battery()
$repr(a)
'{"status": "Discharging", "name": "BAT0", "uevent": "POWER_SUPPLY_NAME=BAT0\nPOWER_SUPPLY_STATUS=Discharging\nPOWER_SUPPLY_PRESENT=1\nPOWER_SUPPLY_TECHNOLOGY=Li-ion\nPOWER_SUPPLY_CYCLE_COUNT=0\nPOWER_SUPPLY_VOLTAGE_MIN_DESIGN=10800000\nPOWER_SUPPLY_VOLTAGE_NOW=11960000\nPOWER_SUPPLY_CURRENT_NOW=620000\nPOWER_SUPPLY_CHARGE_FULL_DESIGN=4400000\nPOWER_SUPPLY_CHARGE_FULL=3998000\nPOWER_SUPPLY_CHARGE_NOW=3562000\nPOWER_SUPPLY_MODEL_NAME=1005P\nPOWER_SUPPLY_MANUFACTURER=ASUS\nPOWER_SUPPLY_SERIAL_NUMBER=", "alarm": 0, "charge_full": 3998000, "voltage_now": 11960000, "serial_number": "", "model_name": "1005P", "current_now": 620000, "charge_now": 3562000, "type": "Battery", "path": "/sys/class/power_supply/BAT0", "voltage_min_design": 10800000, "manufacturer": "ASUS", "technology": "Li-ion", "cycle_count": 0, "present": 1, "charge_full_design": 4400000}'
$str(a)
CRITICAL:batinfo.battery:Attribute capacity did not exist
So the battrey object correctly initialized, but the kernel doesn't seem to provide the "capacity" attribute. Maybe, batinfo should be quiet about it (it destroys Glances interface otherwise) or perhaps batinfo could deduce the battery current capacity from the uevent attribute... I'm pretty noob, and not sure if I'm getting it right... but if you confirm the coherence of my interpretation I could propose a little patch. Capacity is just the percentage calculated from CHARGEFULL and CHARGENOW right ?
Thanks again for Ur time !
This happens on Python 3.3, 3.4 or 3.5:
$ python3.5 -m unittest
FF.Fbatinfo/test_batinfo.py:53: DeprecationWarning: Please use assertEqual instead.
self.assertEquals(batteries_count, 2)
.
======================================================================
FAIL: test_batinfo_capacity (test_batinfo.TestBatInfo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "batinfo/test_batinfo.py", line 42, in test_batinfo_capacity
self.assertTrue(self.bat.stat[0].capacity == 34)
AssertionError: False is not true
======================================================================
FAIL: test_batinfo_charge_now (test_batinfo.TestBatInfo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "batinfo/test_batinfo.py", line 47, in test_batinfo_charge_now
self.assertTrue(self.bat.stat[1].charge_now == 3074000)
AssertionError: False is not true
======================================================================
FAIL: test_batinfo_name_default (test_batinfo.TestBatInfo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "batinfo/test_batinfo.py", line 37, in test_batinfo_name_default
self.assertTrue(self.bat.stat[0].name == "BAT1")
AssertionError: False is not true
----------------------------------------------------------------------
Ran 5 tests in 0.007s
FAILED (failures=3)
Tests on Python 2.7 succeeded.
Power cable is unpluged...
In [6]: b.stat
Out[6]: [{"status": "Discharging", "capacity": 29, "name": "BAT0", "uevent": "POWER_SUPPLY_NAME=BAT0\nPOWER_SUPPLY_STATUS=Discharging\nPOWER_SUPPLY_PRESENT=1\nPOWER_SUPPLY_TECHNOLOGY=Unknown\nPOWER_SUPPLY_CYCLE_COUNT=0\nPOWER_SUPPLY_VOLTAGE_MIN_DESIGN=7500000\nPOWER_SUPPLY_VOLTAGE_NOW=7461000\nPOWER_SUPPLY_CURRENT_NOW=1109000\nPOWER_SUPPLY_CHARGE_FULL_DESIGN=7470000\nPOWER_SUPPLY_CHARGE_FULL=7328000\nPOWER_SUPPLY_CHARGE_NOW=2155000\nPOWER_SUPPLY_CAPACITY=29\nPOWER_SUPPLY_MODEL_NAME=Dell\nPOWER_SUPPLY_MANUFACTURER=SANYO\nPOWER_SUPPLY_SERIAL_NUMBER=152", "alarm": 0, "charge_full": 7328000, "voltage_now": 7461000, "serial_number": 152, "cycle_count": 0, "current_now": 1109000, "charge_now": 2155000, "voltage_min_design": 7500000, "path": "/sys/class/power_supply/BAT0", "technology": "Unknown", "manufacturer": "SANYO", "type": "Battery", "model_name": "Dell", "present": 1, "charge_full_design": 7470000}]
Plug the power cable...
In [7]: b.stat
CRITICAL:batinfo.battery:Can not read file current_now
Out[7]: [{"status": "Charging", "capacity": 29, "name": "BAT0", "uevent": "POWER_SUPPLY_NAME=BAT0\nPOWER_SUPPLY_STATUS=Charging\nPOWER_SUPPLY_PRESENT=1\nPOWER_SUPPLY_TECHNOLOGY=Unknown\nPOWER_SUPPLY_CYCLE_COUNT=0\nPOWER_SUPPLY_VOLTAGE_MIN_DESIGN=7500000\nPOWER_SUPPLY_VOLTAGE_NOW=7625000\nPOWER_SUPPLY_CHARGE_FULL_DESIGN=7470000\nPOWER_SUPPLY_CHARGE_FULL=7328000\nPOWER_SUPPLY_CHARGE_NOW=2148000\nPOWER_SUPPLY_CAPACITY=29\nPOWER_SUPPLY_MODEL_NAME=Dell\nPOWER_SUPPLY_MANUFACTURER=SANYO\nPOWER_SUPPLY_SERIAL_NUMBER=152", "alarm": 0, "charge_full": 7328000, "voltage_now": 7625000, "serial_number": 152, "cycle_count": 0, "current_now": "", "charge_now": 2148000, "voltage_min_design": 7500000, "path": "/sys/class/power_supply/BAT0", "technology": "Unknown", "manufacturer": "SANYO", "type": "Battery", "model_name": "Dell", "present": 1, "charge_full_design": 7470000}]
It would be nice if the tests are shipped. Can you please add them to the tarball/archive? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.