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

Fix broken controller parser schema to include power state prop #628

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions jc/parsers/bluetoothctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class info():
"alias": str,
"class": str,
"powered": str,
"power_state": str,
"discoverable": str,
"discoverable_timeout": str,
"pairable": str,
Expand Down Expand Up @@ -185,6 +186,7 @@ class info():
+ r"|\s*Alias:\s*(?P<alias>.+)"
+ r"|\s*Class:\s*(?P<class>.+)"
+ r"|\s*Powered:\s*(?P<powered>.+)"
+ r"|\s*PowerState:\s*(?P<power_state>.+)"
+ r"|\s*Discoverable:\s*(?P<discoverable>.+)"
+ r"|\s*DiscoverableTimeout:\s*(?P<discoverable_timeout>.+)"
+ r"|\s*Pairable:\s*(?P<pairable>.+)"
Expand Down Expand Up @@ -219,6 +221,7 @@ def _parse_controller(next_lines: List[str]) -> Optional[Controller]:
"alias": '',
"class": '',
"powered": '',
"power_state": '',
"discoverable": '',
"discoverable_timeout": '',
"pairable": '',
Expand Down Expand Up @@ -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"]:
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/generic/bluetoothctl_controller_2.out
Original file line number Diff line number Diff line change
@@ -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
43 changes: 42 additions & 1 deletion tests/test_bluetoothctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,48 @@ def test_bluetoothctl_controller(self):
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": "yes"
}

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
Expand Down
Loading