hidpp20: fix error when showing battery

Signed-off-by: Filipe Laíns <lains@archlinux.org>
This commit is contained in:
Peter F. Patel-Schneider 2020-01-12 13:03:57 -05:00 committed by Filipe Laíns
parent c30f0a79bd
commit 0198d58dc7
No known key found for this signature in database
GPG Key ID: F893C674816AA95D
1 changed files with 6 additions and 4 deletions

View File

@ -166,7 +166,6 @@ def _print_device(dev):
print (' %s, pos:%d, group:%1d, gmask:%d' % ( ', '.join(flags), k.pos, k.group, k.group_mask))
if dev.online:
battery = _hidpp20.get_battery(dev)
(voltage, charging, charge_sts, charge_lvl, charge_type) = _hidpp20.get_voltage(dev)
if battery is None:
battery = _hidpp10.get_battery(dev)
if battery is not None:
@ -180,10 +179,13 @@ def _print_device(dev):
else:
text = 'N/A'
print (' Battery: %s, %s.' % (text, status))
elif voltage:
print (' Battery: %smV, %s.' % (voltage, 'Charging' if charging else 'Discharging'))
else:
print (' Battery status unavailable.')
battery_voltage = _hidpp20.get_voltage(dev)
if battery_voltage :
(voltage, charging, charge_sts, charge_lvl, charge_type) = battery_voltage
print (' Battery: %smV, %s.' % (voltage, 'Charging' if charging else 'Discharging'))
else:
print (' Battery status unavailable.')
else:
print (' Battery: unknown (device is offline).')