Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 13 additions & 5 deletions src/blinkstick/backends/unix_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from blinkstick.constants import VENDOR_ID, PRODUCT_ID
from blinkstick.backends.base import BaseBackend
from blinkstick.devices import BlinkStickDevice
from blinkstick.exceptions import BlinkStickException
from blinkstick.exceptions import BlinkStickException, USBBackendNotAvailable
from blinkstick.models import SerialDetails


Expand Down Expand Up @@ -38,10 +38,18 @@ def _refresh_attached_blinkstick_device(self):
def get_attached_blinkstick_devices(
find_all: bool = True,
) -> list[BlinkStickDevice[usb.core.Device]]:
raw_devices = (
usb.core.find(find_all=find_all, idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
or []
)
try:
raw_devices = (
usb.core.find(
find_all=find_all, idVendor=VENDOR_ID, idProduct=PRODUCT_ID
)
or []
)
except usb.core.NoBackendError:
# TODO: improve this error message to provide more information on how to remediate the problem
raise USBBackendNotAvailable(
"Could not find USB backend. Is libusb installed?"
)
return [
# TODO: refactor this to DRY up the usb.util.get_string calls
BlinkStickDevice(
Expand Down
4 changes: 4 additions & 0 deletions src/blinkstick/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ class BlinkStickException(Exception):

class NotConnected(BlinkStickException):
pass


class USBBackendNotAvailable(BlinkStickException):
pass