mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
refactor: acpi parser: adhere code to the happy path to avoid nested branches (#488)
* refactor: acpi parser: keep working code in happy path to avoid nested branches * fix: use elif for branches marked charging and discharging --------- Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1cd723b48f
commit
71db67ef49
@ -337,18 +337,14 @@ def parse(data, raw=False, quiet=False):
|
|||||||
output_line['state'] = 'Not charging'
|
output_line['state'] = 'Not charging'
|
||||||
output_line['charge_percent'] = line.split()[-1].rstrip('%,')
|
output_line['charge_percent'] = line.split()[-1].rstrip('%,')
|
||||||
|
|
||||||
if 'Charging' in line \
|
if any(word in line for word in ('Charging', 'Discharging', 'Full')):
|
||||||
or 'Discharging' in line \
|
|
||||||
or 'Full' in line:
|
|
||||||
|
|
||||||
output_line['state'] = line.split()[2][:-1]
|
output_line['state'] = line.split()[2][:-1]
|
||||||
output_line['charge_percent'] = line.split()[3].rstrip('%,')
|
output_line['charge_percent'] = line.split()[3].rstrip('%,')
|
||||||
if 'will never fully discharge' in line:
|
if 'will never fully discharge' in line or 'rate information unavailable' in line:
|
||||||
pass
|
pass
|
||||||
elif 'rate information unavailable' not in line:
|
elif 'Charging' in line:
|
||||||
if 'Charging' in line:
|
|
||||||
output_line['until_charged'] = line.split()[4]
|
output_line['until_charged'] = line.split()[4]
|
||||||
if 'Discharging' in line:
|
elif 'Discharging' in line:
|
||||||
output_line['charge_remaining'] = line.split()[4]
|
output_line['charge_remaining'] = line.split()[4]
|
||||||
|
|
||||||
if 'design capacity' in line:
|
if 'design capacity' in line:
|
||||||
@ -359,10 +355,7 @@ def parse(data, raw=False, quiet=False):
|
|||||||
if obj_type == 'Adapter':
|
if obj_type == 'Adapter':
|
||||||
output_line['type'] = obj_type
|
output_line['type'] = obj_type
|
||||||
output_line['id'] = obj_id
|
output_line['id'] = obj_id
|
||||||
if 'on-line' in line:
|
output_line['on-line'] = 'on-line' in line
|
||||||
output_line['on-line'] = True
|
|
||||||
else:
|
|
||||||
output_line['on-line'] = False
|
|
||||||
|
|
||||||
if obj_type == 'Thermal':
|
if obj_type == 'Thermal':
|
||||||
output_line['type'] = obj_type
|
output_line['type'] = obj_type
|
||||||
|
Reference in New Issue
Block a user