From d8e469a33ab59423f4a7f6507e570505e2defafa Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 30 Apr 2013 19:53:15 +0200 Subject: [PATCH] hidpp10: split reg07 (battery) parsing so it can be reused --- lib/logitech/unifying_receiver/hidpp10.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/logitech/unifying_receiver/hidpp10.py b/lib/logitech/unifying_receiver/hidpp10.py index 95da0f37..4c0666a8 100644 --- a/lib/logitech/unifying_receiver/hidpp10.py +++ b/lib/logitech/unifying_receiver/hidpp10.py @@ -96,15 +96,18 @@ def get_battery(device): if reply: level = ord(reply[:1]) battery_status = ord(reply[1:2]) - charge = (90 if level == 7 # full - else 50 if level == 5 # good - else 20 if level == 3 # low - else 5 if level == 1 # critical - else 0 ) # wtf? - status = ('charging' if battery_status == 0x25 - else 'fully charged' if battery_status == 0x22 - else 'discharging') - return charge, status + return parse_battery_reply(level, battery_status) + +def parse_battery_reply(level, battery_status): + charge = (90 if level == 7 # full + else 50 if level == 5 # good + else 20 if level == 3 # low + else 5 if level == 1 # critical + else 0 ) # wtf? + status = ('charging' if battery_status == 0x25 + else 'fully charged' if battery_status == 0x22 + else 'discharging') + return charge, status def get_serial(device):