From 5af42c8fe469a23396155bdc70afa5ec4dbf847b Mon Sep 17 00:00:00 2001 From: mate-dev <67105053+mate-dev@users.noreply.github.com> Date: Wed, 6 Dec 2023 18:03:53 +0000 Subject: [PATCH] Added additional conditions for lastHeard, voltage, batteryLevel --- plugins/nodes_plugin.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/nodes_plugin.py b/plugins/nodes_plugin.py index 8fbae57..16adc1f 100644 --- a/plugins/nodes_plugin.py +++ b/plugins/nodes_plugin.py @@ -6,12 +6,17 @@ from datetime import datetime def get_relative_time(timestamp): now = datetime.now() dt = datetime.fromtimestamp(timestamp) + + # Calculate the time difference between the current time and the given timestamp delta = now - dt + + # Extract the relevant components from the time difference days = delta.days seconds = delta.seconds + # Convert the time difference into a relative timeframe if days > 7: - return dt.strftime("%b %d, %Y") + return dt.strftime("%b %d, %Y") # Return the timestamp in a specific format if it's older than 7 days elif days >= 1: return f"{days} days ago" elif seconds >= 3600: @@ -37,8 +42,8 @@ $shortname $longname / $devicemodel / $battery $voltage / $snr / $lastseen from meshtastic_utils import connect_meshtastic meshtastic_client = connect_meshtastic() - - response = f">**Nodes: {len(meshtastic_client.nodes)}**\n\n" + + response = f"Nodes: {len(meshtastic_client.nodes)}\n" for node, info in meshtastic_client.nodes.items(): snr = "" @@ -56,11 +61,8 @@ $shortname $longname / $devicemodel / $battery $voltage / $snr / $lastseen voltage = f"{info['deviceMetrics']['voltage']}V " if "batteryLevel" in info["deviceMetrics"] and info["deviceMetrics"]["batteryLevel"] is not None: battery = f"{info['deviceMetrics']['batteryLevel']}% " - - response += f">