# wasmachine.py - een toestandsmachine als tabel: (toestand, gebeurtenis) -> (nieuwe toestand, actie)
OVERGANGEN = {
    ("KLAAR", "start"): ("VULLEN", "deur vergrendelen, waterklep open"),
    ("VULLEN", "niveau bereikt"): ("VERWARMEN", "waterklep dicht, verwarming aan"),
    ("VULLEN", "5 min voorbij"): ("FOUT", "waterklep dicht: komt er geen water?"),
    ("VERWARMEN", "40 graden"): ("WASSEN", "verwarming uit, trommel draait"),
    ("WASSEN", "30 min voorbij"): ("POMPEN", "trommel stil, pomp aan"),
    ("POMPEN", "leeg"): ("SPOELEN", "pomp uit, waterklep open, trommel draait"),
    ("POMPEN", "3 min voorbij"): ("FOUT", "pomp uit: filter verstopt?"),
    ("SPOELEN", "10 min voorbij"): ("CENTRIFUGEREN", "waterklep dicht, pomp aan, 1200 omw/min"),
    ("CENTRIFUGEREN", "8 min voorbij"): ("KLAAR", "trommel stil, pomp uit, deur ontgrendelen"),
}


def verwerk(toestand, gebeurtenis):
    """Zoekt de overgang op. Staat de combinatie niet in de tabel, dan gebeurt er niets."""
    if (toestand, gebeurtenis) in OVERGANGEN:
        nieuw, actie = OVERGANGEN[(toestand, gebeurtenis)]
        print(f"{toestand:13} --{gebeurtenis}--> {nieuw:13} {actie}")
        return nieuw
    print(f"{toestand:13} --{gebeurtenis}--> (genegeerd)")
    return toestand


toestand = "KLAAR"
for g in ["deur open", "start", "niveau bereikt", "start", "40 graden", "deur open", "30 min voorbij",
          "3 min voorbij"]:
    toestand = verwerk(toestand, g)
print("eindtoestand:", toestand)
