From 51d0ccf654a6b4010b027e049d44edf6e4f15681 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Fri, 12 Jul 2013 14:35:16 +0200 Subject: [PATCH] only popup the window once per device on battery alerts --- lib/logitech/unifying_receiver/notifications.py | 13 +++++++------ lib/logitech/unifying_receiver/status.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/logitech/unifying_receiver/notifications.py b/lib/logitech/unifying_receiver/notifications.py index 81c0df6a..cc52fd50 100644 --- a/lib/logitech/unifying_receiver/notifications.py +++ b/lib/logitech/unifying_receiver/notifications.py @@ -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) diff --git a/lib/logitech/unifying_receiver/status.py b/lib/logitech/unifying_receiver/status.py index 5f2fcbbc..6508f09b 100644 --- a/lib/logitech/unifying_receiver/status.py +++ b/lib/logitech/unifying_receiver/status.py @@ -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: