mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-05 00:49:03 +02:00
Fix broken controller parser schema to include power state prop (#652)
This commit fixes issue #627 Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
@ -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<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>.+)"
|
||||
@ -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"]:
|
||||
|
20
tests/fixtures/generic/bluetoothctl_controller_2.out
vendored
Normal file
20
tests/fixtures/generic/bluetoothctl_controller_2.out
vendored
Normal file
@ -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
|
@ -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
|
||||
|
Reference in New Issue
Block a user