1717from __future__ import annotations
1818
1919from pathlib import Path
20- from typing import Callable , List , Optional , Sequence , Tuple
20+ from typing import Callable , Dict , List , Optional , Sequence , Tuple
2121
2222from easyhid import Enumeration
2323
@@ -256,7 +256,7 @@ def open(
256256 connected = get_connected_devices ()
257257 if not connected :
258258 raise RuntimeError ("No connected or supported devices found." )
259- device = connected [0 ][ 1 ]
259+ device = connected [0 ]
260260
261261 if device not in device_specs :
262262 raise ValueError (f"Unknown device: '{ device } '. Available: { list (device_specs .keys ())} " )
@@ -323,12 +323,11 @@ def open_with_config(
323323 )
324324
325325
326- def get_connected_paths_and_names () -> Tuple [ List [ str ], List [ str ] ]:
326+ def get_connected_paths_and_names () -> Dict [ str , str ]:
327327 """Return the paths and names of the supported devices currently connected.
328328
329329 Returns:
330- Tuple of two lists: (device_paths, device_names).
331- Tuple of empty lists if no supported devices are found.
330+ Dict of paths: device names (e.g., {"/dev/hidraw0": "SpaceMouse Pro"}).
332331
333332 Raises:
334333 RuntimeError: If HID API is not installed.
@@ -341,15 +340,13 @@ def get_connected_paths_and_names() -> Tuple[List[str], List[str]]:
341340 ) from e
342341
343342 device_specs = get_device_specs ()
344- device_paths = []
345- device_names = []
343+ devices_by_path = {}
346344
347345 # hid.find() is all connected HID devices,
348346 # device_specs is all supported Spacemouse devices.
349347 for hid_device in hid .find ():
350348 for name , spec in device_specs .items ():
351349 if hid_device .vendor_id == spec .vendor_id and hid_device .product_id == spec .product_id :
352- device_paths .append (hid_device .path )
353- device_names .append (name )
350+ devices_by_path [hid_device .path ] = name
354351
355- return device_paths , device_names
352+ return devices_by_path
0 commit comments