docstrings in ki qualität, weil ki sie geschrieben hat
This commit is contained in:
@@ -43,6 +43,7 @@ def get_coffees():
|
||||
return coffees
|
||||
|
||||
def create_toggle_machine():
|
||||
"""Create a command to toggle the coffee machine."""
|
||||
randID = random.randint(1000, 9999)
|
||||
fullCommand = {'command': 'toggle_machine', 'status': 'pending', 'command_id': randID}
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
@@ -60,6 +61,7 @@ def create_toggle_machine():
|
||||
return fullCommand
|
||||
|
||||
def create_make_coffee():
|
||||
"""Create a command to make coffee."""
|
||||
randID = random.randint(1000, 9999)
|
||||
fullCommand = {'command': 'make_coffee', 'status': 'pending', 'command_id': randID}
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
@@ -75,6 +77,7 @@ def create_make_coffee():
|
||||
return fullCommand
|
||||
|
||||
def create_coffee_entry():
|
||||
"""Create a coffee entry in the coffee database."""
|
||||
conn = sqlite3.connect(DB_PATH_COFFEE)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
|
||||
@@ -23,6 +23,7 @@ from modules.socketio import resend_static_data
|
||||
from modules.db import create_coffee_entry
|
||||
|
||||
def track_coffee_made(data, flanksUp, flanksDown):
|
||||
"""Track if coffee has been made based on the ESP data."""
|
||||
coffee_made = False
|
||||
#logic for tracking coffee made
|
||||
|
||||
@@ -34,18 +35,21 @@ def track_coffee_made(data, flanksUp, flanksDown):
|
||||
return
|
||||
|
||||
def track_error_water(data, flanksUp, flanksDown):
|
||||
"""Track if there could be an error with water."""
|
||||
water = load_dict("water")
|
||||
if water["fill"] <= 7:
|
||||
return True
|
||||
return False
|
||||
|
||||
def track_error_beans(data, flanksUp, flanksDown):
|
||||
"""Track if there could be an error with beans."""
|
||||
beans = load_dict("beans")
|
||||
if beans["fill"] <= 7:
|
||||
return True
|
||||
return False
|
||||
|
||||
def track_error(data, flanksUp, flanksDown):
|
||||
"""Backrrack an Coffee machine error."""
|
||||
if track_error_water(data, flanksUp, flanksDown):
|
||||
return "Wasser Leer"
|
||||
elif track_error_beans(data, flanksUp, flanksDown):
|
||||
@@ -53,6 +57,8 @@ def track_error(data, flanksUp, flanksDown):
|
||||
return "Unbekannter Fehler"
|
||||
|
||||
def refactor_and_use_esp_data(data):
|
||||
"""Refactor and use the ESP data to update the machine state.
|
||||
Calls track_coffee_made() and track_error functions()."""
|
||||
# global oldDataSet
|
||||
if 'oldDataSet' not in globals() or oldDataSet is None:
|
||||
oldDataSet = data # Initialize oldDataSet with default values
|
||||
|
||||
@@ -7,12 +7,15 @@ BASE_PATH = os.path.abspath(BASE_PATH)
|
||||
|
||||
|
||||
def save_dict(name, data):
|
||||
"""Saves a dictionary to a JSON file."""
|
||||
path = os.path.join(BASE_PATH, f"{name}.json")
|
||||
os.makedirs(BASE_PATH, exist_ok=True)
|
||||
with open(path, "w") as f:
|
||||
json.dump(data, f, default=str, indent=2)
|
||||
|
||||
def load_dict(name):
|
||||
"""Loads a dictionary from a JSON file.
|
||||
returns the data or an empty dict if the file does not exist."""
|
||||
path = os.path.join(BASE_PATH, f"{name}.json")
|
||||
if os.path.exists(path):
|
||||
with open(path, "r") as f:
|
||||
|
||||
@@ -8,6 +8,7 @@ socketio = SocketIO(cors_allowed_origins="*", async_mode='threading')
|
||||
|
||||
# function to change the datetime format to isoformat because json does not support datetime
|
||||
def convert_datetimes(obj):
|
||||
"""Convert datetime objects in a dict or list to a specific string format."""
|
||||
if isinstance(obj, dict):
|
||||
return {k: convert_datetimes(v) for k, v in obj.items()}
|
||||
elif isinstance(obj, list):
|
||||
@@ -19,6 +20,7 @@ def convert_datetimes(obj):
|
||||
|
||||
|
||||
def resend_static_data():
|
||||
"""Resend static data to the frontend via SocketIO."""
|
||||
water = load_dict("water")
|
||||
beans = load_dict("beans")
|
||||
machine = load_dict("machine")
|
||||
|
||||
Reference in New Issue
Block a user