Skip to content
Snippets Groups Projects
Verified Commit 22229457 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add fallback for unknown messages to LED cheese example

parent a2c6d90d
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import re import re
import time import time
from collections import OrderedDict
from machine import Pin, PWM from machine import Pin, PWM
from credentials import * from credentials import *
from wifi import Wifi from wifi import Wifi
...@@ -79,6 +80,10 @@ def allow_user(matches, event): ...@@ -79,6 +80,10 @@ def allow_user(matches, event):
f.write(user + "\n") f.write(user + "\n")
matrix.send_room_message(ROOM_ID, "%s darf mich jetzt leuchten lassen!" % (user,)) matrix.send_room_message(ROOM_ID, "%s darf mich jetzt leuchten lassen!" % (user,))
def fallback(matches, event):
"""Fallback fo unknown messages."""
sender = event["sender"]
matrix.send_room_message(ROOM_ID, "Was willst du, %s?" % (sender,))
# Define LED colour pins and PWM objects # Define LED colour pins and PWM objects
pin_red = Pin(13, Pin.OUT) pin_red = Pin(13, Pin.OUT)
...@@ -96,7 +101,10 @@ network.connect() ...@@ -96,7 +101,10 @@ network.connect()
matrix = Matrix(HOMESERVER, MATRIX_ID, ACCESS_TOKEN) matrix = Matrix(HOMESERVER, MATRIX_ID, ACCESS_TOKEN)
# On which texts to react and which LEDs to turn on # On which texts to react and which LEDs to turn on
cases = {"%s, leuchte (.*)" % (NICK,): set_colour, "%s, hoer auf (.*)" % (NICK,): allow_user} cases = OrderedDict()
cases["%s, leuchte (.*)" % (NICK,)] = set_colour
cases["%s, hoer auf (.*)" % (NICK,)] = allow_user
cases["%s.*" % (NICK,)] = fallback
if network.is_connected(): if network.is_connected():
# Set my nickname # Set my nickname
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment