Ntfy headers

This commit is contained in:
2025-06-08 19:42:37 -04:00
parent 7dd33aca8c
commit 7e59d19b46
4 changed files with 51 additions and 26 deletions

View File

@ -10,11 +10,11 @@ from ntfy import Ntfy
last_cpu_check_warning: float = time.time()
class Tempature:
cpu_temp_warning_message: str = "🌡️ CPU is at a high tempature."
cpu_temp_queue_check: int = 120 # Seconds
warning_message: str = "🌡️ CPU is at a high tempature."
timeout_check: int = 180 # Seconds
def __init__(self, ntfy_instance: Ntfy, cpu_warning_temp: int):
self.cpu_warning_temp = cpu_warning_temp
def __init__(self, ntfy_instance: Ntfy, warning_temp: int):
self.warning_temp = warning_temp
self.ntfy = ntfy_instance
def get(self) -> Optional[float]:
@ -26,14 +26,14 @@ class Tempature:
return float(match.group(1))
return None
def __queue_time(self, last_check: float) -> bool:
return (time.time() - last_check) > Tempature.cpu_temp_queue_check * 1000
def __timeout_expired(self, last_check: float) -> bool:
return (time.time() - last_check) > Tempature.timeout_check * 1000
def ntfy_check(self):
cpu_temp = self.get()
if cpu_temp:
cpu_temp = math.floor(cpu_temp)
if cpu_temp >= self.cpu_warning_temp and self.__queue_time(last_cpu_check_warning):
self.ntfy.send(f"{Tempature.cpu_temp_warning_message} {cpu_temp} C")
if cpu_temp >= self.warning_temp and self.__timeout_expired(last_cpu_check_warning):
self.ntfy.send(f"{Tempature.warning_message} {cpu_temp} C")
else:
print_t("\033[31mCannot get a feasible tempature value for the CPU. (lm-sensors)\033[0m")