From 7936d2dd487f99bf1733c7bb446a6c9de7418e05 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Wed, 3 Jun 2020 15:23:19 -0400 Subject: [PATCH] receiver: use battery voltage in read_battery if available --- lib/logitech_receiver/hidpp20.py | 11 ++++------- lib/logitech_receiver/status.py | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/logitech_receiver/hidpp20.py b/lib/logitech_receiver/hidpp20.py index 13d2c817..92296b7d 100644 --- a/lib/logitech_receiver/hidpp20.py +++ b/lib/logitech_receiver/hidpp20.py @@ -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]) diff --git a/lib/logitech_receiver/status.py b/lib/logitech_receiver/status.py index 821dd002..ded08c6e 100644 --- a/lib/logitech_receiver/status.py +++ b/lib/logitech_receiver/status.py @@ -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.