receiver: only check for device features once per device

This commit is contained in:
Peter F. Patel-Schneider 2020-05-28 13:46:54 -04:00 committed by Filipe Laíns
parent f198b2706b
commit 89995656cd
2 changed files with 7 additions and 4 deletions

View File

@ -71,6 +71,7 @@ class PairedDevice(object):
self._keys = None
self._registers = None
self._settings = None
self._feature_settings_checked = False
# Misc stuff that's irrelevant to any functionality, but may be
# displayed in the UI and caching it here helps.
@ -251,8 +252,8 @@ class PairedDevice(object):
self._settings = [s(self) for s in self.descriptor.settings]
else:
self._settings = []
_check_feature_settings(self, self._settings)
if not self._feature_settings_checked:
self._feature_settings_checked =_check_feature_settings(self, self._settings)
return self._settings
def enable_notifications(self, enable=True):

View File

@ -371,12 +371,13 @@ del _SETTINGS_LIST
#
#
# Returns True if device was queried to find features, False otherwise
def check_feature_settings(device, already_known):
"""Try to auto-detect device settings by the HID++ 2.0 features they have."""
if device.features is None or not device.online:
return
return False
if device.protocol and device.protocol < 2.0:
return
return False
def check_feature(name, featureId, field_name=None):
"""
@ -414,3 +415,4 @@ def check_feature_settings(device, already_known):
check_feature(_POINTER_SPEED[0], _F.POINTER_SPEED)
check_feature(_SMART_SHIFT[0], _F.SMART_SHIFT)
check_feature(_BACKLIGHT[0], _F.BACKLIGHT2)
return True