jikes
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# this function is processing the cyclic data from the esp format:
|
# this function is processing the cyclic data from the esp format:
|
||||||
# [off_value/on_value]
|
# [off_value/on_value]
|
||||||
# {
|
# {
|
||||||
@@ -19,5 +18,77 @@
|
|||||||
# "kaffee_fertig": [0/1],
|
# "kaffee_fertig": [0/1],
|
||||||
# }
|
# }
|
||||||
|
|
||||||
def refactor_and_use_esp_data(data):
|
from modules.persistence import load_dict, save_dict
|
||||||
|
from modules.socketio import resend_static_data
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
DB_PATH_COFFEE = os.path.join(os.path.dirname(__file__), '../db/coffee.db')
|
||||||
|
|
||||||
|
def track_coffee_made(data, flanksUp, flanksDown):
|
||||||
|
coffee_made = False
|
||||||
|
#logic for tracking coffee made
|
||||||
|
|
||||||
|
if coffee_made:
|
||||||
|
conn = sqlite3.connect(DB_PATH_COFFEE)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO coffee (user, status)
|
||||||
|
VALUES (?, ?)
|
||||||
|
""", ("admin", "served"))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
print("Coffee made detected, data saved.")
|
||||||
|
return
|
||||||
|
|
||||||
|
def track_error_water(data, flanksUp, flanksDown):
|
||||||
|
water = load_dict("water")
|
||||||
|
if water["fill"] <= 7:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def track_error_beans(data, flanksUp, flanksDown):
|
||||||
|
beans = load_dict("beans")
|
||||||
|
if beans["fill"] <= 7:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def track_error(data, flanksUp, flanksDown):
|
||||||
|
if track_error_water(data, flanksUp, flanksDown):
|
||||||
|
return "Wasser Leer"
|
||||||
|
elif track_error_beans(data, flanksUp, flanksDown):
|
||||||
|
return "Bohnen Leer"
|
||||||
|
return "Unbekannter Fehler"
|
||||||
|
|
||||||
|
def refactor_and_use_esp_data(data):
|
||||||
|
# global oldDataSet
|
||||||
|
if 'oldDataSet' not in globals() or oldDataSet is None:
|
||||||
|
oldDataSet = data # Initialize oldDataSet with default values
|
||||||
|
|
||||||
|
flanksUp = {key: (oldDataSet[key] == 0 and data[key] == 1) for key in data}
|
||||||
|
flanksDown = {key: (oldDataSet[key] == 1 and data[key] == 0) for key in data}
|
||||||
|
|
||||||
|
machine = load_dict("machine")
|
||||||
|
if data["an"] == 0:
|
||||||
|
machine["state"] = "ON"
|
||||||
|
elif data["an"] == 1: #elif die Sängerin xD
|
||||||
|
machine["state"] = "OFF"
|
||||||
|
|
||||||
|
if data["bereit"] == 0:
|
||||||
|
machine["ready"] = True
|
||||||
|
elif data["bereit"] == 1:
|
||||||
|
machine["ready"] = False
|
||||||
|
|
||||||
|
if data["fehler"] == 0:
|
||||||
|
machine["berror"] = True
|
||||||
|
machine["error"] = track_error(data, flanksUp, flanksDown)
|
||||||
|
elif data["fehler"] == 1:
|
||||||
|
machine["berror"] = False
|
||||||
|
machine["error"] = "Keine Fehler"
|
||||||
|
|
||||||
|
save_dict("machine", machine)
|
||||||
|
resend_static_data()
|
||||||
|
|
||||||
|
track_coffee_made(data, flanksUp, flanksDown)
|
||||||
|
oldDataSet = data
|
||||||
return
|
return
|
||||||
Reference in New Issue
Block a user