ui: display battery voltage in ui if available
This commit is contained in:
parent
7936d2dd48
commit
013f383bc8
|
@ -48,6 +48,7 @@ KEYS = _NamedInts(
|
||||||
NOTIFICATION_FLAGS=6,
|
NOTIFICATION_FLAGS=6,
|
||||||
ERROR=7,
|
ERROR=7,
|
||||||
BATTERY_NEXT_LEVEL=8,
|
BATTERY_NEXT_LEVEL=8,
|
||||||
|
BATTERY_VOLTAGE=9,
|
||||||
)
|
)
|
||||||
|
|
||||||
# If the battery charge is under this percentage, trigger an attention event
|
# If the battery charge is under this percentage, trigger an attention event
|
||||||
|
@ -171,7 +172,7 @@ class DeviceStatus(dict):
|
||||||
return bool(self._active)
|
return bool(self._active)
|
||||||
__nonzero__ = __bool__
|
__nonzero__ = __bool__
|
||||||
|
|
||||||
def set_battery_info(self, level, status, nextLevel=None, timestamp=None):
|
def set_battery_info(self, level, status, nextLevel=None, voltage=None, timestamp=None):
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
_log.debug("%s: battery %s, %s", self._device, level, status)
|
_log.debug("%s: battery %s, %s", self._device, level, status)
|
||||||
|
|
||||||
|
@ -194,6 +195,8 @@ class DeviceStatus(dict):
|
||||||
old_level, self[KEYS.BATTERY_LEVEL] = self.get(KEYS.BATTERY_LEVEL), level
|
old_level, self[KEYS.BATTERY_LEVEL] = self.get(KEYS.BATTERY_LEVEL), level
|
||||||
old_status, self[KEYS.BATTERY_STATUS] = self.get(KEYS.BATTERY_STATUS), status
|
old_status, self[KEYS.BATTERY_STATUS] = self.get(KEYS.BATTERY_STATUS), status
|
||||||
self[KEYS.BATTERY_NEXT_LEVEL] = nextLevel
|
self[KEYS.BATTERY_NEXT_LEVEL] = nextLevel
|
||||||
|
if voltage is not None:
|
||||||
|
self[KEYS.BATTERY_VOLTAGE] = voltage
|
||||||
|
|
||||||
charging = status in (_hidpp20.BATTERY_STATUS.recharging, _hidpp20.BATTERY_STATUS.almost_full,
|
charging = status in (_hidpp20.BATTERY_STATUS.recharging, _hidpp20.BATTERY_STATUS.almost_full,
|
||||||
_hidpp20.BATTERY_STATUS.full, _hidpp20.BATTERY_STATUS.slow_recharge)
|
_hidpp20.BATTERY_STATUS.full, _hidpp20.BATTERY_STATUS.slow_recharge)
|
||||||
|
@ -220,6 +223,7 @@ class DeviceStatus(dict):
|
||||||
_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)
|
||||||
|
|
||||||
|
# Retrieve and regularize battery status
|
||||||
def read_battery(self, timestamp=None):
|
def read_battery(self, timestamp=None):
|
||||||
if self._active:
|
if self._active:
|
||||||
d = self._device
|
d = self._device
|
||||||
|
@ -227,14 +231,17 @@ class DeviceStatus(dict):
|
||||||
|
|
||||||
if d.protocol < 2.0:
|
if d.protocol < 2.0:
|
||||||
battery = _hidpp10.get_battery(d)
|
battery = _hidpp10.get_battery(d)
|
||||||
else:
|
self.set_battery_keys(battery)
|
||||||
battery = _hidpp20.get_battery(d)
|
return
|
||||||
if battery is None:
|
|
||||||
v = _hidpp20.get_voltage(d)
|
battery = _hidpp20.get_battery(d)
|
||||||
if v is not None:
|
if battery is None:
|
||||||
_, charging, status, level, _ = v
|
v = _hidpp20.get_voltage(d)
|
||||||
status = _hidpp20.BATTERY_STATUS.recharging if status == _hidpp20.BATTERY_STATUS.recharging else _hidpp20.BATTERY_STATUS.discharging
|
if v is not None:
|
||||||
battery = ( level, status, None )
|
voltage, charging, _ignore, level, _ignore = v
|
||||||
|
status = _hidpp20.BATTERY_STATUS.recharging if charging else _hidpp20.BATTERY_STATUS.discharging
|
||||||
|
self.set_battery_keys( (level, status, None), voltage)
|
||||||
|
return
|
||||||
|
|
||||||
# Really unnecessary, if the device has SOLAR_DASHBOARD it should be
|
# Really unnecessary, if the device has SOLAR_DASHBOARD it should be
|
||||||
# broadcasting it's battery status anyway, it will just take a little while.
|
# broadcasting it's battery status anyway, it will just take a little while.
|
||||||
|
@ -243,14 +250,16 @@ class DeviceStatus(dict):
|
||||||
if battery is None and d.features and _hidpp20.FEATURE.SOLAR_DASHBOARD in d.features:
|
if battery is None and d.features and _hidpp20.FEATURE.SOLAR_DASHBOARD in d.features:
|
||||||
d.feature_request(_hidpp20.FEATURE.SOLAR_DASHBOARD, 0x00, 1, 1)
|
d.feature_request(_hidpp20.FEATURE.SOLAR_DASHBOARD, 0x00, 1, 1)
|
||||||
return
|
return
|
||||||
|
self.set_battery_keys(battery)
|
||||||
|
|
||||||
if battery is not None:
|
def set_battery_keys(self, battery, voltage=None) :
|
||||||
level, status, nextLevel = battery
|
if battery is not None:
|
||||||
self.set_battery_info(level, status, nextLevel)
|
level, status, nextLevel = battery
|
||||||
elif KEYS.BATTERY_STATUS in self:
|
self.set_battery_info(level, status, nextLevel, voltage)
|
||||||
self[KEYS.BATTERY_STATUS] = None
|
elif KEYS.BATTERY_STATUS in self:
|
||||||
self[KEYS.BATTERY_CHARGING] = None
|
self[KEYS.BATTERY_STATUS] = None
|
||||||
self.changed()
|
self[KEYS.BATTERY_CHARGING] = None
|
||||||
|
self.changed()
|
||||||
|
|
||||||
def changed(self, active=None, alert=ALERT.NONE, reason=None, timestamp=None):
|
def changed(self, active=None, alert=ALERT.NONE, reason=None, timestamp=None):
|
||||||
assert self._changed_callback
|
assert self._changed_callback
|
||||||
|
|
|
@ -619,6 +619,7 @@ def _update_device_panel(device, panel, buttons, full=False):
|
||||||
|
|
||||||
battery_level = device.status.get(_K.BATTERY_LEVEL)
|
battery_level = device.status.get(_K.BATTERY_LEVEL)
|
||||||
battery_next_level = device.status.get(_K.BATTERY_NEXT_LEVEL)
|
battery_next_level = device.status.get(_K.BATTERY_NEXT_LEVEL)
|
||||||
|
battery_voltage = device.status.get(_K.BATTERY_VOLTAGE)
|
||||||
|
|
||||||
if battery_level is None:
|
if battery_level is None:
|
||||||
icon_name = _icons.battery()
|
icon_name = _icons.battery()
|
||||||
|
@ -632,7 +633,9 @@ def _update_device_panel(device, panel, buttons, full=False):
|
||||||
panel._battery._icon.set_from_icon_name(icon_name, _INFO_ICON_SIZE)
|
panel._battery._icon.set_from_icon_name(icon_name, _INFO_ICON_SIZE)
|
||||||
panel._battery._icon.set_sensitive(True)
|
panel._battery._icon.set_sensitive(True)
|
||||||
|
|
||||||
if isinstance(battery_level, _NamedInt):
|
if battery_voltage is not None:
|
||||||
|
text = "%(battery_voltage)dmV" % { 'battery_voltage' : battery_voltage }
|
||||||
|
elif isinstance(battery_level, _NamedInt):
|
||||||
text = _(str(battery_level))
|
text = _(str(battery_level))
|
||||||
else:
|
else:
|
||||||
text = "%(battery_percent)d%%" % { 'battery_percent': battery_level }
|
text = "%(battery_percent)d%%" % { 'battery_percent': battery_level }
|
||||||
|
@ -819,11 +822,14 @@ def update(device, need_popup=False):
|
||||||
_model.set_value(item, _COLUMN.ACTIVE, is_online)
|
_model.set_value(item, _COLUMN.ACTIVE, is_online)
|
||||||
|
|
||||||
battery_level = device.status.get(_K.BATTERY_LEVEL)
|
battery_level = device.status.get(_K.BATTERY_LEVEL)
|
||||||
|
battery_voltage = device.status.get(_K.BATTERY_VOLTAGE)
|
||||||
if battery_level is None:
|
if battery_level is None:
|
||||||
_model.set_value(item, _COLUMN.STATUS_TEXT, _CAN_SET_ROW_NONE)
|
_model.set_value(item, _COLUMN.STATUS_TEXT, _CAN_SET_ROW_NONE)
|
||||||
_model.set_value(item, _COLUMN.STATUS_ICON, _CAN_SET_ROW_NONE)
|
_model.set_value(item, _COLUMN.STATUS_ICON, _CAN_SET_ROW_NONE)
|
||||||
else:
|
else:
|
||||||
if isinstance(battery_level, _NamedInt):
|
if battery_voltage is not None:
|
||||||
|
status_text = "%(battery_voltage)dmV" % { 'battery_voltage' : battery_voltage }
|
||||||
|
elif isinstance(battery_level, _NamedInt):
|
||||||
status_text = _(str(battery_level))
|
status_text = _(str(battery_level))
|
||||||
else:
|
else:
|
||||||
status_text = "%(battery_percent)d%%" % { 'battery_percent': battery_level }
|
status_text = "%(battery_percent)d%%" % { 'battery_percent': battery_level }
|
||||||
|
|
Loading…
Reference in New Issue