mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
fix for battery not charging message
This commit is contained in:
@ -2,6 +2,7 @@ jc changelog
|
|||||||
|
|
||||||
20230417 v1.23.2
|
20230417 v1.23.2
|
||||||
- Add `bluetoothctl` command parser
|
- 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 `iwconfig` command parser for SSIDs with dashes in the name
|
||||||
- Fix `crontab` command parsers for incorrect variable parsing in some cases
|
- Fix `crontab` command parsers for incorrect variable parsing in some cases
|
||||||
- Fix pytest warnings
|
- Fix pytest warnings
|
||||||
|
@ -250,4 +250,4 @@ Returns:
|
|||||||
### Parser Information
|
### Parser Information
|
||||||
Compatibility: linux
|
Compatibility: linux
|
||||||
|
|
||||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||||
|
@ -227,7 +227,7 @@ import jc.utils
|
|||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.5'
|
version = '1.6'
|
||||||
description = '`acpi` command parser'
|
description = '`acpi` command parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@ -333,7 +333,14 @@ def parse(data, raw=False, quiet=False):
|
|||||||
if obj_type == 'Battery':
|
if obj_type == 'Battery':
|
||||||
output_line['type'] = obj_type
|
output_line['type'] = obj_type
|
||||||
output_line['id'] = obj_id
|
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['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:
|
||||||
|
1
tests/fixtures/generic/acpi-not-charging.json
vendored
Normal file
1
tests/fixtures/generic/acpi-not-charging.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"type":"Battery","id":0,"state":"Not charging","charge_percent":100}]
|
1
tests/fixtures/generic/acpi-not-charging.out
vendored
Normal file
1
tests/fixtures/generic/acpi-not-charging.out
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Battery 0: Not charging, 100%
|
@ -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:
|
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()
|
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
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V.json'), 'r', encoding='utf-8') as f:
|
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())
|
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:
|
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())
|
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):
|
def test_acpi_nodata(self):
|
||||||
"""
|
"""
|
||||||
Test 'acpi' with no data
|
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)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user