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.69k stars 195 forks source link

[BUG?] Bluetoothctl Not Parsing Correctly #419

Closed Stetsed closed 1 year ago

Stetsed commented 1 year ago

I am currently trying to integrate JC into my workflow due to it allow me to much easier create widgets with JSON data. I'm trying to parse the bluetoothctl devices command but it isn't filling in most of the classes. And even when I use bluetooth info MAC and then parse that it doesn't get it either while the command does output it.

❯ bluetoothctl info DF:1C:C3:B4:1A:1F | jc --bluetoothctl -p
[
  {
    "name": "M585/M590",
    "is_public": false,
    "address": "DF:1C:C3:B4:1A:1F",
    "alias": "M585/M590",
    "class": "",
    "icon": "",
    "paired": "",
    "bonded": "",
    "trusted": "",
    "blocked": "",
    "connected": "",
    "legacy_pairing": "",
    "rssi": 0,
    "txpower": 0,
    "uuids": []
  }
]

~ 
❯ bluetoothctl info DF:1C:C3:B4:1A:1F
Device DF:1C:C3:B4:1A:1F (random)
    Name: M585/M590
    Alias: M585/M590
    Appearance: 0x03c2
    Icon: input-mouse
    Paired: yes
    Bonded: yes
    Trusted: no
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
    UUID: Human Interface Device    (00001812-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (00010000-0000-1000-8000-011f2000046d)
    Modalias: usb:v046DpB01Bd0011
    Battery Percentage: 0x64 (100)
Stetsed commented 1 year ago

Okay I was able to fix it by using JC directly

Stetsed commented 1 year ago

Edit it turns out to be an issue with my mouse as that's the only thing that outputs JSON wrong

kellyjonbrazil commented 1 year ago

Could you copy paste the mouse bluetoothctl output? Maybe we can fix that.

Stetsed commented 1 year ago

@kellyjonbrazil

Device DF:1C:C3:B4:1A:1F (random)
    Name: M585/M590
    Alias: M585/M590
    Appearance: 0x03c2
    Icon: input-mouse
    Paired: yes
    Bonded: yes
    Trusted: no
    Blocked: no
    Connected: no
    LegacyPairing: no
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
    UUID: Human Interface Device    (00001812-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (00010000-0000-1000-8000-011f2000046d)
    Modalias: usb:v046DpB01Bd0011
Stetsed commented 1 year ago

I also tried switching from the jc package to jc-git and that didn't fix it

kellyjonbrazil commented 1 year ago

@tzeikob want to take a look at this?

tzeikob commented 1 year ago

Sure, I'll try to reproduce the error by passing the output given directly via the bluetoothctl.

My first take on this is that the culprit might be the (random) next to the mac address, where public or none is the expected value.