Add a timestamp with the last update to each card
This commit is contained in:
parent
a8c8dca4aa
commit
75881cbe48
2 changed files with 12 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
||||||
import platform
|
import platform
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
@ -25,12 +26,17 @@ class System:
|
||||||
self.description = description
|
self.description = description
|
||||||
self.state = SystemState.UNKNOWN
|
self.state = SystemState.UNKNOWN
|
||||||
self.state_verbose = ""
|
self.state_verbose = ""
|
||||||
|
self.last_update = 0
|
||||||
|
|
||||||
def get_actions(self) -> dict:
|
def get_actions(self) -> dict:
|
||||||
# to be overridden
|
# to be overridden
|
||||||
# return {'ActionName': callable, ...}
|
# return {'ActionName': callable, ...}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def _update_state(self):
|
||||||
|
self.update_state()
|
||||||
|
self.last_update = time.time()
|
||||||
|
|
||||||
def update_state(self):
|
def update_state(self):
|
||||||
# to be overridden
|
# to be overridden
|
||||||
self.state = SystemState.UNKNOWN
|
self.state = SystemState.UNKNOWN
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Copyright (c) 2025, Julian Müller (ChaoticByte)
|
# Copyright (c) 2025, Julian Müller (ChaoticByte)
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import datetime
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
from .system import System, SystemState
|
from .system import System, SystemState
|
||||||
|
@ -28,7 +29,10 @@ def init_ui(
|
||||||
card = card.style("border-left: 4px solid dodgerblue")
|
card = card.style("border-left: 4px solid dodgerblue")
|
||||||
|
|
||||||
with card:
|
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 != "":
|
if t.description != "":
|
||||||
ui.label(t.description).classes("opacity-75 text-wrap")
|
ui.label(t.description).classes("opacity-75 text-wrap")
|
||||||
if t.state_verbose != "":
|
if t.state_verbose != "":
|
||||||
|
@ -51,7 +55,7 @@ def init_ui(
|
||||||
for t in systems:
|
for t in systems:
|
||||||
if isinstance(t, System):
|
if isinstance(t, System):
|
||||||
# we start all ...
|
# we start all ...
|
||||||
coros.append(run.io_bound(t.update_state))
|
coros.append(run.io_bound(t._update_state))
|
||||||
# ... and await later.
|
# ... and await later.
|
||||||
asyncio.gather(*coros)
|
asyncio.gather(*coros)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue