Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_tools/bin/battery_capacity_summary.py] print N/A for unavailable data #1342

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions jsk_tools/bin/battery_capacity_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def callback(data):
status = data.status
for s in status:
if s.name.startswith("/Power System/Smart Battery"):
results[s.name] = { "HardwareID": s.hardware_id }
if s.name not in results:
results[s.name] = { "HardwareID": s.hardware_id }
for kv in s.values:
if(kv.key.startswith("Full Charge Capacity (mAh)")):
results[s.name]["FullCapacity"] = int(kv.value)
Expand All @@ -33,13 +34,16 @@ def callback(data):
keep_flag = False

def getColor(result):
cap = result["FullCapacity"]
if cap > 5500:
return Fore.GREEN
elif cap > 4000:
return Fore.YELLOW
else:
return Fore.RED
try:
cap = result["FullCapacity"]
if cap > 5500:
return Fore.GREEN
elif cap > 4000:
return Fore.YELLOW
else:
return Fore.RED
except:
return ""

def output():
global results
Expand All @@ -49,7 +53,7 @@ def output():
print fmt.format("Battery Name", *sorted_keys)
for name in sorted_names:
color = getColor(results[name])
v = [results[name][k] for k in sorted_keys]
v = [results[name][k] if k in results[name] else "N/A" for k in sorted_keys]
print color + fmt.format(name, *v) + Fore.RESET

if __name__ == '__main__':
Expand Down