forked from dingdang-robot/dingdang-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLamp.py
37 lines (28 loc) · 867 Bytes
/
Lamp.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
30
31
32
33
34
35
36
37
# -*- coding: utf-8-*- # 台灯控制
import sys
import os
import logging
import wiringpi
sys.setdefaultencoding('utf8')
SLUG="Lamp"
WORDS=["TAIDENG"]
def handle(text, mic, profile, wxbot=None):
logger = logging.getLogger(__name__)
# get config
pin=profile[SLUG]['pin']
wiringpi.wiringPiSetupPhys()
wiringpi.pinMode(pin,1)
if any(word in text for word in [u"打开",u"开启"]):
wiringpi.digitalWrite(pin,0)
mic.say("好的,已经打开台灯")
elif any(word in text for word in [u"关闭",u"关掉",u"熄灭"]):
wiringpi.digitalWrite(pin,1)
mic.say("好的,已经关闭台灯")
return True
def isValid(text):
"""
Returns True if the input is related to weather.
Arguments:
text -- user-input, typically transcribed speech
"""
return u"台灯" in text