device: correctly record battery feature when ADC MEASUREMENT produces error
This commit is contained in:
parent
3a6b479e8b
commit
7031f5338f
|
@ -359,11 +359,14 @@ class Device:
|
||||||
battery_feature = self.persister.get('_battery', None) if self.persister else None
|
battery_feature = self.persister.get('_battery', None) if self.persister else None
|
||||||
if battery_feature != 0:
|
if battery_feature != 0:
|
||||||
result = _hidpp20.get_battery(self, battery_feature)
|
result = _hidpp20.get_battery(self, battery_feature)
|
||||||
if result:
|
try:
|
||||||
feature, level, next, status, voltage = result
|
feature, level, next, status, voltage = result
|
||||||
if self.persister and battery_feature is None:
|
if self.persister and battery_feature is None:
|
||||||
self.persister['_battery'] = feature
|
self.persister['_battery'] = feature
|
||||||
return level, next, status, voltage
|
return level, next, status, voltage
|
||||||
|
except Exception:
|
||||||
|
if self.persister and battery_feature is None:
|
||||||
|
self.persister['_battery'] = result
|
||||||
|
|
||||||
def enable_connection_notifications(self, enable=True):
|
def enable_connection_notifications(self, enable=True):
|
||||||
"""Enable or disable device (dis)connection notifications on this
|
"""Enable or disable device (dis)connection notifications on this
|
||||||
|
|
|
@ -1318,12 +1318,12 @@ def decipher_battery_voltage(report):
|
||||||
|
|
||||||
|
|
||||||
def get_adc_measurement(device):
|
def get_adc_measurement(device):
|
||||||
try: # this feature call has been known to produce errors so be extra cautious
|
try: # this feature call produces an error for headsets that are connected but inactive
|
||||||
report = feature_request(device, FEATURE.ADC_MEASUREMENT)
|
report = feature_request(device, FEATURE.ADC_MEASUREMENT)
|
||||||
if report is not None:
|
if report is not None:
|
||||||
return decipher_adc_measurement(report)
|
return decipher_adc_measurement(report)
|
||||||
except FeatureCallError:
|
except FeatureCallError:
|
||||||
return None
|
return FEATURE.ADC_MEASUREMENT if FEATURE.ADC_MEASUREMENT in device.features else None
|
||||||
|
|
||||||
|
|
||||||
def decipher_adc_measurement(report):
|
def decipher_adc_measurement(report):
|
||||||
|
@ -1347,7 +1347,8 @@ battery_functions = {
|
||||||
|
|
||||||
|
|
||||||
def get_battery(device, feature):
|
def get_battery(device, feature):
|
||||||
"""Return battery information - feature, approximate level, next, charging, voltage"""
|
"""Return battery information - feature, approximate level, next, charging, voltage
|
||||||
|
or battery feature if there is one but it is not responding or None for no battery feature"""
|
||||||
if feature is not None:
|
if feature is not None:
|
||||||
battery_function = battery_functions.get(feature, None)
|
battery_function = battery_functions.get(feature, None)
|
||||||
if battery_function:
|
if battery_function:
|
||||||
|
@ -1359,7 +1360,7 @@ def get_battery(device, feature):
|
||||||
result = battery_function(device)
|
result = battery_function(device)
|
||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
return 0, None, None, None, None
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def get_keys(device):
|
def get_keys(device):
|
||||||
|
|
Loading…
Reference in New Issue