hidpp10: split reg07 (battery) parsing so it can be reused
This commit is contained in:
parent
0f80901bce
commit
d8e469a33a
|
@ -96,15 +96,18 @@ def get_battery(device):
|
||||||
if reply:
|
if reply:
|
||||||
level = ord(reply[:1])
|
level = ord(reply[:1])
|
||||||
battery_status = ord(reply[1:2])
|
battery_status = ord(reply[1:2])
|
||||||
charge = (90 if level == 7 # full
|
return parse_battery_reply(level, battery_status)
|
||||||
else 50 if level == 5 # good
|
|
||||||
else 20 if level == 3 # low
|
def parse_battery_reply(level, battery_status):
|
||||||
else 5 if level == 1 # critical
|
charge = (90 if level == 7 # full
|
||||||
else 0 ) # wtf?
|
else 50 if level == 5 # good
|
||||||
status = ('charging' if battery_status == 0x25
|
else 20 if level == 3 # low
|
||||||
else 'fully charged' if battery_status == 0x22
|
else 5 if level == 1 # critical
|
||||||
else 'discharging')
|
else 0 ) # wtf?
|
||||||
return charge, status
|
status = ('charging' if battery_status == 0x25
|
||||||
|
else 'fully charged' if battery_status == 0x22
|
||||||
|
else 'discharging')
|
||||||
|
return charge, status
|
||||||
|
|
||||||
|
|
||||||
def get_serial(device):
|
def get_serial(device):
|
||||||
|
|
Loading…
Reference in New Issue