mirror of
https://github.com/meshtastic/python.git
synced 2026-01-20 05:37:57 -05:00
fixed decimal places and LastHeard
This commit is contained in:
@@ -133,6 +133,16 @@ def setRouter(interface, on):
|
||||
prefs.gps_attempt_time = 0
|
||||
prefs.gps_update_interval = 0
|
||||
|
||||
|
||||
#Returns formatted value
|
||||
def formatFloat(value, formatStr, default="N/A"):
|
||||
return formatStr.format(value) if value else default
|
||||
|
||||
#Returns Last Heard Time in human readable format
|
||||
def getLH(ts, default="N/A"):
|
||||
return datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') if ts else default
|
||||
|
||||
#Print Nodes
|
||||
def printNodes(nodes):
|
||||
#Create the table and define the structure
|
||||
table = EasyTable("Nodes")
|
||||
@@ -143,14 +153,15 @@ def printNodes(nodes):
|
||||
tableData = []
|
||||
for node in nodes:
|
||||
#aux var to get not defined keys
|
||||
lat=str(node['position'].get("latitude", "N/A"))
|
||||
lon=str(node['position'].get("longitude", "N/A"))
|
||||
alt=str(node['position'].get("altitude", "N/A"))
|
||||
batt=str(node['position'].get("batteryLevel", "N/A"))
|
||||
snr=str(node.get("snr", "N/A"))
|
||||
LH= getLH(node['position'].get("time"))
|
||||
lat=formatFloat(node['position'].get("latitude"), "{:.4f}", "N/A")
|
||||
lon=formatFloat(node['position'].get("longitude"), "{:.4f}", "N/A")
|
||||
alt=formatFloat(node['position'].get("altitude"), "{:.4f}", "N/A")
|
||||
batt=formatFloat(node['position'].get("batteryLevel"), "{:.2f}", "N/A")
|
||||
snr=formatFloat(node.get("snr"), "{:.2f}", "N/A")
|
||||
tableData.append({"User":node['user']['longName'],
|
||||
"Position":"Lat:"+lat+",Lon:"+lon+",Alt:"+alt,
|
||||
"Battery":batt, "SNR":snr})
|
||||
"Battery":batt, "SNR":snr, "LastHeard":LH})
|
||||
table.setData(tableData)
|
||||
table.displayTable()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user