Browse Source

Auto-detect device in test_sink script

If there's a single PD Buddy Sink attached, it's pretty clear which one
we want to be testing.  As such, the testing script shouldn't require
the device to be specified if it can find exactly one Sink.  This commit
does just that, and like so, I will almost never have to figure out
which device file I need when testing a Sink again.
Clara Hobbs 6 years ago
parent
commit
18dc3ae125
1 changed files with 11 additions and 2 deletions
  1. 11
    2
      pdbuddy/tools/test_sink.py

+ 11
- 2
pdbuddy/tools/test_sink.py View File

57
                     sinkinfo.product, sinkinfo.serial_number)
57
                     sinkinfo.product, sinkinfo.serial_number)
58
         sys.exit(0)
58
         sys.exit(0)
59
 
59
 
60
-    # If there's no device file specified, complain and exit
60
+    # If there's no device file specified, try to auto-detect
61
     if not args.tty:
61
     if not args.tty:
62
-        parser.error('the following arguments are required: tty')
62
+        devices = list(pdbuddy.Sink.get_devices())
63
+        # If the wrong number of devices is present, complain and exit.
64
+        if len(devices) < 1:
65
+            print('No PD Buddy Sink devices found')
66
+            sys.exit(1)
67
+        elif len(devices) > 1:
68
+            print('Multiple PD Buddy Sink devices found')
69
+            sys.exit(1)
70
+        # Set args.tty to the auto-detected Sink
71
+        args.tty = devices[0].device
63
 
72
 
64
     # Define configurations for testing
73
     # Define configurations for testing
65
     cfg_20v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
74
     cfg_20v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,

Loading…
Cancel
Save