Skip to content

Commit 3cf76cc

Browse files
authored
Merge pull request #492 from NurNano/feature/SystemUptime
2 parents 2a25630 + c0e3736 commit 3cf76cc

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

library/scheduler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def DateStats():
153153
# logger.debug("Refresh date stats")
154154
stats.Date.stats()
155155

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

157162
@async_job("Custom_Stats")
158163
@schedule(timedelta(seconds=config.THEME_DATA['STATS']['CUSTOM'].get("INTERVAL", None)).total_seconds())

library/stats.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import library.config as config
3535
from library.display import display
3636
from library.log import logger
37-
37+
from uptime import uptime
3838
DEFAULT_HISTORY_SIZE = 10
3939

4040
ETH_CARD = config.CONFIG_DATA["config"]["ETH"]
@@ -723,6 +723,36 @@ def stats():
723723
)
724724

725725

726+
class SystemUptime:
727+
@staticmethod
728+
def stats():
729+
if HW_SENSORS == "STATIC":
730+
# For static sensors, use predefined uptime
731+
uptimesec = "4294036"
732+
uptimeformatted = "49 days, 16:47:16"
733+
else:
734+
uptimesec = int(uptime())
735+
uptimeformatted = str(datetime.timedelta(seconds = uptimesec))
736+
737+
systemuptime_theme_data = config.THEME_DATA['STATS']['UPTIME']
738+
739+
systemuptime_sec_theme_data = systemuptime_theme_data['SECONDS']['TEXT']
740+
systemuptime_sec_format = systemuptime_sec_theme_data.get("FORMAT", 'medium')
741+
if systemuptime_sec_theme_data and systemuptime_sec_theme_data['SHOW']:
742+
display_themed_value(
743+
theme_data = systemuptime_sec_theme_data,
744+
value= uptimesec
745+
)
746+
747+
systemuptime_withdays_theme_data = systemuptime_theme_data['WITHDAYS']['TEXT']
748+
systemuptime_formatted_format = systemuptime_withdays_theme_data.get("FORMAT", 'medium')
749+
if systemuptime_withdays_theme_data and systemuptime_withdays_theme_data['SHOW']:
750+
display_themed_value(
751+
theme_data = systemuptime_withdays_theme_data,
752+
value= uptimeformatted
753+
)
754+
755+
726756
class Custom:
727757
@staticmethod
728758
def stats():

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def on_win32_wm_event(hWnd, msg, wParam, lParam):
208208
scheduler.DiskStats()
209209
scheduler.NetStats()
210210
scheduler.DateStats()
211+
scheduler.SystemUptimeStats()
211212
scheduler.CustomStats()
212213
scheduler.QueueHandler()
213214

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pystray~=0.19.5 # Tray icon (all OS)
77
babel~=2.14.0 # Date/time formatting
88
ruamel.yaml~=0.18.6 # For configuration editor
99
sv-ttk~=2.6.0 # Tk Sun Valley theme for configuration editor
10+
uptime~=3.0.1 # For System Uptime
1011

1112
# Efficient image serialization
1213
numpy~=1.24.4; python_version < "3.9" # For Python 3.8 max.

res/themes/default.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,13 @@ STATS:
206206
HOUR:
207207
TEXT:
208208
SHOW: False
209+
UPTIME:
210+
INTERVAL: 100
211+
SECONDS:
212+
TEXT:
213+
SHOW: False
214+
WITHDAYS:
215+
TEXT:
216+
SHOW: False
209217
CUSTOM:
210218
INTERVAL: 100

theme-editor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def refresh_theme():
111111
stats.Disk.stats()
112112
stats.Net.stats()
113113
stats.Date.stats()
114+
stats.SystemUptime.stats()
114115
stats.Custom.stats()
115116

116117

0 commit comments

Comments
 (0)