From 75881cbe48e88956306dfe063bb8a8c856e7e644 Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Sun, 23 Feb 2025 21:17:03 +0100 Subject: [PATCH] Add a timestamp with the last update to each card --- dashboard/system.py | 6 ++++++ dashboard/ui.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dashboard/system.py b/dashboard/system.py index a28fc81..17e0d5d 100644 --- a/dashboard/system.py +++ b/dashboard/system.py @@ -6,6 +6,7 @@ import platform import requests import subprocess +import time from enum import Enum from typing import Tuple @@ -25,12 +26,17 @@ class System: self.description = description self.state = SystemState.UNKNOWN self.state_verbose = "" + self.last_update = 0 def get_actions(self) -> dict: # to be overridden # return {'ActionName': callable, ...} return {} + def _update_state(self): + self.update_state() + self.last_update = time.time() + def update_state(self): # to be overridden self.state = SystemState.UNKNOWN diff --git a/dashboard/ui.py b/dashboard/ui.py index 6c721f9..0b32532 100644 --- a/dashboard/ui.py +++ b/dashboard/ui.py @@ -1,6 +1,7 @@ # Copyright (c) 2025, Julian Müller (ChaoticByte) import asyncio +import datetime from typing import List from .system import System, SystemState @@ -28,7 +29,10 @@ def init_ui( card = card.style("border-left: 4px solid dodgerblue") with card: - ui.label(t.name).classes("text-xl font-medium text-wrap") + with ui.row(align_items="center").classes("w-full"): + ui.label(t.name).classes("text-xl font-medium text-wrap") + ui.space() + ui.label(datetime.datetime.fromtimestamp(t.last_update).strftime(r"%H:%M:%S")).classes("opacity-25 text-xs") if t.description != "": ui.label(t.description).classes("opacity-75 text-wrap") if t.state_verbose != "": @@ -51,7 +55,7 @@ def init_ui( for t in systems: if isinstance(t, System): # we start all ... - coros.append(run.io_bound(t.update_state)) + coros.append(run.io_bound(t._update_state)) # ... and await later. asyncio.gather(*coros)