From c9cfcfaddf23038eb2da0badf8b85a80610a124e Mon Sep 17 00:00:00 2001 From: MarkParker5 Date: Tue, 23 Mar 2021 00:55:30 +0200 Subject: [PATCH] add SmartHome.light (led control) v.1 --- SmartHome/__init__.py | 1 + SmartHome/light.py | 64 +++++++++++++++++++++++++++++++++++++++++++ voice_assistant.py | 1 - 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 SmartHome/light.py diff --git a/SmartHome/__init__.py b/SmartHome/__init__.py index 8ca2a13..35e19ec 100644 --- a/SmartHome/__init__.py +++ b/SmartHome/__init__.py @@ -1,3 +1,4 @@ from .main_light import * from .window import * from .alarmclock import * +from .light import * diff --git a/SmartHome/light.py b/SmartHome/light.py new file mode 100644 index 0000000..1c5fc9a --- /dev/null +++ b/SmartHome/light.py @@ -0,0 +1,64 @@ +from .SmartHome import * +from Command import Response +################################################################################ + +def method(params): + SmartHome.send({ + 'target': 'main_light', + 'cmd': 'light_on', + }) + voice = text = '' + return Response(text = text, voice = voice) + +keywords = {} +patterns = ['* (включ|выключ)* свет *'] +main_light = SmartHome('main_light', keywords, patterns) +main_light.setStart(method) + +################################################################################ +# led + +def method(params): + SmartHome.send({ + 'target': 'led', + 'cmd': 'led_on', + }) + voice = text = '' + return Response(text = text, voice = voice) + +keywords = {} +patterns = ['* включи* подсветку *'] +light_on = SmartHome('led_on', keywords, patterns) +light_on.setStart(method) + +################################################################################ + +def method(params): + SmartHome.send({ + 'target': 'led', + 'cmd': 'led_off', + }) + voice = text = '' + return Response(text = text, voice = voice) + +keywords = {} +patterns = ['* выключи* подсветку *'] +led_off = SmartHome('led_off', keywords, patterns) +led_off.setStart(method) + +################################################################################ + +def method(params): + SmartHome.send({ + 'target': 'led', + 'cmd': 'led_hello', + }) + voice = text = '' + return Response(text = text, voice = voice) + +keywords = {} +patterns = [] +led_hello = SmartHome('led_hello', keywords, patterns) +led_hello.setStart(method) + +################################################################################ diff --git a/voice_assistant.py b/voice_assistant.py index 4f206a3..cc739cd 100644 --- a/voice_assistant.py +++ b/voice_assistant.py @@ -118,7 +118,6 @@ while True: print('\nYou: ', end='') speech = listener.listen() print(speech.get('text') or '', end='') - voids = 0 while True: if speech['status'] == 'error': break