Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/blinkstick/backends/unix_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,29 @@ def get_attached_blinkstick_devices(
raise USBBackendNotAvailable(
"Could not find USB backend. Is libusb installed?"
)
return [
# TODO: refactor this to DRY up the usb.util.get_string calls
BlinkStickDevice(
raw_device=device,
serial_details=SerialDetails(
serial=str(usb.util.get_string(device, 3, 1033))
),
manufacturer=str(usb.util.get_string(device, 1, 1033)),
version_attribute=device.bcdDevice,
description=str(usb.util.get_string(device, 2, 1033)),
)
for device in raw_devices
]

try:
devices = [
# TODO: refactor this to DRY up the usb.util.get_string calls
BlinkStickDevice(
raw_device=device,
serial_details=SerialDetails(
serial=str(usb.util.get_string(device, 3, 1033))
),
manufacturer=str(usb.util.get_string(device, 1, 1033)),
version_attribute=device.bcdDevice,
description=str(usb.util.get_string(device, 2, 1033)),
)
for device in raw_devices
]
except usb.core.USBError as e:
# if the error is due to a permission issue, raise a more specific exception
if "Operation not permitted" in str(e):
raise USBBackendNotAvailable(
"Permission denied accessing USB backend. Does a udev rule need to be added?"
)
raise
return devices

@staticmethod
def find_by_serial(serial: str) -> list[BlinkStickDevice[usb.core.Device]] | None:
Expand Down