forked from auracaster/bumble_mirror
pyusb: power_cycle if '!' is present at the start of the transport
This commit is contained in:
@@ -227,6 +227,10 @@ async def open_pyusb_transport(spec: str) -> Transport:
|
|||||||
usb_find = libusb_package.find
|
usb_find = libusb_package.find
|
||||||
|
|
||||||
# Find the device according to the spec moniker
|
# Find the device according to the spec moniker
|
||||||
|
power_cycle = False
|
||||||
|
if spec.startswith('!'):
|
||||||
|
power_cycle = True
|
||||||
|
spec = spec[1:]
|
||||||
if ':' in spec:
|
if ':' in spec:
|
||||||
vendor_id, product_id = spec.split(':')
|
vendor_id, product_id = spec.split(':')
|
||||||
device = usb_find(idVendor=int(vendor_id, 16), idProduct=int(product_id, 16))
|
device = usb_find(idVendor=int(vendor_id, 16), idProduct=int(product_id, 16))
|
||||||
@@ -259,11 +263,12 @@ async def open_pyusb_transport(spec: str) -> Transport:
|
|||||||
logger.debug(f'USB Device: {device}')
|
logger.debug(f'USB Device: {device}')
|
||||||
|
|
||||||
# Power Cycle the device
|
# Power Cycle the device
|
||||||
try:
|
if power_cycle:
|
||||||
device = await _power_cycle(device) # type: ignore
|
try:
|
||||||
except Exception as e:
|
device = await _power_cycle(device) # type: ignore
|
||||||
logging.debug(e)
|
except Exception as e:
|
||||||
logging.info(f"Unable to power cycle {hex(device.idVendor)} {hex(device.idProduct)}") # type: ignore
|
logging.debug(e)
|
||||||
|
logging.info(f"Unable to power cycle {hex(device.idVendor)} {hex(device.idProduct)}") # type: ignore
|
||||||
|
|
||||||
# Collect the metadata
|
# Collect the metadata
|
||||||
device_metadata = {'vendor_id': device.idVendor, 'product_id': device.idProduct}
|
device_metadata = {'vendor_id': device.idVendor, 'product_id': device.idProduct}
|
||||||
|
|||||||
Reference in New Issue
Block a user