diff --git a/jc/parsers/bluetoothctl.py b/jc/parsers/bluetoothctl.py index 3d241334..370b1d9a 100644 --- a/jc/parsers/bluetoothctl.py +++ b/jc/parsers/bluetoothctl.py @@ -139,6 +139,7 @@ try: "alias": str, "class": str, "powered": str, + "power_state": str, "discoverable": str, "discoverable_timeout": str, "pairable": str, @@ -185,6 +186,7 @@ _controller_line_pattern = ( + r"|\s*Alias:\s*(?P.+)" + r"|\s*Class:\s*(?P.+)" + r"|\s*Powered:\s*(?P.+)" + + r"|\s*PowerState:\s*(?P.+)" + r"|\s*Discoverable:\s*(?P.+)" + r"|\s*DiscoverableTimeout:\s*(?P.+)" + r"|\s*Pairable:\s*(?P.+)" @@ -219,6 +221,7 @@ def _parse_controller(next_lines: List[str]) -> Optional[Controller]: "alias": '', "class": '', "powered": '', + "power_state": '', "discoverable": '', "discoverable_timeout": '', "pairable": '', @@ -261,6 +264,8 @@ def _parse_controller(next_lines: List[str]) -> Optional[Controller]: controller["class"] = matches["class"] elif matches["powered"]: controller["powered"] = matches["powered"] + elif matches["power_state"]: + controller["power_state"] = matches["power_state"] elif matches["discoverable"]: controller["discoverable"] = matches["discoverable"] elif matches["discoverable_timeout"]: diff --git a/tests/fixtures/generic/bluetoothctl_controller_2.out b/tests/fixtures/generic/bluetoothctl_controller_2.out new file mode 100644 index 00000000..1024227f --- /dev/null +++ b/tests/fixtures/generic/bluetoothctl_controller_2.out @@ -0,0 +1,20 @@ +Controller CC:52:AF:17:6A:E4 (public) + Manufacturer: 0x000f (15) + Version: 0x05 (5) + Name: starbase + Alias: starbase + Class: 0x006c010c (7078156) + Powered: yes + PowerState: on + Discoverable: no + DiscoverableTimeout: 0x000000b4 (180) + Pairable: no + UUID: Handsfree (0000111e-0000-1000-8000-00805f9b34fb) + UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb) + UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb) + UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) + UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb) + UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb) + UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb) + Modalias: usb:v1D6Bp0246d054F + Discovering: no diff --git a/tests/test_bluetoothctl.py b/tests/test_bluetoothctl.py index 1df04213..85076103 100644 --- a/tests/test_bluetoothctl.py +++ b/tests/test_bluetoothctl.py @@ -104,7 +104,48 @@ class BluetoothctlTests(unittest.TestCase): if actual: for k, v in expected.items(): self.assertEqual(v, actual[0][k], f"Controller regex failed on {k}") - + + def test_bluetoothctl_controller_2(self): + """ + Test 'bluetoothctl' with controller 2 + """ + + with open("tests/fixtures/generic/bluetoothctl_controller_2.out", "r") as f: + output = f.read() + + actual = parse(output, quiet=True) + + self.assertIsNotNone(actual) + self.assertIsNotNone(actual[0]) + + expected = { + "address": "CC:52:AF:17:6A:E4", + "is_public": True, + "name": "starbase", + "alias": "starbase", + "class": "0x006c010c (7078156)", + "powered": "yes", + "power_state": "on", + "discoverable": "no", + "discoverable_timeout": "0x000000b4 (180)", + "pairable": "no", + "uuids": [ + "Handsfree (0000111e-0000-1000-8000-00805f9b34fb)", + "Audio Source (0000110a-0000-1000-8000-00805f9b34fb)", + "Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)", + "PnP Information (00001200-0000-1000-8000-00805f9b34fb)", + "A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)", + "A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)", + "Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)" + ], + "modalias": "usb:v1D6Bp0246d054F", + "discovering": "no" + } + + if actual: + for k, v in expected.items(): + self.assertEqual(v, actual[0][k], f"Controller regex failed on {k}") + def test_bluetoothctl_controller_with_manufacturer(self): """ Test 'bluetoothctl' with controller having manufacturer attr