Add manufacturer
This commit is contained in:
parent
5779599000
commit
6a8bf6c27f
2 changed files with 32 additions and 2 deletions
|
|
@ -583,6 +583,12 @@ def build_arg_parser() -> argparse.ArgumentParser:
|
|||
default=[],
|
||||
help="Only include serial ports whose description contains this substring (case-insensitive). Repeatable.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--include-port-manufacturer",
|
||||
action="append",
|
||||
default=[],
|
||||
help="Only include serial ports whose manufacturer contains this substring (case-insensitive). Repeatable.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--include-controller-name",
|
||||
action="append",
|
||||
|
|
@ -673,6 +679,7 @@ class PairingState:
|
|||
include_non_usb: bool = False
|
||||
ignore_port_desc: List[str] = field(default_factory=list)
|
||||
include_port_desc: List[str] = field(default_factory=list)
|
||||
include_port_mfr: List[str] = field(default_factory=list)
|
||||
|
||||
|
||||
def load_button_maps(console: Console, args: argparse.Namespace) -> Tuple[Dict[int, SwitchButton], Dict[int, SwitchButton], set[int]]:
|
||||
|
|
@ -798,6 +805,7 @@ def prepare_pairing_state(
|
|||
include_non_usb = args.all_ports or False
|
||||
ignore_port_desc = [d.lower() for d in args.ignore_port_desc]
|
||||
include_port_desc = [d.lower() for d in args.include_port_desc]
|
||||
include_port_mfr = [m.lower() for m in args.include_port_manufacturer]
|
||||
available_ports: List[str] = []
|
||||
|
||||
mappings = list(args.map)
|
||||
|
|
@ -809,6 +817,7 @@ def prepare_pairing_state(
|
|||
include_non_usb=include_non_usb,
|
||||
ignore_descriptions=ignore_port_desc,
|
||||
include_descriptions=include_port_desc,
|
||||
include_manufacturers=include_port_mfr,
|
||||
)
|
||||
if not discovered:
|
||||
parser.error("No UART devices found for interactive pairing.")
|
||||
|
|
@ -825,6 +834,7 @@ def prepare_pairing_state(
|
|||
include_non_usb=include_non_usb,
|
||||
ignore_descriptions=ignore_port_desc,
|
||||
include_descriptions=include_port_desc,
|
||||
include_manufacturers=include_port_mfr,
|
||||
)
|
||||
if discovered:
|
||||
available_ports.extend(info["device"] for info in discovered)
|
||||
|
|
@ -843,6 +853,7 @@ def prepare_pairing_state(
|
|||
include_non_usb=include_non_usb,
|
||||
ignore_port_desc=ignore_port_desc,
|
||||
include_port_desc=include_port_desc,
|
||||
include_port_mfr=include_port_mfr,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -902,6 +913,7 @@ def discover_new_ports(pairing: PairingState, contexts: Dict[int, ControllerCont
|
|||
include_non_usb=pairing.include_non_usb,
|
||||
ignore_descriptions=pairing.ignore_port_desc,
|
||||
include_descriptions=pairing.include_port_desc,
|
||||
include_manufacturers=pairing.include_port_mfr,
|
||||
)
|
||||
current_paths = {info["device"] for info in discovered}
|
||||
known_paths = set(pairing.available_ports)
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ def discover_serial_ports(
|
|||
include_non_usb: bool = False,
|
||||
ignore_descriptions: Optional[List[str]] = None,
|
||||
include_descriptions: Optional[List[str]] = None,
|
||||
include_manufacturers: Optional[List[str]] = None,
|
||||
) -> List[Dict[str, str]]:
|
||||
"""
|
||||
List serial ports with simple filtering similar to controller_uart_bridge.
|
||||
|
|
@ -96,9 +97,11 @@ def discover_serial_ports(
|
|||
include_non_usb: Include ports that don't look USB-based (e.g., onboard UARTs).
|
||||
ignore_descriptions: Substrings (case-insensitive) to exclude by description.
|
||||
include_descriptions: If provided, only include ports whose description contains one of these substrings.
|
||||
include_manufacturers: If provided, only include ports whose manufacturer contains one of these substrings.
|
||||
"""
|
||||
ignored = [d.lower() for d in (ignore_descriptions or [])]
|
||||
includes = [d.lower() for d in (include_descriptions or [])]
|
||||
include_mfrs = [m.lower() for m in (include_manufacturers or [])]
|
||||
results: List[Dict[str, str]] = []
|
||||
for port in list_ports.comports():
|
||||
path = port.device or ""
|
||||
|
|
@ -107,11 +110,20 @@ def discover_serial_ports(
|
|||
if not include_non_usb and not _is_usb_serial_port(port):
|
||||
continue
|
||||
desc_lower = (port.description or "").lower()
|
||||
mfr_lower = (port.manufacturer or "").lower()
|
||||
if include_mfrs and not any(keep in mfr_lower for keep in include_mfrs):
|
||||
continue
|
||||
if includes and not any(keep in desc_lower for keep in includes):
|
||||
continue
|
||||
if any(skip in desc_lower for skip in ignored):
|
||||
continue
|
||||
results.append({"device": path, "description": port.description or "Unknown"})
|
||||
results.append(
|
||||
{
|
||||
"device": path,
|
||||
"description": port.description or "Unknown",
|
||||
"manufacturer": port.manufacturer or "",
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
|
|
@ -119,9 +131,15 @@ def first_serial_port(
|
|||
include_non_usb: bool = False,
|
||||
ignore_descriptions: Optional[List[str]] = None,
|
||||
include_descriptions: Optional[List[str]] = None,
|
||||
include_manufacturers: Optional[List[str]] = None,
|
||||
) -> Optional[str]:
|
||||
"""Return the first discovered serial port path (or None if none are found)."""
|
||||
ports = discover_serial_ports(include_non_usb, ignore_descriptions, include_descriptions)
|
||||
ports = discover_serial_ports(
|
||||
include_non_usb,
|
||||
ignore_descriptions,
|
||||
include_descriptions,
|
||||
include_manufacturers,
|
||||
)
|
||||
if not ports:
|
||||
return None
|
||||
return ports[0]["device"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue