The raspi now controls a motor to lock unlock
This commit is contained in:
2026-06-07 10:27:22 +02:00
parent 02f7502daf
commit 79d441a86e
4 changed files with 214 additions and 10 deletions
+30 -10
View File
@@ -5,6 +5,9 @@ class CLI:
def __init__(self, tracker) -> None:
self.tracker = tracker
self.current_user = None
from raspi.motor import Raspi
self.motor = Raspi()
def run(self):
while True:
@@ -157,20 +160,27 @@ class CLI:
if confirm == "y":
result = self.tracker.add_purchase(self.current_user, item_id)
self._clear_screen()
print("=" * 50)
print("PURCHASE ADDED")
print("=" * 50)
print()
print(f"{result['message']}")
print(f"New debt: ${result['new_debt']:.2f}")
print()
if result["status"] == "success":
self._clear_screen()
print("=" * 50)
print("PURCHASE ADDED")
print("=" * 50)
print()
print(f"{result['message']}")
print(f"New debt: ${result['new_debt']:.2f}")
print()
input("Press Enter to continue...")
self.motor.unlock_async()
input("Press Enter to continue...")
self.motor.lock_async()
else:
print(f"Error: {result['message']}")
input("Press Enter to continue...")
else:
print("Purchase cancelled.")
input("Press Enter to continue...")
def _view_user_debt(self):
self._clear_screen()
@@ -237,7 +247,9 @@ class CLI:
print("4. View transaction history")
print("5. Manage users")
print("6. Manage items")
print("7. Logout")
print("7. Open Kühlschrank (Unlock)")
print("8. Close Kühlschrank (Lock)")
print("9. Logout")
print()
choice = input("Choose option: ").strip()
@@ -255,6 +267,14 @@ class CLI:
elif choice == "6":
self._manage_items()
elif choice == "7":
print("Kühlschrank wird geöffnet (Entriegeln)...")
self.motor.unlock_async()
input("Press Enter to continue...")
elif choice == "8":
print("Kühlschrank wird geschlossen (Verriegeln)...")
self.motor.lock_async()
input("Press Enter to continue...")
elif choice == "9":
break
else:
self._invalid_choice()