mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
Parse numeric fields to their actual numeric value
This commit is contained in:
@ -59,8 +59,8 @@ a controller and a device but there might be fields corresponding to one entity.
|
|||||||
"blocked": string,
|
"blocked": string,
|
||||||
"connected": string,
|
"connected": string,
|
||||||
"legacy_pairing": string,
|
"legacy_pairing": string,
|
||||||
"rssi": string,
|
"rssi": int,
|
||||||
"txpower": string,
|
"txpower": int,
|
||||||
"uuids": array
|
"uuids": array
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -91,8 +91,8 @@ Examples:
|
|||||||
"Headset (00001708-0000-1000-8000-00805f9b34fb)",
|
"Headset (00001708-0000-1000-8000-00805f9b34fb)",
|
||||||
"Headset HS (00001831-0000-1000-8000-00805f9b34fb)"
|
"Headset HS (00001831-0000-1000-8000-00805f9b34fb)"
|
||||||
],
|
],
|
||||||
"rssi": "-52",
|
"rssi": -52,
|
||||||
"txpower": "4"
|
"txpower": 4
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
@ -151,14 +151,14 @@ try:
|
|||||||
"blocked": str,
|
"blocked": str,
|
||||||
"connected": str,
|
"connected": str,
|
||||||
"legacy_pairing": str,
|
"legacy_pairing": str,
|
||||||
"rssi": str,
|
"rssi": int,
|
||||||
"txpower": str,
|
"txpower": int,
|
||||||
"uuids": List[str],
|
"uuids": List[str],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
Controller = Dict[str, Union[str, bool, List[str]]]
|
Controller = Dict[str, Union[str, bool, List[str]]]
|
||||||
Device = Dict[str, Union[str, bool, List[str]]]
|
Device = Dict[str, Union[str, bool, int, List[str]]]
|
||||||
|
|
||||||
|
|
||||||
_controller_head_pattern = r"Controller (?P<address>([0-9A-F]{2}:){5}[0-9A-F]{2}) (?P<name>.+)"
|
_controller_head_pattern = r"Controller (?P<address>([0-9A-F]{2}:){5}[0-9A-F]{2}) (?P<name>.+)"
|
||||||
@ -318,9 +318,17 @@ def _parse_device(next_lines: List[str]) -> Device:
|
|||||||
elif matches["modalias"]:
|
elif matches["modalias"]:
|
||||||
device["modalias"] = matches["modalias"]
|
device["modalias"] = matches["modalias"]
|
||||||
elif matches["rssi"]:
|
elif matches["rssi"]:
|
||||||
device["rssi"] = matches["rssi"]
|
rssi = matches["rssi"]
|
||||||
|
try:
|
||||||
|
device["rssi"] = int(rssi)
|
||||||
|
except ValueError and not quiet:
|
||||||
|
jc.utils.warning_message([f"{next_line} : rssi - {rssi} is not int-able"])
|
||||||
elif matches["txpower"]:
|
elif matches["txpower"]:
|
||||||
device["txpower"] = matches["txpower"]
|
txpower = matches["txpower"]
|
||||||
|
try:
|
||||||
|
device["txpower"] = int(txpower)
|
||||||
|
except ValueError and not quiet:
|
||||||
|
jc.utils.warning_message([f"{next_line} : txpower - {txpower} is not int-able"])
|
||||||
elif matches["uuid"]:
|
elif matches["uuid"]:
|
||||||
if not "uuids" in device:
|
if not "uuids" in device:
|
||||||
device["uuids"] = []
|
device["uuids"] = []
|
||||||
|
Reference in New Issue
Block a user