local changes
This commit is contained in:
19
button.py
19
button.py
@@ -9,12 +9,13 @@ from urllib.request import urlopen
|
|||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
from os import system
|
from os import system
|
||||||
import threading
|
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):
|
def ssh_(host, name):
|
||||||
print("[ssh]", host, name)
|
print("[ssh]", host, name, file=stdout)
|
||||||
system("ssh " + str(name) + "@" + host)
|
system("ssh " + str(name) + "@" + host)
|
||||||
|
|
||||||
def ssh(host, name):
|
def ssh(host, name):
|
||||||
@@ -131,6 +132,9 @@ class APILoader:
|
|||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def getData(self):
|
def getData(self):
|
||||||
|
if not self.thread.is_alive():
|
||||||
|
print("API thread is dead. Trying to restart...", file=stdout)
|
||||||
|
self.start()
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -138,13 +142,14 @@ class APILoader:
|
|||||||
try:
|
try:
|
||||||
self.loadData()
|
self.loadData()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Unable to load API data:", e)
|
print("Unable to load API data:", e, file=stdout)
|
||||||
|
|
||||||
time.sleep(self.delay)
|
time.sleep(self.delay)
|
||||||
|
|
||||||
def loadData(self):
|
def loadData(self):
|
||||||
|
print("Loading API data...", file=stdout)
|
||||||
# Load api data
|
# 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"))
|
data = loads(response.decode("utf-8"))
|
||||||
|
|
||||||
self.data = {door["location"]: not door["value"]
|
self.data = {door["location"]: not door["value"]
|
||||||
@@ -153,7 +158,7 @@ class APILoader:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
print("[*] Initializing...")
|
print("[*] Initializing...", file=stdout)
|
||||||
# Initialize GPIO board
|
# Initialize GPIO board
|
||||||
gpio.setmode(gpio.BCM)
|
gpio.setmode(gpio.BCM)
|
||||||
|
|
||||||
@@ -179,14 +184,14 @@ sensor = MultiSensor([i for i in buttons])
|
|||||||
|
|
||||||
doors = {
|
doors = {
|
||||||
"aerie": Door("10.42.1.28", ("open", "close")),
|
"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
|
# Initialize API interface
|
||||||
loader = APILoader(4)
|
loader = APILoader(4)
|
||||||
loader.start()
|
loader.start()
|
||||||
|
|
||||||
print("[*] Starting...")
|
print("[*] Starting...", file=stdout)
|
||||||
while True:
|
while True:
|
||||||
for led in leds:
|
for led in leds:
|
||||||
leds[led].draw((0, 0, 0))
|
leds[led].draw((0, 0, 0))
|
||||||
|
Reference in New Issue
Block a user