diff --git a/CHANGELOG b/CHANGELOG index d1248abe..c44e004b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ jc changelog 20230417 v1.23.2 - Add `bluetoothctl` command parser +- Fix `acpi` command parser for "Not charging" battery status lines - Fix `iwconfig` command parser for SSIDs with dashes in the name - Fix `crontab` command parsers for incorrect variable parsing in some cases - Fix pytest warnings diff --git a/docs/parsers/acpi.md b/docs/parsers/acpi.md index 22a79f54..82d57965 100644 --- a/docs/parsers/acpi.md +++ b/docs/parsers/acpi.md @@ -250,4 +250,4 @@ Returns: ### Parser Information Compatibility: linux -Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/parsers/acpi.py b/jc/parsers/acpi.py index 5afd1546..1457aecb 100644 --- a/jc/parsers/acpi.py +++ b/jc/parsers/acpi.py @@ -227,7 +227,7 @@ import jc.utils class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.5' + version = '1.6' description = '`acpi` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -333,7 +333,14 @@ def parse(data, raw=False, quiet=False): if obj_type == 'Battery': output_line['type'] = obj_type output_line['id'] = obj_id - if 'Charging' in line or 'Discharging' in line or 'Full' in line: + if 'Not charging' in line: + 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: + output_line['state'] = line.split()[2][:-1] output_line['charge_percent'] = line.split()[3].rstrip('%,') if 'will never fully discharge' in line: diff --git a/tests/fixtures/generic/acpi-not-charging.json b/tests/fixtures/generic/acpi-not-charging.json new file mode 100644 index 00000000..108fc125 --- /dev/null +++ b/tests/fixtures/generic/acpi-not-charging.json @@ -0,0 +1 @@ +[{"type":"Battery","id":0,"state":"Not charging","charge_percent":100}] diff --git a/tests/fixtures/generic/acpi-not-charging.out b/tests/fixtures/generic/acpi-not-charging.out new file mode 100644 index 00000000..b19effb2 --- /dev/null +++ b/tests/fixtures/generic/acpi-not-charging.out @@ -0,0 +1 @@ +Battery 0: Not charging, 100% diff --git a/tests/test_acpi.py b/tests/test_acpi.py index ab60049b..604864c5 100644 --- a/tests/test_acpi.py +++ b/tests/test_acpi.py @@ -27,6 +27,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V-never-fully-discharge.out'), 'r', encoding='utf-8') as f: acpi_V_never_fully_discharge = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-not-charging.out'), 'r', encoding='utf-8') as f: + acpi_not_charging = f.read() + # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V.json'), 'r', encoding='utf-8') as f: generic_acpi_V_json = json.loads(f.read()) @@ -46,6 +49,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V-never-fully-discharge.json'), 'r', encoding='utf-8') as f: acpi_V_never_fully_discharge_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-not-charging.json'), 'r', encoding='utf-8') as f: + acpi_not_charging_json = json.loads(f.read()) + def test_acpi_nodata(self): """ Test 'acpi' with no data @@ -88,6 +94,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.acpi.parse(self.acpi_V_never_fully_discharge, quiet=True), self.acpi_V_never_fully_discharge_json) + def test_acpi_not_charging(self): + """ + Test 'acpi' with "Not charging" message + """ + self.assertEqual(jc.parsers.acpi.parse(self.acpi_not_charging, quiet=True), self.acpi_not_charging_json) + if __name__ == '__main__': unittest.main()