receiver: add safety for non-compliant mouse features

receiver: safely handle errors with check_feature to allow device to be detected even if some features are inconsistent
This commit is contained in:
Rijnhard Hessel 2020-02-21 16:33:14 +02:00 committed by GitHub
parent a5813e4e23
commit 8e67bbbc11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -19,6 +19,9 @@
from __future__ import absolute_import, division, print_function, unicode_literals
from logging import getLogger, DEBUG as _DEBUG
_log = getLogger(__name__)
del getLogger
from .i18n import _
from . import hidpp10 as _hidpp10
@ -391,7 +394,14 @@ def check_feature_settings(device, already_known):
# Convert user-visible settings name for FeatureSettings
field_name = name.replace('-', '_')
feature = getattr(FeatureSettings, field_name)()
already_known.append(feature(device))
try:
detected = feature(device)
if _log.isEnabledFor(_DEBUG):
_log.debug("check_feature[%s] detected %s", featureId, detected)
already_known.append(detected)
except Exception as reason:
_log.error("check_feature[%s] inconsistent feature %s", featureId, reason)
check_feature(_HI_RES_SCROLL[0], _F.HI_RES_SCROLLING)
check_feature(_LOW_RES_SCROLL[0], _F.LOWRES_WHEEL)