From b193b397011697b8fb8993d84548e30473406aa3 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 23 Aug 2013 21:23:23 +0200 Subject: [PATCH] Fix missing reprogrammable keys The assumption that the Features IDs are in increasing order does not hold. This causes the feature check for REPROG CONTROLS (1B00) to fail, therefore remove the micro-optimisation. While at it, rename variables and document the functions better. --- lib/logitech_receiver/hidpp20.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index fd03da2e..5ab67008 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -210,9 +210,10 @@ class FeaturesArray(object): indices = index.indices(len(self.features)) return [self.__getitem__(i) for i in range(*indices)] - def __contains__(self, value): + def __contains__(self, featureId): + """Tests whether the list contains given Feature ID""" if self._check(): - ivalue = int(value) + ivalue = int(featureId) may_have = False for f in self.features: @@ -220,8 +221,6 @@ class FeaturesArray(object): may_have = True elif ivalue == int(f): return True - elif ivalue < int(f): - break if may_have: reply = self.device.request(0x0000, _pack('!H', ivalue)) @@ -231,17 +230,16 @@ class FeaturesArray(object): self.features[index] = FEATURE[ivalue] return True - def index(self, value): + def index(self, featureId): + """Gets the Feature Index for a given Feature ID""" if self._check(): may_have = False - ivalue = int(value) + ivalue = int(featureId) for index, f in enumerate(self.features): if f is None: may_have = True elif ivalue == int(f): return index - elif ivalue < int(f): - raise ValueError("%r not in list" % value) if may_have: reply = self.device.request(0x0000, _pack('!H', ivalue)) @@ -250,7 +248,7 @@ class FeaturesArray(object): self.features[index] = FEATURE[ivalue] return index - raise ValueError("%r not in list" % value) + raise ValueError("%r not in list" % featureId) def __iter__(self): if self._check():