fix: Replace invalid hidpp10 usage

Related #1097
This commit is contained in:
Matthias Hagmann 2024-02-28 22:29:36 +01:00 committed by Peter F. Patel-Schneider
parent 6939fb7196
commit c3b01bffae
2 changed files with 12 additions and 6 deletions

View File

@ -25,6 +25,7 @@ from struct import unpack as _unpack
from . import diversion as _diversion from . import diversion as _diversion
from . import hidpp10 as _hidpp10 from . import hidpp10 as _hidpp10
from . import hidpp10_constants as _hidpp10_constants
from . import hidpp20 as _hidpp20 from . import hidpp20 as _hidpp20
from . import hidpp20_constants as _hidpp20_constants from . import hidpp20_constants as _hidpp20_constants
from . import settings_templates as _st from . import settings_templates as _st
@ -37,7 +38,7 @@ from .status import KEYS as _K
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
_R = _hidpp10.REGISTERS _R = _hidpp10_constants.REGISTERS
_F = _hidpp20_constants.FEATURE _F = _hidpp20_constants.FEATURE
@ -72,7 +73,7 @@ def _process_receiver_notification(receiver, status, n):
status.new_device = None status.new_device = None
pair_error = ord(n.data[:1]) pair_error = ord(n.data[:1])
if pair_error: if pair_error:
status[_K.ERROR] = error_string = _hidpp10.PAIRING_ERRORS[pair_error] status[_K.ERROR] = error_string = _hidpp10_constants.PAIRING_ERRORS[pair_error]
status.new_device = None status.new_device = None
logger.warning("pairing error %d: %s", pair_error, error_string) logger.warning("pairing error %d: %s", pair_error, error_string)
status.changed(reason=reason) status.changed(reason=reason)
@ -90,7 +91,7 @@ def _process_receiver_notification(receiver, status, n):
status.device_passkey = None status.device_passkey = None
discover_error = ord(n.data[:1]) discover_error = ord(n.data[:1])
if discover_error: if discover_error:
status[_K.ERROR] = discover_string = _hidpp10.BOLT_PAIRING_ERRORS[discover_error] status[_K.ERROR] = discover_string = _hidpp10_constants.BOLT_PAIRING_ERRORS[discover_error]
logger.warning("bolt discovering error %d: %s", discover_error, discover_string) logger.warning("bolt discovering error %d: %s", discover_error, discover_string)
status.changed(reason=reason) status.changed(reason=reason)
return True return True
@ -127,7 +128,7 @@ def _process_receiver_notification(receiver, status, n):
elif n.address == 0x02 and not pair_error: elif n.address == 0x02 and not pair_error:
status.new_device = receiver.register_new_device(n.data[7]) status.new_device = receiver.register_new_device(n.data[7])
if pair_error: if pair_error:
status[_K.ERROR] = error_string = _hidpp10.BOLT_PAIRING_ERRORS[pair_error] status[_K.ERROR] = error_string = _hidpp10_constants.BOLT_PAIRING_ERRORS[pair_error]
status.new_device = None status.new_device = None
logger.warning("pairing error %d: %s", pair_error, error_string) logger.warning("pairing error %d: %s", pair_error, error_string)
status.changed(reason=reason) status.changed(reason=reason)

View File

@ -19,7 +19,7 @@
import logging import logging
from gi.repository import GLib, Gtk from gi.repository import GLib, Gtk
from logitech_receiver import hidpp10 as _hidpp10 from logitech_receiver import hidpp10_constants as _hidpp10_constants
from logitech_receiver.status import KEYS as _K from logitech_receiver.status import KEYS as _K
from solaar.i18n import _, ngettext from solaar.i18n import _, ngettext
@ -90,8 +90,13 @@ def _check_lock_state(assistant, receiver, count=2):
kind = receiver.status.device_kind kind = receiver.status.device_kind
authentication = receiver.status.device_authentication authentication = receiver.status.device_authentication
name = receiver.status.device_name name = receiver.status.device_name
entropy = 10
if kind == _hidpp10_constants.DEVICE_KIND.keyboard:
entropy = 20
if receiver.pair_device( if receiver.pair_device(
address=address, authentication=authentication, entropy=20 if kind == _hidpp10.DEVICE_KIND.keyboard else 10 address=address,
authentication=authentication,
entropy=entropy,
): ):
return True return True
else: else: