forked from wzpan/wukong-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lamp.py
30 lines (24 loc) · 923 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
# -*- coding: utf-8-*-
# 台灯控制
import importlib
from robot import config, logging
from robot.sdk.AbstractPlugin import AbstractPlugin
logger = logging.getLogger(__name__)
class Plugin(AbstractPlugin):
SLUG="Lamp"
def handle(self, text, parsed):
import wiringpi
# get config
profile = config.get()
pin=profile[self.SLUG]['pin']
wiringpi.wiringPiSetupPhys()
wiringpi.pinMode(pin,1)
if any(word in text for word in [u"打开",u"开启"]):
wiringpi.digitalWrite(pin,0)
self.say("好的,已经打开台灯", cache=True)
elif any(word in text for word in [u"关闭",u"关掉",u"熄灭"]):
wiringpi.digitalWrite(pin,1)
self.say("好的,已经关闭台灯", cache=True)
def isValid(self, text, parsed):
return importlib.util.find_spec('wiringpi') and \
"台灯" in text