device: keep track of feature versions

This commit is contained in:
Peter F. Patel-Schneider 2022-07-19 13:13:55 -04:00
parent 3f350ef4db
commit e72c637667
1 changed files with 10 additions and 3 deletions

View File

@ -239,6 +239,7 @@ class FeaturesArray(dict):
self.supported = True self.supported = True
self.device = device self.device = device
self.inverse = {} self.inverse = {}
self.version = {}
self.count = 0 self.count = 0
def _check(self): def _check(self):
@ -271,10 +272,11 @@ 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.device.feature_request(FEATURE.FEATURE_SET, 0x10, index) response = self.device.feature_request(FEATURE.FEATURE_SET, 0x10, index)
if feature: if response:
feature = FEATURE[_unpack('!H', feature[:2])[0]] feature = FEATURE[_unpack('!H', response[:2])[0]]
self[feature] = index self[feature] = index
self.version[feature] = response[3]
return feature return feature
def enumerate(self): # return all features and their index, ordered by index def enumerate(self): # return all features and their index, ordered by index
@ -283,6 +285,10 @@ class FeaturesArray(dict):
feature = self.get_feature(index) feature = self.get_feature(index)
yield feature, index yield feature, index
def get_feature_version(self, feature):
if self[feature]:
return self.version[feature]
__bool__ = __nonzero__ = _check __bool__ = __nonzero__ = _check
def __getitem__(self, feature): def __getitem__(self, feature):
@ -294,6 +300,7 @@ class FeaturesArray(dict):
if response: if response:
index = response[0] index = response[0]
self[feature] = index if index else False self[feature] = index if index else False
self.version[feature] = response[2]
return index if index else False return index if index else False
def __setitem__(self, feature, index): def __setitem__(self, feature, index):