hidapi: Explicitly load hidapi/udev implementation
Linux uses udev, other platforms use the cross-platform hidapi implementation. Remove implicit loading of hidapi in hidapi/__init__.py.
This commit is contained in:
parent
99fc9c6fcb
commit
46fafa0e68
|
|
@ -1,47 +0,0 @@
|
||||||
## Copyright (C) 2012-2013 Daniel Pavel
|
|
||||||
##
|
|
||||||
## This program is free software; you can redistribute it and/or modify
|
|
||||||
## it under the terms of the GNU General Public License as published by
|
|
||||||
## the Free Software Foundation; either version 2 of the License, or
|
|
||||||
## (at your option) any later version.
|
|
||||||
##
|
|
||||||
## This program is distributed in the hope that it will be useful,
|
|
||||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
## GNU General Public License for more details.
|
|
||||||
##
|
|
||||||
## You should have received a copy of the GNU General Public License along
|
|
||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
"""Generic Human Interface Device API."""
|
|
||||||
|
|
||||||
import platform
|
|
||||||
|
|
||||||
if platform.system() in ("Darwin", "Windows"):
|
|
||||||
from hidapi.hidapi_impl import close # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import enumerate # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import find_paired_node # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import find_paired_node_wpid # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import get_manufacturer # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import get_product # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import get_serial # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import monitor_glib # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import open # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import open_path # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import read # noqa: F401
|
|
||||||
from hidapi.hidapi_impl import write # noqa: F401
|
|
||||||
else:
|
|
||||||
from hidapi.udev_impl import close # noqa: F401
|
|
||||||
from hidapi.udev_impl import enumerate # noqa: F401
|
|
||||||
from hidapi.udev_impl import find_paired_node # noqa: F401
|
|
||||||
from hidapi.udev_impl import find_paired_node_wpid # noqa: F401
|
|
||||||
from hidapi.udev_impl import get_manufacturer # noqa: F401
|
|
||||||
from hidapi.udev_impl import get_product # noqa: F401
|
|
||||||
from hidapi.udev_impl import get_serial # noqa: F401
|
|
||||||
from hidapi.udev_impl import monitor_glib # noqa: F401
|
|
||||||
from hidapi.udev_impl import open # noqa: F401
|
|
||||||
from hidapi.udev_impl import open_path # noqa: F401
|
|
||||||
from hidapi.udev_impl import read # noqa: F401
|
|
||||||
from hidapi.udev_impl import write # noqa: F401
|
|
||||||
|
|
||||||
__version__ = "0.9"
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import platform
|
||||||
import readline
|
import readline
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
@ -27,7 +28,10 @@ from select import select
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import hidapi
|
if platform.system() == "Linux":
|
||||||
|
import hidapi.udev_impl as hidapi
|
||||||
|
else:
|
||||||
|
import hidapi.hidapi_impl as hidapi
|
||||||
|
|
||||||
LOGITECH_VENDOR_ID = 0x046D
|
LOGITECH_VENDOR_ID = 0x046D
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import logging
|
import logging
|
||||||
|
import platform
|
||||||
import struct
|
import struct
|
||||||
import threading
|
import threading
|
||||||
import typing
|
import typing
|
||||||
|
|
@ -31,7 +32,6 @@ from time import time
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
import hidapi
|
|
||||||
|
|
||||||
from . import base_usb
|
from . import base_usb
|
||||||
from . import common
|
from . import common
|
||||||
|
|
@ -47,6 +47,11 @@ if typing.TYPE_CHECKING:
|
||||||
gi.require_version("Gdk", "3.0")
|
gi.require_version("Gdk", "3.0")
|
||||||
from gi.repository import GLib # NOQA: E402
|
from gi.repository import GLib # NOQA: E402
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
import hidapi.udev_impl as hidapi
|
||||||
|
else:
|
||||||
|
import hidapi.hidapi_impl as hidapi
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_hidpp20 = hidpp20.Hidpp20()
|
_hidpp20 = hidpp20.Hidpp20()
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
@ -28,6 +29,11 @@ from logitech_receiver import receiver
|
||||||
|
|
||||||
from solaar import NAME
|
from solaar import NAME
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
import hidapi.udev_impl as hidapi
|
||||||
|
else:
|
||||||
|
import hidapi.hidapi_impl as hidapi
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -106,7 +112,7 @@ def _receivers(dev_path=None):
|
||||||
if dev_path is not None and dev_path != dev_info.path:
|
if dev_path is not None and dev_path != dev_info.path:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
r = receiver.ReceiverFactory.create_receiver(dev_info)
|
r = receiver.ReceiverFactory.create_receiver(hidapi.find_paired_node_wpid, dev_info)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("[%s] => %s", dev_info.path, r)
|
logger.debug("[%s] => %s", dev_info.path, r)
|
||||||
if r:
|
if r:
|
||||||
|
|
@ -122,9 +128,9 @@ def _receivers_and_devices(dev_path=None):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
if dev_info.isDevice:
|
if dev_info.isDevice:
|
||||||
d = device.DeviceFactory.create_device(base, dev_info)
|
d = device.DeviceFactory.create_device(hidapi.find_paired_node, base, dev_info)
|
||||||
else:
|
else:
|
||||||
d = receiver.ReceiverFactory.create_receiver(dev_info)
|
d = receiver.ReceiverFactory.create_receiver(hidapi.find_paired_node_wpid, dev_info)
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("[%s] => %s", dev_info.path, d)
|
logger.debug("[%s] => %s", dev_info.path, d)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
@ -24,7 +25,6 @@ from collections import namedtuple
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
import hidapi
|
|
||||||
import logitech_receiver
|
import logitech_receiver
|
||||||
|
|
||||||
from logitech_receiver import base
|
from logitech_receiver import base
|
||||||
|
|
@ -40,6 +40,11 @@ from . import i18n
|
||||||
gi.require_version("Gtk", "3.0") # NOQA: E402
|
gi.require_version("Gtk", "3.0") # NOQA: E402
|
||||||
from gi.repository import GLib # NOQA: E402 # isort:skip
|
from gi.repository import GLib # NOQA: E402 # isort:skip
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
import hidapi.udev_impl as hidapi
|
||||||
|
else:
|
||||||
|
import hidapi.hidapi_impl as hidapi
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_GHOST_DEVICE = namedtuple("_GHOST_DEVICE", ("receiver", "number", "name", "kind", "online"))
|
_GHOST_DEVICE = namedtuple("_GHOST_DEVICE", ("receiver", "number", "name", "kind", "online"))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
|
import platform
|
||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import hidapi
|
if platform.system() == "Linux":
|
||||||
|
import hidapi.udev_impl as hidapi
|
||||||
|
else:
|
||||||
|
import hidapi.hidapi_impl as hidapi
|
||||||
|
|
||||||
|
|
||||||
def test_find_paired_node():
|
def test_find_paired_node():
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,11 @@ from logitech_receiver import receiver
|
||||||
|
|
||||||
from . import fake_hidpp
|
from . import fake_hidpp
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
import hidapi.udev_impl as hidapi
|
||||||
|
else:
|
||||||
|
import hidapi.hidapi_impl as hidapi
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"index, expected_kind",
|
"index, expected_kind",
|
||||||
|
|
@ -113,7 +118,7 @@ c534_info = {"kind": common.NamedInt(0, "unknown"), "polling": "", "power_switch
|
||||||
(DeviceInfo("14"), responses_lacking, 0x14, None, 1),
|
(DeviceInfo("14"), responses_lacking, 0x14, None, 1),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_ReceiverFactory_create_receiver(device_info, responses, handle, serial, max_devices, mock_base):
|
def test_receiver_factory_create_receiver(device_info, responses, handle, serial, max_devices, mock_base):
|
||||||
mock_base[0].side_effect = fake_hidpp.open_path
|
mock_base[0].side_effect = fake_hidpp.open_path
|
||||||
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
||||||
find_paired_node_wpid_func = hidapi.find_paired_node_wpid
|
find_paired_node_wpid_func = hidapi.find_paired_node_wpid
|
||||||
|
|
@ -140,7 +145,9 @@ def test_ReceiverFactory_create_receiver(device_info, responses, handle, serial,
|
||||||
(DeviceInfo("13", product_id=0xCCCC), responses_unusual, None, None, -1, c534_info, 3),
|
(DeviceInfo("13", product_id=0xCCCC), responses_unusual, None, None, -1, c534_info, 3),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_ReceiverFactory_props(device_info, responses, firmware, codename, remaining_pairings, pairing_info, count, mock_base):
|
def test_receiver_factory_props(
|
||||||
|
device_info, responses, firmware, codename, remaining_pairings, pairing_info, count, mock_base
|
||||||
|
):
|
||||||
mock_base[0].side_effect = fake_hidpp.open_path
|
mock_base[0].side_effect = fake_hidpp.open_path
|
||||||
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
||||||
|
|
||||||
|
|
@ -162,7 +169,7 @@ def test_ReceiverFactory_props(device_info, responses, firmware, codename, remai
|
||||||
(DeviceInfo("13", product_id=0xCCCC), responses_unusual, "No paired devices.", "<Receiver(13,19)>"),
|
(DeviceInfo("13", product_id=0xCCCC), responses_unusual, "No paired devices.", "<Receiver(13,19)>"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_ReceiverFactory_string(device_info, responses, status_str, strng, mock_base):
|
def test_receiver_factory_string(device_info, responses, status_str, strng, mock_base):
|
||||||
mock_base[0].side_effect = fake_hidpp.open_path
|
mock_base[0].side_effect = fake_hidpp.open_path
|
||||||
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
||||||
|
|
||||||
|
|
@ -180,7 +187,7 @@ def test_ReceiverFactory_string(device_info, responses, status_str, strng, mock_
|
||||||
(DeviceInfo("14", product_id="C534"), responses_lacking),
|
(DeviceInfo("14", product_id="C534"), responses_lacking),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_ReceiverFactory_nodevice(device_info, responses, mock_base):
|
def test_receiver_factory_nodevice(device_info, responses, mock_base):
|
||||||
mock_base[0].side_effect = fake_hidpp.open_path
|
mock_base[0].side_effect = fake_hidpp.open_path
|
||||||
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
mock_base[1].side_effect = partial(fake_hidpp.request, responses)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue