local changes

This commit is contained in:
T
2025-01-30 19:55:45 +01:00
parent 7b89530fbe
commit c54e2649ef

View File

@@ -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))