kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.82k stars 202 forks source link

Fix broken bluetoothctl parser #598

Open tzeikob opened 4 days ago

tzeikob commented 4 days ago

The bluetoothctl parser seems to be broken failing to extract and resolve part of the information the bluetoothctl package is giving to the user.

jc version:  1.25.3
python interpreter version:  3.12.3
python path:  /usr/bin/python3

bluetoothctl show:

Controller 48:A4:72:3C:96:63 (public)
    Manufacturer: 0x0002 (2)
    Version: 0x08 (8)
    Name: ubuntu
    Alias: ubuntu
    Class: 0x007c0104 (8126724)
    Powered: yes
    Discoverable: no
    DiscoverableTimeout: 0x000000b4 (180)
    Pairable: no
    UUID: Message Notification Se.. (00001133-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: OBEX Object Push          (00001105-0000-1000-8000-00805f9b34fb)
    UUID: Message Access Server     (00001132-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: IrMC Sync                 (00001104-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (00005005-0000-1000-8000-0002ee000001)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Phonebook Access Server   (0000112f-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree Audio Gateway   (0000111f-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: OBEX File Transfer        (00001106-0000-1000-8000-00805f9b34fb)
    UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0548
    Discovering: no
    Roles: central
    Roles: peripheral
Advertising Features:
    ActiveInstances: 0x00 (0)
    SupportedInstances: 0x05 (5)
    SupportedIncludes: tx-power
    SupportedIncludes: appearance
    SupportedIncludes: local-name

bluetoothctl show | jc --bluetoothctl

[
  {
    "name": "",
    "is_default": false,
    "is_public": true,
    "is_random": false,
    "address": "48:A4:72:3C:96:63",
    "alias": "",
    "class": "",
    "powered": "",
    "discoverable": "",
    "discoverable_timeout": "",
    "pairable": "",
    "modalias": "",
    "discovering": "",
    "uuids": []
  }
]
tzeikob commented 4 days ago

@kellyjonbrazil perhaps more parts are broken in the parser. I'm on it!

tzeikob commented 3 days ago

I found the root of the cause, it seems that bluetoothctl show is now giving extra attributes like the manufacturer and the version of a controller, breaking the order of the controller's regexp sheme in the bluetoothctl parser file.

I fixed it, soon I'll post a PR.

kellyjonbrazil commented 2 days ago

Thanks for the fix! I'll merge it soon so it will go into the next release.