Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemUptime #492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions library/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def DateStats():
# logger.debug("Refresh date stats")
stats.Date.stats()

@async_job("SystemUptime_Stats")
@schedule(timedelta(seconds=config.THEME_DATA['STATS']['UPTIME'].get("INTERVAL", None)).total_seconds())
def SystemUptimeStats():
# logger.debug("Refresh system uptime stats")
stats.SystemUptime.stats()

@async_job("Custom_Stats")
@schedule(timedelta(seconds=config.THEME_DATA['STATS']['CUSTOM'].get("INTERVAL", None)).total_seconds())
Expand Down
32 changes: 31 additions & 1 deletion library/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import library.config as config
from library.display import display
from library.log import logger

from uptime import uptime
DEFAULT_HISTORY_SIZE = 10

ETH_CARD = config.CONFIG_DATA["config"]["ETH"]
Expand Down Expand Up @@ -723,6 +723,36 @@ def stats():
)


class SystemUptime:
@staticmethod
def stats():
if HW_SENSORS == "STATIC":
# For static sensors, use predefined uptime
uptimesec = "4294036"
uptimeformatted = "49 days, 16:47:16"
else:
uptimesec = int(uptime())
uptimeformatted = str(datetime.timedelta(seconds = uptimesec))

systemuptime_theme_data = config.THEME_DATA['STATS']['UPTIME']

systemuptime_sec_theme_data = systemuptime_theme_data['SECONDS']['TEXT']
systemuptime_sec_format = systemuptime_sec_theme_data.get("FORMAT", 'medium')
if systemuptime_sec_theme_data and systemuptime_sec_theme_data['SHOW']:
display_themed_value(
theme_data = systemuptime_sec_theme_data,
value= uptimesec
)

systemuptime_withdays_theme_data = systemuptime_theme_data['WITHDAYS']['TEXT']
systemuptime_formatted_format = systemuptime_withdays_theme_data.get("FORMAT", 'medium')
if systemuptime_withdays_theme_data and systemuptime_withdays_theme_data['SHOW']:
display_themed_value(
theme_data = systemuptime_withdays_theme_data,
value= uptimeformatted
)


class Custom:
@staticmethod
def stats():
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def on_win32_wm_event(hWnd, msg, wParam, lParam):
scheduler.DiskStats()
scheduler.NetStats()
scheduler.DateStats()
scheduler.SystemUptimeStats()
scheduler.CustomStats()
scheduler.QueueHandler()

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pystray~=0.19.5 # Tray icon (all OS)
babel~=2.14.0 # Date/time formatting
ruamel.yaml~=0.18.6 # For configuration editor
sv-ttk~=2.6.0 # Tk Sun Valley theme for configuration editor
uptime~=3.0.1 # For System Uptime

# Efficient image serialization
numpy~=1.24.4; python_version < "3.9" # For Python 3.8 max.
Expand Down
8 changes: 8 additions & 0 deletions res/themes/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,13 @@ STATS:
HOUR:
TEXT:
SHOW: False
UPTIME:
INTERVAL: 100
SECONDS:
TEXT:
SHOW: False
WITHDAYS:
TEXT:
SHOW: False
CUSTOM:
INTERVAL: 100
1 change: 1 addition & 0 deletions theme-editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def refresh_theme():
stats.Disk.stats()
stats.Net.stats()
stats.Date.stats()
stats.SystemUptime.stats()
stats.Custom.stats()


Expand Down