Skip to content

Commit 5669fdf

Browse files
authored
bdDetect: Enrich USB serial data with info about USB device (#15764)
Many braille displays use a serial converter from FTDI with VID 0x403" and PID 0x6001. Given the weird nature of Albatross devices not being able to identify themselves on request, the Albatross driver is currently a disturbing factor in automatic detection. Description of user facing changes None. Description of development approach This pr enriches information for serial ports in bdDetect. The _DeviceInfoFetcher class now has an extra autoprop usbComPorts that bundles com port info with USB metadata. If all works as expected, the Albatross driver will be able to limit itself to Albatross devices only after this pr by using the busReportedDeviceDescription dictionary entry. Removed duplicated code from hwPortUtils
1 parent 70e19c9 commit 5669fdf

3 files changed

Lines changed: 337 additions & 304 deletions

File tree

‎source/bdDetect.py‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ def getDriversForConnectedUsbDevices(
141141
)
142142
usbComDeviceMatches = (
143143
DeviceMatch(DeviceType.SERIAL, port["usbID"], port["port"], port)
144-
for port in deviceInfoFetcher.comPorts
145-
if "usbID" in port
144+
for port in deviceInfoFetcher.usbComPorts
146145
)
147146
# Tee is used to ensure that the DeviceMatches aren't created multiple times.
148147
# The processing of these HID device matches, looking for a custom driver, means that all
@@ -256,9 +255,9 @@ def _set_btDevsCache(
256255
self._btDevsCache = cache.copy() if cache else None
257256

258257
#: Type info for auto property: _get_comPorts
259-
comPorts: List[Dict]
258+
comPorts: list[dict[str, str]]
260259

261-
def _get_comPorts(self) -> List[Dict]:
260+
def _get_comPorts(self) -> list[dict[str, str]]:
262261
return list(hwPortUtils.listComPorts(onlyAvailable=True))
263262

264263
#: Type info for auto property: _get_usbDevices
@@ -267,6 +266,21 @@ def _get_comPorts(self) -> List[Dict]:
267266
def _get_usbDevices(self) -> List[Dict]:
268267
return list(hwPortUtils.listUsbDevices(onlyAvailable=True))
269268

269+
#: Type info for auto property: _get_usbComPorts
270+
usbComPorts: list[dict[str, str]]
271+
272+
def _get_usbComPorts(self) -> list[dict[str, str]]:
273+
comPorts = []
274+
for port in self.comPorts:
275+
if (usbId := port.get("usbID")) is None:
276+
continue
277+
if (usbDict := next(
278+
(d for d in self.usbDevices if d.get("usbID") == usbId),
279+
None
280+
)) is not None:
281+
comPorts.append(port | usbDict)
282+
return comPorts
283+
270284
#: Type info for auto property: _get_hidDevices
271285
hidDevices: List[Dict]
272286

@@ -454,7 +468,7 @@ def getConnectedUsbDevicesForDriver(driver: str) -> Iterator[DeviceMatch]:
454468
),
455469
(
456470
DeviceMatch(DeviceType.SERIAL, port["usbID"], port["port"], port)
457-
for port in deviceInfoFetcher.comPorts if "usbID" in port
471+
for port in deviceInfoFetcher.usbComPorts
458472
)
459473
)
460474
for match in usbDevs:

0 commit comments

Comments
 (0)