Merge pull request #23 from Lekensteyn/hid10-battery

Parse battery status of HID++ 1.0 devices
This commit is contained in:
Daniel Pavel 2013-04-27 05:20:29 -07:00
commit a3599b53bb
1 changed files with 10 additions and 2 deletions

View File

@ -94,8 +94,16 @@ def get_battery(device):
reply = get_register(device, 'battery_status', 0x07)
if reply:
battery_status = ord(reply[:1])
_log.info("%s: battery status %02X", device, battery_status)
level = ord(reply[:1])
battery_status = ord(reply[2:3])
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 'discharging')
return charge, status
def get_serial(device):