Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not hid:
if sys.platform.startswith('linux'):
hid = 'hidraw'
elif sys.platform == 'darwin':
hid = 'hid'
else:
hid = 'usb'
api = globals()[hid]
if hid.startswith('hid'):
handles = HidapiDevice.enumerate(api, vendor, product)
else:
handles = PyUsbHid.enumerate(vendor, product)
drivers = sorted(find_all_subclasses(UsbHidDriver), key=lambda x: x.__name__)
LOGGER.debug('searching %s (api=%s, drivers=[%s])', self.__class__.__name__, api.__name__,
', '.join(map(lambda x: x.__name__, drivers)))
for handle in handles:
if bus and handle.bus != bus:
continue
if address and handle.address != address:
continue
if usb_port and handle.port != usb_port:
continue
LOGGER.debug('probing drivers for device %s:%s', hex(handle.vendor_id),
hex(handle.product_id))
for drv in drivers:
yield from drv.probe(handle, vendor=vendor, product=product, **kwargs)
def find_liquidctl_devices(pick=None, **kwargs):
"""Find devices and instantiate corresponding liquidctl drivers.
Probes all buses and drivers that have been loaded by the time of the call
and yields driver instances.
Filter conditions can be passed through to the buses and drivers via
`**kwargs`. A driver instance will be yielded for each compatible device
that matches the supplied filter conditions.
If `pick` is passed, only the driver instance for the `(pick + 1)`-th
matched device will be yielded.
"""
buses = sorted(find_all_subclasses(BaseBus), key=lambda x: x.__name__)
num = 0
for bus_cls in buses:
for dev in bus_cls().find_devices(**kwargs):
if not pick is None:
if num == pick:
yield dev
return
num += 1
else:
yield dev
def find_devices(self, vendor=None, product=None, bus=None, address=None,
usb_port=None, **kwargs):
""" Find compatible regular USB devices."""
drivers = sorted(find_all_subclasses(UsbDriver), key=lambda x: x.__name__)
LOGGER.debug('searching %s (drivers=[%s])', self.__class__.__name__,
', '.join(map(lambda x: x.__name__, drivers)))
for handle in PyUsbDevice.enumerate(vendor, product):
if bus and handle.bus != bus:
continue
if address and handle.address != address:
continue
if usb_port and handle.port != usb_port:
continue
LOGGER.debug('probing drivers for device %s:%s', hex(handle.vendor_id),
hex(handle.product_id))
for drv in drivers:
yield from drv.probe(handle, vendor=vendor, product=product, **kwargs)