From 63f69faada960838922307ff7dfddd459b33e0a5 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Fri, 8 Nov 2024 16:20:00 +0800 Subject: [PATCH] Add temperature sensor monitoring --- temperature_monitor.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 temperature_monitor.py diff --git a/temperature_monitor.py b/temperature_monitor.py new file mode 100644 index 0000000..f775b51 --- /dev/null +++ b/temperature_monitor.py @@ -0,0 +1,35 @@ +""" +Temperature sensor monitoring +""" + +import psutil + + +class TemperatureMonitor: + def get_temperatures(self): + """Get system temperatures if available""" + try: + temps = psutil.sensors_temperatures() + return temps + except AttributeError: + return None + + def display_temperatures(self): + """Display system temperatures""" + temps = self.get_temperatures() + + if not temps: + print("\nTemperature sensors not available on this system") + return + + print("\nSystem Temperatures:") + print(f"{'Sensor':<30}{'Current':<15}{'High':<15}{'Critical':<15}") + print("-" * 75) + + for name, entries in temps.items(): + for entry in entries: + label = entry.label or name + current = f"{entry.current}°C" if entry.current else "N/A" + high = f"{entry.high}°C" if entry.high else "N/A" + critical = f"{entry.critical}°C" if entry.critical else "N/A" + print(f"{label:<30}{current:<15}{high:<15}{critical:<15}")