device: optimize some functions in FeaturesArray

This commit is contained in:
Peter F. Patel-Schneider 2024-03-12 12:18:14 -04:00
parent 0b599194d1
commit dfd3d10c2e
1 changed files with 6 additions and 0 deletions

View File

@ -91,6 +91,9 @@ class FeaturesArray(dict):
if feature is not None: if feature is not None:
return feature return feature
elif self._check(): elif self._check():
feature = self.inverse.get(index)
if feature is not None:
return feature
response = self.device.feature_request(FEATURE.FEATURE_SET, 0x10, index) response = self.device.feature_request(FEATURE.FEATURE_SET, 0x10, index)
if response: if response:
feature = FEATURE[_unpack("!H", response[:2])[0]] feature = FEATURE[_unpack("!H", response[:2])[0]]
@ -117,6 +120,9 @@ class FeaturesArray(dict):
if index is not None: if index is not None:
return index return index
elif self._check(): elif self._check():
index = super().get(feature)
if index is not None:
return index
response = self.device.request(0x0000, _pack("!H", feature)) response = self.device.request(0x0000, _pack("!H", feature))
if response: if response:
index = response[0] index = response[0]