receiver: use battery voltage in read_battery if available
This commit is contained in:
parent
cb84d3b797
commit
7936d2dd48
|
@ -195,9 +195,9 @@ CHARGE_STATUS = _NamedInts(
|
|||
error=0x07)
|
||||
|
||||
CHARGE_LEVEL = _NamedInts(
|
||||
average=0x00,
|
||||
full=0x01,
|
||||
critical=0x02)
|
||||
average=50,
|
||||
full=90,
|
||||
critical=5)
|
||||
|
||||
CHARGE_TYPE = _NamedInts(
|
||||
standard=0x00,
|
||||
|
@ -513,10 +513,7 @@ def get_name(device):
|
|||
|
||||
|
||||
def get_battery(device):
|
||||
"""Reads a device's battery level.
|
||||
|
||||
:raises FeatureNotSupported: if the device does not support this feature.
|
||||
"""
|
||||
"""Reads a device's battery level."""
|
||||
battery = feature_request(device, FEATURE.BATTERY_STATUS)
|
||||
if battery:
|
||||
discharge, dischargeNext, status = _unpack('!BBB', battery[:3])
|
||||
|
|
|
@ -229,6 +229,12 @@ class DeviceStatus(dict):
|
|||
battery = _hidpp10.get_battery(d)
|
||||
else:
|
||||
battery = _hidpp20.get_battery(d)
|
||||
if battery is None:
|
||||
v = _hidpp20.get_voltage(d)
|
||||
if v is not None:
|
||||
_, charging, status, level, _ = v
|
||||
status = _hidpp20.BATTERY_STATUS.recharging if status == _hidpp20.BATTERY_STATUS.recharging else _hidpp20.BATTERY_STATUS.discharging
|
||||
battery = ( level, status, None )
|
||||
|
||||
# Really unnecessary, if the device has SOLAR_DASHBOARD it should be
|
||||
# broadcasting it's battery status anyway, it will just take a little while.
|
||||
|
|
Loading…
Reference in New Issue