only popup the window once per device on battery alerts
This commit is contained in:
parent
9c8252b59f
commit
51d0ccf654
|
@ -213,17 +213,18 @@ def _process_feature_notification(device, status, n, feature):
|
||||||
if feature == _F.SOLAR_DASHBOARD:
|
if feature == _F.SOLAR_DASHBOARD:
|
||||||
if n.data[5:9] == b'GOOD':
|
if n.data[5:9] == b'GOOD':
|
||||||
charge, lux, adc = _unpack('!BHH', n.data[:5])
|
charge, lux, adc = _unpack('!BHH', n.data[:5])
|
||||||
status[_K.BATTERY_LEVEL] = charge
|
|
||||||
# guesstimate the battery voltage, emphasis on 'guess'
|
# 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:
|
if n.address == 0x00:
|
||||||
status[_K.LIGHT_LEVEL] = None
|
status[_K.LIGHT_LEVEL] = None
|
||||||
status[_K.BATTERY_CHARGING] = None
|
status.set_battery_info(charge, status_text)
|
||||||
status.changed(active=True)
|
|
||||||
elif n.address == 0x10:
|
elif n.address == 0x10:
|
||||||
status[_K.LIGHT_LEVEL] = lux
|
status[_K.LIGHT_LEVEL] = lux
|
||||||
status[_K.BATTERY_CHARGING] = lux > 200
|
if lux > 200:
|
||||||
status.changed(active=True)
|
status_text = _hidpp20.BATTERY_STATUS.recharging
|
||||||
|
status.set_battery_info(charge, status_text)
|
||||||
elif n.address == 0x20:
|
elif n.address == 0x20:
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
_log.debug("%s: Light Check button pressed", device)
|
_log.debug("%s: Light Check button pressed", device)
|
||||||
|
|
|
@ -178,9 +178,14 @@ class DeviceStatus(dict):
|
||||||
changed = old_level != level or old_status != status or old_charging != charging
|
changed = old_level != level or old_status != status or old_charging != charging
|
||||||
alert, reason = ALERT.NONE, None
|
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)
|
_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):
|
if isinstance(level, _NamedInt):
|
||||||
reason = 'battery: %s (%s)' % (level, status)
|
reason = 'battery: %s (%s)' % (level, status)
|
||||||
else:
|
else:
|
||||||
|
@ -189,7 +194,7 @@ class DeviceStatus(dict):
|
||||||
if changed or reason:
|
if changed or reason:
|
||||||
# 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(alert=alert, reason=reason, timestamp=timestamp)
|
self.changed(active=True, alert=alert, reason=reason, timestamp=timestamp)
|
||||||
|
|
||||||
def read_battery(self, timestamp=None):
|
def read_battery(self, timestamp=None):
|
||||||
if self._active:
|
if self._active:
|
||||||
|
|
Loading…
Reference in New Issue