only popup the window once per device on battery alerts

This commit is contained in:
Daniel Pavel 2013-07-12 14:35:16 +02:00
parent 9c8252b59f
commit 51d0ccf654
2 changed files with 15 additions and 9 deletions

View File

@ -213,17 +213,18 @@ def _process_feature_notification(device, status, n, feature):
if feature == _F.SOLAR_DASHBOARD:
if n.data[5:9] == b'GOOD':
charge, lux, adc = _unpack('!BHH', n.data[:5])
status[_K.BATTERY_LEVEL] = charge
# guesstimate the battery voltage, emphasis on 'guess'
status[_K.BATTERY_STATUS] = '%1.2fV' % (adc * 2.67793237653 / 0x0672)
# status_text = '%1.2fV' % (adc * 2.67793237653 / 0x0672)
status_text = _hidpp20.BATTERY_STATUS.discharging
if n.address == 0x00:
status[_K.LIGHT_LEVEL] = None
status[_K.BATTERY_CHARGING] = None
status.changed(active=True)
status.set_battery_info(charge, status_text)
elif n.address == 0x10:
status[_K.LIGHT_LEVEL] = lux
status[_K.BATTERY_CHARGING] = lux > 200
status.changed(active=True)
if lux > 200:
status_text = _hidpp20.BATTERY_STATUS.recharging
status.set_battery_info(charge, status_text)
elif n.address == 0x20:
if _log.isEnabledFor(_DEBUG):
_log.debug("%s: Light Check button pressed", device)

View File

@ -178,9 +178,14 @@ class DeviceStatus(dict):
changed = old_level != level or old_status != status or old_charging != charging
alert, reason = ALERT.NONE, None
if not _hidpp20.BATTERY_OK(status) or level <= _BATTERY_ATTENTION_LEVEL:
if _hidpp20.BATTERY_OK(status) and level > _BATTERY_ATTENTION_LEVEL:
self[KEYS.ERROR] = None
else:
_log.warn("%s: battery %d%%, ALERT %s", self._device, level, status)
alert = ALERT.NOTIFICATION | ALERT.ATTENTION
if self.get(KEYS.ERROR) != status:
self[KEYS.ERROR] = status
# only show the notification once
alert = ALERT.NOTIFICATION | ALERT.ATTENTION
if isinstance(level, _NamedInt):
reason = 'battery: %s (%s)' % (level, status)
else:
@ -189,7 +194,7 @@ class DeviceStatus(dict):
if changed or reason:
# update the leds on the device, if any
_hidpp10.set_3leds(self._device, level, charging=charging, warning=bool(alert))
self.changed(alert=alert, reason=reason, timestamp=timestamp)
self.changed(active=True, alert=alert, reason=reason, timestamp=timestamp)
def read_battery(self, timestamp=None):
if self._active: