From 04bdf3bb8a0a12b94fbfb4fc34e331ef5428282a Mon Sep 17 00:00:00 2001 From: MattHag <16444067+MattHag@users.noreply.github.com> Date: Tue, 28 May 2024 02:27:33 +0200 Subject: [PATCH] Introduce constant for Logitech vendor ID The Vendor ID for Logitech is 0x46D = 1133. --- lib/logitech_receiver/base.py | 9 +++++---- lib/logitech_receiver/base_usb.py | 18 ++++++++++-------- lib/logitech_receiver/common.py | 2 ++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/logitech_receiver/base.py b/lib/logitech_receiver/base.py index a02a745c91..fbf94ccf66 100644 --- a/lib/logitech_receiver/base.py +++ b/lib/logitech_receiver/base.py @@ -38,6 +38,7 @@ from . import hidpp10_constants from . import hidpp20 from . import hidpp20_constants +from .common import LOGITECH_VENDOR_ID logger = logging.getLogger(__name__) @@ -59,7 +60,7 @@ def __str__(self): def _usb_device(product_id: int, usb_interface: int) -> dict[str, Any]: return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "bus_id": 3, "usb_interface": usb_interface, @@ -68,7 +69,7 @@ def _usb_device(product_id: int, usb_interface: int) -> dict[str, Any]: def _bluetooth_device(product_id: int) -> dict[str, Any]: - return {"vendor_id": 1133, "product_id": product_id, "bus_id": 5, "isDevice": True} + return {"vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "bus_id": 5, "isDevice": True} KNOWN_DEVICE_IDS = [] @@ -84,7 +85,7 @@ def _bluetooth_device(product_id: int) -> dict[str, Any]: def other_device_check(bus_id: int, vendor_id: int, product_id: int): """Check whether product is a Logitech USB-connected or Bluetooth device based on bus, vendor, and product IDs This allows Solaar to support receiverless HID++ 2.0 devices that it knows nothing about""" - if vendor_id != 0x46D: # Logitech + if vendor_id != LOGITECH_VENDOR_ID: return if bus_id == 0x3: # USB if product_id >= 0xC07D and product_id <= 0xC094 or product_id >= 0xC32B and product_id <= 0xC344: @@ -151,7 +152,7 @@ def filter_receivers(bus_id, vendor_id, product_id, hidpp_short=False, hidpp_lon for record in base_usb.ALL: # known receivers if match(record, bus_id, vendor_id, product_id): return record - if vendor_id == 0x046D and 0xC500 <= product_id <= 0xC5FF: # unknown receiver + if vendor_id == LOGITECH_VENDOR_ID and 0xC500 <= product_id <= 0xC5FF: # unknown receiver return {"vendor_id": vendor_id, "product_id": product_id, "bus_id": bus_id, "isDevice": False} diff --git a/lib/logitech_receiver/base_usb.py b/lib/logitech_receiver/base_usb.py index aa5e7f78f0..2a4344a0e8 100644 --- a/lib/logitech_receiver/base_usb.py +++ b/lib/logitech_receiver/base_usb.py @@ -26,6 +26,8 @@ from solaar.i18n import _ +from logitech_receiver.common import LOGITECH_VENDOR_ID + # max_devices is only used for receivers that do not support reading from _R.receiver_info offset 0x03, default to 1 # may_unpair is only used for receivers that do not support reading from _R.receiver_info offset 0x03, default to False # unpair is for receivers that do support reading from _R.receiver_info offset 0x03, no default @@ -36,7 +38,7 @@ def _bolt_receiver(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 2, "name": _("Bolt Receiver"), @@ -48,7 +50,7 @@ def _bolt_receiver(product_id): def _unifying_receiver(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 2, "name": _("Unifying Receiver"), @@ -59,7 +61,7 @@ def _unifying_receiver(product_id): def _nano_receiver(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 1, "name": _("Nano Receiver"), @@ -71,7 +73,7 @@ def _nano_receiver(product_id): def _nano_receiver_no_unpair(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 1, "name": _("Nano Receiver"), @@ -84,7 +86,7 @@ def _nano_receiver_no_unpair(product_id): def _nano_receiver_max2(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 1, "name": _("Nano Receiver"), @@ -97,7 +99,7 @@ def _nano_receiver_max2(product_id): def _nano_receiver_maxn(product_id, max): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 1, "name": _("Nano Receiver"), @@ -121,7 +123,7 @@ def _lenovo_receiver(product_id): def _lightspeed_receiver(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 2, "receiver_kind": "lightspeed", @@ -132,7 +134,7 @@ def _lightspeed_receiver(product_id): def _ex100_receiver(product_id): return { - "vendor_id": 1133, + "vendor_id": LOGITECH_VENDOR_ID, "product_id": product_id, "usb_interface": 1, "name": _("EX100 Receiver 27 Mhz"), diff --git a/lib/logitech_receiver/common.py b/lib/logitech_receiver/common.py index 6471570210..60a881ceec 100644 --- a/lib/logitech_receiver/common.py +++ b/lib/logitech_receiver/common.py @@ -27,6 +27,8 @@ from solaar.i18n import _ +LOGITECH_VENDOR_ID = 0x046D + def crc16(data: bytes): """