summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-01-26 23:42:17 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-01-26 23:42:17 +0100
commit78f8a41eb902c144dd31a9e4bafe63c25fea3c76 (patch)
tree8e57a9b3066220cee940b385dfa877074824c031
parent022cf0a05d34f4274269d4f8002ee95b9f3e32d2 (diff)
downloadpsutil-78f8a41eb902c144dd31a9e4bafe63c25fea3c76.tar.gz
update doc
-rw-r--r--docs/index.rst22
-rw-r--r--psutil/_pslinux.py5
2 files changed, 17 insertions, 10 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 52424b39..af44c516 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -622,19 +622,22 @@ Sensors
.. function:: sensors_battery()
- Return a namedtuple with the following values:
+ Return battery status information as a namedtuple including the following
+ values:
- **percent**: battery power left as a percentage.
- - **secsleft**: number of seconds left before battery run out of power; this
- may also be :data:`psutil.POWER_TIME_UNKNOWN <psutil.POWER_TIME_UNKNOWN>`
- or :data:`psutil.POWER_TIME_UNLIMITED <psutil.POWER_TIME_UNLIMITED>`.
+ - **secsleft**: (rough approximation) number of seconds left before the
+ battery run out of power; this may be set to
+ :data:`psutil.POWER_TIME_UNKNOWN <psutil.POWER_TIME_UNKNOWN>`
+ or :data:`psutil.POWER_TIME_UNLIMITED <psutil.POWER_TIME_UNLIMITED>` in
+ case the remaining time cannot be determined or is unlimited.
If no battery is installed this function will return ``None``. Example::
>>> def secs2hours(secs):
- ... m, s = divmod(secs, 60)
- ... h, m = divmod(m, 60)
- ... return "%d:%02d:%02d" % (h, m, s)
+ ... mm, ss = divmod(secs, 60)
+ ... hh, mm = divmod(m, 60)
+ ... return "%d:%02d:%02d" % (hh, mm, ss)
...
>>> batt = psutil.sensors_battery()
>>> batt
@@ -2018,8 +2021,9 @@ Constants
.. data:: POWER_TIME_UNKNOWN
.. data:: POWER_TIME_UNLIMITED
- This can be the value of *secsleft* field of
- :func:`psutil.sensors_battery()`.
+ Whether the remaining time of the battery cannot be determined or is
+ unlimited.
+ May be assigned to :func:`psutil.sensors_battery()`'s *secsleft* field.
.. versionadded:: 5.1.0
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index fff77aab..5be7f759 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1072,7 +1072,10 @@ def sensors_battery():
energy_now = int(cat(root + "energy_now"))
power_now = int(cat(root + "power_now"))
percent = int(cat(root + "capacity"))
- secsleft = int(energy_now / power_now * 3600)
+ try:
+ secsleft = int(energy_now / power_now * 3600)
+ except ZeroDivisionError:
+ secsleft = _common.POWER_TIME_UNKNOWN
return _common.sbattery(percent, secsleft)