mirror of
https://github.com/powerline/powerline.git
synced 2025-07-03 20:14:54 +02:00
Merge pull request #1690 from yangby/develop
Fix filenames for linux power supply class in battery segment.
This commit is contained in:
commit
69a72dbf69
@ -77,25 +77,31 @@ def _fetch_battery_info(pl):
|
|||||||
pl.debug('Not using DBUS+UPower as no batteries were found')
|
pl.debug('Not using DBUS+UPower as no batteries were found')
|
||||||
|
|
||||||
if os.path.isdir('/sys/class/power_supply'):
|
if os.path.isdir('/sys/class/power_supply'):
|
||||||
linux_energy_full_fmt = '/sys/class/power_supply/{0}/energy_full'
|
# ENERGY_* attributes represents capacity in µWh only.
|
||||||
linux_energy_fmt = '/sys/class/power_supply/{0}/energy_now'
|
# CHARGE_* attributes represents capacity in µAh only.
|
||||||
|
linux_capacity_units = ('energy', 'charge')
|
||||||
|
linux_energy_full_fmt = '/sys/class/power_supply/{0}/{1}_full'
|
||||||
|
linux_energy_fmt = '/sys/class/power_supply/{0}/{1}_now'
|
||||||
linux_status_fmt = '/sys/class/power_supply/{0}/status'
|
linux_status_fmt = '/sys/class/power_supply/{0}/status'
|
||||||
devices = []
|
devices = []
|
||||||
for linux_supplier in os.listdir('/sys/class/power_supply'):
|
for linux_supplier in os.listdir('/sys/class/power_supply'):
|
||||||
energy_path = linux_energy_fmt.format(linux_supplier)
|
for unit in linux_capacity_units:
|
||||||
|
energy_path = linux_energy_fmt.format(linux_supplier, unit)
|
||||||
if not os.path.exists(energy_path):
|
if not os.path.exists(energy_path):
|
||||||
continue
|
continue
|
||||||
pl.debug('Using /sys/class/power_supply with battery {0}', linux_supplier)
|
pl.debug('Using /sys/class/power_supply with battery {0} and unit {1}',
|
||||||
devices.append(linux_supplier)
|
linux_supplier, unit)
|
||||||
|
devices.append((linux_supplier, unit))
|
||||||
|
break # energy or charge, not both
|
||||||
if devices:
|
if devices:
|
||||||
def _get_battery_status(pl):
|
def _get_battery_status(pl):
|
||||||
energy = 0.0
|
energy = 0.0
|
||||||
energy_full = 0.0
|
energy_full = 0.0
|
||||||
state = True
|
state = True
|
||||||
for device in devices:
|
for device, unit in devices:
|
||||||
with open(linux_energy_full_fmt.format(device), 'r') as f:
|
with open(linux_energy_full_fmt.format(device, unit), 'r') as f:
|
||||||
energy_full += int(float(f.readline().split()[0]))
|
energy_full += int(float(f.readline().split()[0]))
|
||||||
with open(linux_energy_fmt.format(device), 'r') as f:
|
with open(linux_energy_fmt.format(device, unit), 'r') as f:
|
||||||
energy += int(float(f.readline().split()[0]))
|
energy += int(float(f.readline().split()[0]))
|
||||||
try:
|
try:
|
||||||
with open(linux_status_fmt.format(device), 'r') as f:
|
with open(linux_status_fmt.format(device), 'r') as f:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user