Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: acpi parser: adhere code to the happy path to avoid nested branches #488

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions jc/parsers/acpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,15 @@ def parse(data, raw=False, quiet=False):
output_line['state'] = 'Not charging'
output_line['charge_percent'] = line.split()[-1].rstrip('%,')

if 'Charging' in line \
or 'Discharging' in line \
or 'Full' in line:

if any(word in line for word in ('Charging', 'Discharging', 'Full')):
output_line['state'] = line.split()[2][:-1]
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
elif 'rate information unavailable' not in line:
if 'Charging' in line:
output_line['until_charged'] = line.split()[4]
if 'Discharging' in line:
output_line['charge_remaining'] = line.split()[4]
elif 'Charging' in line:
output_line['until_charged'] = line.split()[4]
elif 'Discharging' in line:
output_line['charge_remaining'] = line.split()[4]

if 'design capacity' in line:
output_line['design_capacity_mah'] = line.split()[4]
Expand All @@ -359,10 +355,7 @@ def parse(data, raw=False, quiet=False):
if obj_type == 'Adapter':
output_line['type'] = obj_type
output_line['id'] = obj_id
if 'on-line' in line:
output_line['on-line'] = True
else:
output_line['on-line'] = False
output_line['on-line'] = 'on-line' in line

if obj_type == 'Thermal':
output_line['type'] = obj_type
Expand Down