-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLight.py
29 lines (22 loc) · 891 Bytes
/
Light.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8-*-
import re
import os
WORDS = ["LIGHT"]
def handle(text, mic, profile):
"""
Responds to the keyword 'light' by switching on/off the GPIO pin
connected to a light, for example through a relay.
Arguments:
text -- user-input, typically transcribed speech
mic -- used to interact with the user (for both input and output)
profile -- contains information related to the user (e.g., phone
number)
"""
os.system('if [ `cat /sys/class/gpio/gpio18/value` -eq "0" ]; then echo "1" > /sys/class/gpio/gpio18/value; else echo "0" > /sys/class/gpio/gpio18/value; fi')
def isValid(text):
"""
Returns True if the input is related to 'light'.
Arguments:
text -- user-input, typically transcribed speech
"""
return bool(re.search(r'\blight\b', text, re.IGNORECASE))