device: use ADC notifications to set device inactive and active

This commit is contained in:
Peter F. Patel-Schneider 2022-09-25 03:48:58 -04:00
parent cdf3957180
commit b2f9df965a
2 changed files with 3 additions and 1 deletions

View File

@ -343,6 +343,8 @@ def _process_feature_notification(device, status, n, feature):
if result: if result:
_ignore, level, next, battery_status, voltage = result _ignore, level, next, battery_status, voltage = result
status.set_battery_info(level, next, battery_status, voltage) status.set_battery_info(level, next, battery_status, voltage)
else: # this feature is used to signal device becoming inactive
status.changed(active=False)
else: else:
_log.warn('%s: unknown ADC MEASUREMENT %s', device, n) _log.warn('%s: unknown ADC MEASUREMENT %s', device, n)

View File

@ -237,7 +237,7 @@ class DeviceStatus(dict):
else: else:
reason = _('Battery: %(percent)d%% (%(status)s)') % {'percent': level, 'status': status.name} reason = _('Battery: %(percent)d%% (%(status)s)') % {'percent': level, 'status': status.name}
if changed or reason: if changed or reason or not self._active: # a battery response means device is active
# update the leds on the device, if any # update the leds on the device, if any
_hidpp10.set_3leds(self._device, level, charging=charging, warning=bool(alert)) _hidpp10.set_3leds(self._device, level, charging=charging, warning=bool(alert))
self.changed(active=True, alert=alert, reason=reason, timestamp=timestamp) self.changed(active=True, alert=alert, reason=reason, timestamp=timestamp)