-
Notifications
You must be signed in to change notification settings - Fork 0
/
voiceserver.py
executable file
·58 lines (47 loc) · 1.41 KB
/
voiceserver.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import requests
from flask import Flask, session, redirect, url_for, escape, request
lightserverAddr = 'http://localhost:2000/'
app = Flask(__name__)
@app.route('/')
def index():
return '''Voice Server'''
zonemap = [ ["all", "house", "cornhole", 'whole'],
['living room'],
["kitchen"],
["living room lamp", "back lamp"],
["front", "entry"],
["office"],
["hall"],
["left", "my lamp", "wills"],
["right", "sarah", "sarahs"],
["master", "our", "bedroom"]]
@app.route('/av/<com>')
def autovoice(com):
if not len(com):
print( "Empty Request")
return ""
zone = '-1'
level = '1'
resp = "None"
for z in reversed(range(len(zonemap))):
for zoneName in zonemap[z]:
if zoneName in com:
print( "Found zone: " + zoneName)
zone = str(z)
break
if not zone == '-1':
break
if 'on' in com:
level = '1'
elif 'night' in com or 'dim' in com or 'them' in com:
level = '2'
elif 'off' in com:
level = '0'
if zone != '-1':
url = lightserverAddr + 'zone/' + zone + '/' + level
print(com + ":" + url)
resp = requests.get(url).content
else:
print("No Zone Found")
return resp
app.run(host='0.0.0.0', debug=True, port=2004)