From c54e2649efb57b489566131101fe323f5c0246aa Mon Sep 17 00:00:00 2001 From: T Date: Thu, 30 Jan 2025 19:55:45 +0100 Subject: [PATCH] local changes --- button.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/button.py b/button.py index a952292..616ec66 100644 --- a/button.py +++ b/button.py @@ -9,12 +9,13 @@ from urllib.request import urlopen from os.path import expanduser from os import system import threading +from sys import stdout -print("Imports took", round(time.time() - start, 2), "seconds") +print("Imports took", round(time.time() - start, 2), "seconds", file=stdout) def ssh_(host, name): - print("[ssh]", host, name) + print("[ssh]", host, name, file=stdout) system("ssh " + str(name) + "@" + host) def ssh(host, name): @@ -131,6 +132,9 @@ class APILoader: self.thread.start() def getData(self): + if not self.thread.is_alive(): + print("API thread is dead. Trying to restart...", file=stdout) + self.start() return self.data def run(self): @@ -138,13 +142,14 @@ class APILoader: try: self.loadData() except Exception as e: - print("Unable to load API data:", e) + print("Unable to load API data:", e, file=stdout) time.sleep(self.delay) def loadData(self): + print("Loading API data...", file=stdout) # Load api data - response = urlopen("https://status.chaospott.de/api/").read() + response = urlopen("https://status.chaospott.de/status.json").read() data = loads(response.decode("utf-8")) self.data = {door["location"]: not door["value"] @@ -153,7 +158,7 @@ class APILoader: -print("[*] Initializing...") +print("[*] Initializing...", file=stdout) # Initialize GPIO board gpio.setmode(gpio.BCM) @@ -179,14 +184,14 @@ sensor = MultiSensor([i for i in buttons]) doors = { "aerie": Door("10.42.1.28", ("open", "close")), - "cellar": Door("10.42.1.20", ("unlock", "lock")), + "cellar": Door("10.42.1.20", ("open", "close")), } # Initialize API interface loader = APILoader(4) loader.start() -print("[*] Starting...") +print("[*] Starting...", file=stdout) while True: for led in leds: leds[led].draw((0, 0, 0))