diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py index e5edcfeb..f9006020 100644 --- a/lib/logitech_receiver/device.py +++ b/lib/logitech_receiver/device.py @@ -359,11 +359,14 @@ class Device: battery_feature = self.persister.get('_battery', None) if self.persister else None if battery_feature != 0: result = _hidpp20.get_battery(self, battery_feature) - if result: + try: feature, level, next, status, voltage = result if self.persister and battery_feature is None: self.persister['_battery'] = feature 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): """Enable or disable device (dis)connection notifications on this diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 4e35ef20..166be1ba 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -1318,12 +1318,12 @@ def decipher_battery_voltage(report): 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) if report is not None: return decipher_adc_measurement(report) except FeatureCallError: - return None + return FEATURE.ADC_MEASUREMENT if FEATURE.ADC_MEASUREMENT in device.features else None def decipher_adc_measurement(report): @@ -1347,7 +1347,8 @@ battery_functions = { 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: battery_function = battery_functions.get(feature, None) if battery_function: @@ -1359,7 +1360,7 @@ def get_battery(device, feature): result = battery_function(device) if result: return result - return 0, None, None, None, None + return 0 def get_keys(device):