Skip to content

Commit

Permalink
pyusb: power_cycle if '!' is present at the start of the transport
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverBzH committed Apr 17, 2024
1 parent 049f902 commit 71df062
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions bumble/transport/pyusb.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ async def close(self):
usb_find = libusb_package.find

# Find the device according to the spec moniker
power_cycle = False
if spec.startswith('!'):
power_cycle = True
spec = spec[1:]
if ':' in spec:
vendor_id, product_id = spec.split(':')
device = usb_find(idVendor=int(vendor_id, 16), idProduct=int(product_id, 16))
Expand Down Expand Up @@ -259,11 +263,12 @@ def device_path(device):
logger.debug(f'USB Device: {device}')

# Power Cycle the device
try:
device = await _power_cycle(device) # type: ignore
except Exception as e:
logging.debug(e)
logging.info(f"Unable to power cycle {hex(device.idVendor)} {hex(device.idProduct)}") # type: ignore
if power_cycle:
try:
device = await _power_cycle(device) # type: ignore
except Exception as e:
logging.debug(e)
logging.info(f"Unable to power cycle {hex(device.idVendor)} {hex(device.idProduct)}") # type: ignore

# Collect the metadata
device_metadata = {'vendor_id': device.idVendor, 'product_id': device.idProduct}
Expand Down

0 comments on commit 71df062

Please sign in to comment.