Skip to content

Commit fe061d7

Browse files
committed
Update config.yaml with new HW_SENSORS settings
1 parent a2371ee commit fe061d7

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

config.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ config:
1313
# THEME: bash-dark-green
1414
THEME: 3.5inchTheme2
1515

16-
# Network metrics
17-
# Put the interface name or let it blank if the card does not exist
16+
# Hardware sensors reading
17+
# Choose the appropriate method for reading your hardware sensors:
18+
# - PYTHON use Python libraries (psutils, GPUtil...) to read hardware sensors (supports all OS but not all HW)
19+
# - LHM use LibreHardwareMonitor library to read hardware sensors (Windows only)
20+
# - STUB use fake random data instead of real hardware sensors
21+
# - AUTO use the best method based on your OS: Windows OS will use LHM, other OS will use Python libraries
22+
HW_SENSORS: AUTO
23+
24+
# Network interfaces
1825
# Linux/MacOS interfaces are named "eth0", "wlan0", "wlp1s0", "enp2s0"...
1926
# For Windows use the interfaces pretty name: "Ethernet 2", "Wi-Fi", ...
27+
# Leave the fields empty if the card does not exist on your setup
2028
ETH: "eth0" # Ethernet Card
2129
WLO: "wlan0" # Wi-Fi Card
2230

library/sensors/sensors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ def disk_usage_percent() -> float:
7474
def disk_used() -> int:
7575
pass
7676

77-
@staticmethod
78-
@abstractmethod
79-
def disk_total() -> int:
80-
pass
81-
8277
@staticmethod
8378
@abstractmethod
8479
def disk_free() -> int:

library/sensors/sensors_python.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,6 @@ def disk_usage_percent() -> float:
241241
def disk_used() -> int:
242242
return psutil.disk_usage("/").used
243243

244-
@staticmethod
245-
def disk_total() -> int:
246-
return psutil.disk_usage("/").total
247-
248244
@staticmethod
249245
def disk_free() -> int:
250246
return psutil.disk_usage("/").free

library/sensors/sensors_simulated.py renamed to library/sensors/sensors_stub.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def virtual_percent() -> float:
4747

4848
@staticmethod
4949
def virtual_used() -> int:
50-
return random.randint(300, 16000)
50+
return random.randint(300000000, 16000000000)
5151

5252
@staticmethod
5353
def virtual_free() -> int:
54-
return random.randint(300, 16000)
54+
return random.randint(300000000, 16000000000)
5555

5656

5757
class Disk(sensors.Disk):
@@ -63,10 +63,6 @@ def disk_usage_percent() -> float:
6363
def disk_used() -> int:
6464
return random.randint(1000000000, 2000000000000)
6565

66-
@staticmethod
67-
def disk_total() -> int:
68-
return random.randint(1000000000, 2000000000000)
69-
7066
@staticmethod
7167
def disk_free() -> int:
7268
return random.randint(1000000000, 2000000000000)

library/stats.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
import datetime
22
import math
3+
import os
4+
import platform
5+
import sys
36

47
from psutil._common import bytes2human
58

69
import library.config as config
7-
import library.sensors.sensors_python as sensors
810
from library.display import display
911
from library.log import logger
1012

1113
THEME_DATA = config.THEME_DATA
1214
CONFIG_DATA = config.CONFIG_DATA
1315
ETH_CARD = CONFIG_DATA["config"]["ETH"]
1416
WLO_CARD = CONFIG_DATA["config"]["WLO"]
17+
HW_SENSORS = CONFIG_DATA["config"]["HW_SENSORS"]
18+
19+
if HW_SENSORS == "PYTHON":
20+
import library.sensors.sensors_python as sensors
21+
elif HW_SENSORS == "LHM":
22+
pass
23+
elif HW_SENSORS == "STUB":
24+
import library.sensors.sensors_stub as sensors
25+
elif HW_SENSORS == "AUTO":
26+
if platform.system() == 'Windows':
27+
pass
28+
else:
29+
import library.sensors.sensors_python as sensors
30+
else:
31+
logger.error("Unsupported SENSORS value in config.yaml")
32+
try:
33+
sys.exit(0)
34+
except:
35+
os._exit(0)
1536

1637

1738
def get_full_path(path, name):
@@ -375,6 +396,8 @@ def stats():
375396
class Disk:
376397
@staticmethod
377398
def stats():
399+
used = sensors.Disk.disk_used()
400+
free = sensors.Disk.disk_free()
378401
if THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("SHOW", False):
379402
display.lcd.DisplayProgressBar(
380403
x=THEME_DATA['STATS']['DISK']['USED']['GRAPH'].get("X", 0),
@@ -394,7 +417,7 @@ def stats():
394417

395418
if THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("SHOW", False):
396419
display.lcd.DisplayText(
397-
text=f"{int(sensors.Disk.disk_used() / 1000000000):>5} G",
420+
text=f"{int(used / 1000000000):>5} G",
398421
x=THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("X", 0),
399422
y=THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("Y", 0),
400423
font=THEME_DATA['STATS']['DISK']['USED']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
@@ -425,7 +448,7 @@ def stats():
425448

426449
if THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("SHOW", False):
427450
display.lcd.DisplayText(
428-
text=f"{int(sensors.Disk.disk_total() / 1000000000):>5} G",
451+
text=f"{int((free + used) / 1000000000):>5} G",
429452
x=THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("X", 0),
430453
y=THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("Y", 0),
431454
font=THEME_DATA['STATS']['DISK']['TOTAL']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),
@@ -439,7 +462,7 @@ def stats():
439462

440463
if THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("SHOW", False):
441464
display.lcd.DisplayText(
442-
text=f"{int(sensors.Disk.disk_free() / 1000000000):>5} G",
465+
text=f"{int(free / 1000000000):>5} G",
443466
x=THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("X", 0),
444467
y=THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("Y", 0),
445468
font=THEME_DATA['STATS']['DISK']['FREE']['TEXT'].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"),

0 commit comments

Comments
 (0)