Merge pull request #111 from rfschmid/show-different-node-details-for-ourself

This commit is contained in:
pdxlocations
2025-02-03 14:08:09 -08:00
committed by GitHub
2 changed files with 53 additions and 28 deletions
+23 -8
View File
@@ -1,6 +1,6 @@
import curses
import textwrap
from utilities.utils import get_channels, get_time_ago, refresh_node_list
from utilities.utils import get_channels, get_readable_duration, get_time_ago, refresh_node_list
from settings import settings_menu
from message_handlers.tx_handler import send_message, send_traceroute
from ui.colors import setup_colors, get_color
@@ -21,18 +21,33 @@ def draw_node_details():
nodestr = ""
width = function_win.getmaxyx()[1]
node_details_list = [f"{node['user']['longName']} "
if 'user' in node and 'longName' in node['user'] else "",
f"({node['user']['shortName']})"
if 'user' in node and 'shortName' in node['user'] else "",
f" | {node['user']['hwModel']}"
if 'user' in node and 'hwModel' in node['user'] else "",
f" | {get_time_ago(node['lastHeard'])}" if ('lastHeard' in node and node['lastHeard']) else "",
f" | Hops: {node['hopsAway']}" if 'hopsAway' in node else "",
f" | SNR: {node['snr']}dB"
if ('snr' in node and 'hopsAway' in node and node['hopsAway'] == 0)
else "",
]
if 'user' in node and 'hwModel' in node['user'] else ""]
if globals.node_list[globals.selected_node] == globals.myNodeNum:
node_details_list.extend([f" | Bat: {node['deviceMetrics']['batteryLevel']}% ({node['deviceMetrics']['voltage']}v)"
if 'deviceMetrics' in node
and 'batteryLevel' in node['deviceMetrics']
and 'voltage' in node['deviceMetrics'] else "",
f" | Up: {get_readable_duration(node['deviceMetrics']['uptimeSeconds'])}" if 'deviceMetrics' in node
and 'uptimeSeconds' in node['deviceMetrics'] else "",
f" | ChUtil: {node['deviceMetrics']['channelUtilization']:.2f}%" if 'deviceMetrics' in node
and 'channelUtilization' in node['deviceMetrics'] else "",
f" | AirUtilTX: {node['deviceMetrics']['airUtilTx']:.2f}%" if 'deviceMetrics' in node
and 'airUtilTx' in node['deviceMetrics'] else "",
])
else:
node_details_list.extend([f" | {get_time_ago(node['lastHeard'])}" if ('lastHeard' in node and node['lastHeard']) else "",
f" | Hops: {node['hopsAway']}" if 'hopsAway' in node else "",
f" | SNR: {node['snr']}dB"
if ('snr' in node and 'hopsAway' in node and node['hopsAway'] == 0)
else "",
])
for s in node_details_list:
if len(nodestr) + len(s) < width - 2:
+30 -20
View File
@@ -1,5 +1,5 @@
import globals
from datetime import datetime
import datetime
from meshtastic.protobuf import config_pb2
import default_config as config
@@ -72,35 +72,45 @@ def convert_to_camel_case(string):
camel_case_string = ''.join(word.capitalize() for word in words)
return camel_case_string
def get_time_ago(timestamp):
now = datetime.now()
dt = datetime.fromtimestamp(timestamp)
delta = now - dt
def get_time_val_units(time_delta):
value = 0
unit = ""
if delta.days > 365:
value = delta.days // 365
if time_delta.days > 365:
value = time_delta.days // 365
unit = "y"
elif delta.days > 30:
value = delta.days // 30
elif time_delta.days > 30:
value = time_delta.days // 30
unit = "mon"
elif delta.days > 7:
value = delta.days // 7
elif time_delta.days > 7:
value = time_delta.days // 7
unit = "w"
elif delta.days > 0:
value = delta.days
elif time_delta.days > 0:
value = time_delta.days
unit = "d"
elif delta.seconds > 3600:
value = delta.seconds // 3600
elif time_delta.seconds > 3600:
value = time_delta.seconds // 3600
unit = "h"
elif delta.seconds > 60:
value = delta.seconds // 60
elif time_delta.seconds > 60:
value = time_delta.seconds // 60
unit = "min"
else:
value = time_delta.seconds
unit = "s"
return (value, unit)
if len(unit) > 0:
def get_readable_duration(seconds):
delta = datetime.timedelta(seconds = seconds)
val, units = get_time_val_units(delta)
return f"{val} {units}"
def get_time_ago(timestamp):
now = datetime.datetime.now()
dt = datetime.datetime.fromtimestamp(timestamp)
delta = now - dt
value, unit = get_time_val_units(delta)
if unit is not "s":
return f"{value} {unit} ago"
return "now"