Skip to content

Commit 89961fa

Browse files
committed
labgrid-suggest: prefer properties of the device itself
As the default udev configuration enables the path_id and usb_id helpers for many USB-based devices, first check if ID_PATH or ID_SERIAL_SHORT are available on the device itself. Use the parent USB device only if it's not found. Signed-off-by: Jan Luebbe <[email protected]>
1 parent 878ae59 commit 89961fa

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

labgrid/resource/udev.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,18 @@ def suggest_match(self, device):
8585
if self.device.properties.get('ID_REVISION'):
8686
meta['revision'] = self.device.properties.get('ID_REVISION')
8787

88-
if self.match.get('SUBSYSTEM', None) == 'usb':
89-
path = self._get_usb_device().properties.get('ID_PATH')
90-
if path:
91-
suggestions.append({'ID_PATH': path})
92-
serial = self._get_usb_device().properties.get('ID_SERIAL_SHORT')
93-
if serial:
94-
suggestions.append({'ID_SERIAL_SHORT': serial})
88+
path = self.device.properties.get('ID_PATH')
89+
if path:
90+
suggestions.append({'ID_PATH': path})
9591
elif self.match.get('@SUBSYSTEM', None) == 'usb':
9692
path = self._get_usb_device().properties.get('ID_PATH')
9793
if path:
9894
suggestions.append({'@ID_PATH': path})
95+
96+
serial = self.device.properties.get('ID_SERIAL_SHORT')
97+
if serial:
98+
suggestions.append({'ID_SERIAL_SHORT': serial})
99+
elif self.match.get('@SUBSYSTEM', None) == 'usb':
99100
serial = self._get_usb_device().properties.get('ID_SERIAL_SHORT')
100101
if serial:
101102
suggestions.append({'@ID_SERIAL_SHORT': serial})

man/labgrid-suggest.1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,30 @@ enable debug mode
5454
.SH EXAMPLES
5555
.sp
5656
For a device that has an \fBID_SERIAL_SHORT\fP key with a unique ID embedded
57-
in the USB\-serial converter, the resource match configuration is:
57+
in the USB\-serial converter, \fBlabgrid\-suggest\fP shows two alternatives:
5858
.INDENT 0.0
5959
.INDENT 3.5
6060
.sp
6161
.nf
6262
.ft C
63+
=== added device ===
64+
USBSerialPort for /devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1\-3/1\-3.1/1\-3.1:1.0/ttyUSB0/tty/ttyUSB0
65+
=== device properties ===
66+
device node: /dev/ttyUSB0
67+
udev tags: , systemd
68+
vendor: Silicon_Labs
69+
vendor (DB): Advanced Micro Devices, Inc. [AMD]
70+
model: CP2102_USB_to_UART_Bridge_Controller
71+
revision: 0100
72+
=== suggested matches ===
6373
USBSerialPort:
6474
match:
65-
\(aq@ID_SERIAL_SHORT\(aq: \(aqP\-00\-00682\(aq
75+
ID_PATH: pci\-0000:02:00.0\-usb\-0:3.1:1.0
76+
\-\-\-
77+
USBSerialPort:
78+
match:
79+
ID_SERIAL_SHORT: P\-00\-03564
80+
\-\-\-
6681
.ft P
6782
.fi
6883
.UNINDENT

man/labgrid-suggest.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,28 @@ EXAMPLES
4545
--------
4646

4747
For a device that has an ``ID_SERIAL_SHORT`` key with a unique ID embedded
48-
in the USB-serial converter, the resource match configuration is:
48+
in the USB-serial converter, ``labgrid-suggest`` shows two alternatives:
4949

5050
.. code-block:: yaml
5151
52+
=== added device ===
53+
USBSerialPort for /devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1-3/1-3.1/1-3.1:1.0/ttyUSB0/tty/ttyUSB0
54+
=== device properties ===
55+
device node: /dev/ttyUSB0
56+
udev tags: , systemd
57+
vendor: Silicon_Labs
58+
vendor (DB): Advanced Micro Devices, Inc. [AMD]
59+
model: CP2102_USB_to_UART_Bridge_Controller
60+
revision: 0100
61+
=== suggested matches ===
5262
USBSerialPort:
5363
match:
54-
'@ID_SERIAL_SHORT': 'P-00-00682'
55-
64+
ID_PATH: pci-0000:02:00.0-usb-0:3.1:1.0
65+
---
66+
USBSerialPort:
67+
match:
68+
ID_SERIAL_SHORT: P-00-03564
69+
---
5670
5771
SEE ALSO
5872
--------

0 commit comments

Comments
 (0)