Skip to content

Commit

Permalink
hidapi: Remove outdated logger enabled checks
Browse files Browse the repository at this point in the history
Logger enabled checks clutter the code unnecessarily. The checks are
now handled in a custom logger class. Eventually they can be completely
removed in the future.

Related #2664
  • Loading branch information
MattHag authored and pfps committed Jan 2, 2025
1 parent d42524d commit 3bf8a85
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
23 changes: 10 additions & 13 deletions lib/hidapi/hidapi_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,25 @@ def _match(
if len(report) == 1 + 6 and report[0] == 0x10:
device["hidpp_short"] = True
except HIDError as e:
if logger.isEnabledFor(logging.INFO):
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
try:
report = _get_input_report(device_handle, 0x11, 32)
if len(report) == 1 + 19 and report[0] == 0x11:
device["hidpp_long"] = True
except HIDError as e:
if logger.isEnabledFor(logging.INFO):
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
finally:
if device_handle:
close(device_handle)

if logger.isEnabledFor(logging.INFO):
logger.info(
"Found device BID %s VID %04X PID %04X HID++ %s %s",
bus_id,
vid,
pid,
device["hidpp_short"],
device["hidpp_long"],
)
logger.info(
"Found device BID %s VID %04X PID %04X HID++ %s %s",
bus_id,
vid,
pid,
device["hidpp_short"],
device["hidpp_long"],
)

if not device["hidpp_short"] and not device["hidpp_long"]:
return None
Expand Down
32 changes: 14 additions & 18 deletions lib/hidapi/udev_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def _match(action: str, device, filter_func: typing.Callable[[int, int, int, boo
interest to Solaar. It is given the bus id, vendor id, and product
id and returns a dictionary with the required hid_driver and
usb_interface and whether this is a receiver or device."""
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"Dbus event {action} {device}")
logger.debug(f"Dbus event {action} {device}")
hid_device = device.find_parent("hid")
if hid_device is None: # only HID devices are of interest to Solaar
return
Expand Down Expand Up @@ -137,18 +136,17 @@ def _match(action: str, device, filter_func: typing.Callable[[int, int, int, boo
intf_device = device.find_parent("usb", "usb_interface")
usb_interface = None if intf_device is None else intf_device.attributes.asint("bInterfaceNumber")
# print('*** usb interface', action, device, 'usb_interface:', intf_device, usb_interface, interface_number)
if logger.isEnabledFor(logging.INFO):
logger.info(
"Found device %s BID %s VID %s PID %s HID++ %s %s USB %s %s",
device.device_node,
bid,
vid,
pid,
hidpp_short,
hidpp_long,
usb_interface,
interface_number,
)
logger.info(
"Found device %s BID %s VID %s PID %s HID++ %s %s USB %s %s",
device.device_node,
bid,
vid,
pid,
hidpp_short,
hidpp_long,
usb_interface,
interface_number,
)
if not (hidpp_short or hidpp_long or interface_number is None or interface_number == usb_interface):
return
attrs = intf_device.attributes if intf_device is not None else None
Expand Down Expand Up @@ -268,8 +266,7 @@ def _process_udev_event(monitor, condition, cb, filter_func):
except Exception:
glib.io_add_watch(m, glib.IO_IN, _process_udev_event, callback, filter_func)

if logger.isEnabledFor(logging.DEBUG):
logger.debug("Starting dbus monitoring")
logger.debug("Starting dbus monitoring")
m.start()


Expand All @@ -282,8 +279,7 @@ def enumerate(filter_func: typing.Callable[[int, int, int, bool, bool], dict[str
:returns: a list of matching ``DeviceInfo`` tuples.
"""

if logger.isEnabledFor(logging.DEBUG):
logger.debug("Starting dbus enumeration")
logger.debug("Starting dbus enumeration")
for dev in pyudev.Context().list_devices(subsystem="hidraw"):
dev_info = _match(ACTION_ADD, dev, filter_func)
if dev_info:
Expand Down

0 comments on commit 3bf8a85

Please sign in to comment.