-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·83 lines (71 loc) · 2.07 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import os
import logging
import samsungctl
import re
from flask import Flask
from flask_ask import Ask, statement, question, session
DEBUG = True
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = DEBUG
ask = Ask(app, "/")
logging.getLogger('flask_ask').setLevel(logging.DEBUG)
#logging.basicConfig(level=logging.DEBUG
# format='%(asctime)s %(levelname)s %(message)s',
# filename='/tmp/myapp.log',
# filemode='w')
remoteConfig = {
"name": "samsungctl",
"description": "PC",
"id": "sergVoiceRemote",
"host": "192.168.0.13",
"port": 55000,
"method": "legacy",
"timeout": 1,
}
RemoteKeyMap = {
'volume up': 'KEY_VOLUP',
'volume down': 'KEY_VOLDOWN',
'channel %d': 'KEY_%d',
'channel up': 'KEY_UP',
'channel down': 'KEY_DOWN',
'power off': 'KEY_POWEROFF'
}
def press_remote_key(key_pressed):
Remote = samsungctl.Remote(remoteConfig)
k = key_pressed.lower()
if re.match('channel (\d+)', k):
n = int(re.match('channel (\d+)', 'channel 5').groups()[0])
k_code = 'KEY_%d' % (n)
else:
k_code = RemoteKeyMap[k]
return Remote.control(k_code)
@ask.launch
def start_skill():
welcome_message = 'Hello to Samsung TV Remote'
return statement(welcome_message)
@ask.intent('AMAZON.StopIntent')
def stop():
return statement("Goodbye")
@ask.intent('AMAZON.CancelIntent')
def cancel():
return statement("Goodbye")
@ask.session_ended
def session_ended():
return "{}", 200
@ask.intent('tvButtonPressed',
mapping={
'key': 'Key',
'direction': 'Direction'
})
def tv_button_pressed(key, direction):
k=key + " " +direction
press_remote_key(k)
return statement("ok").simple_card('The Tele', "ok")
if __name__ == '__main__':
if 'ASK_VERIFY_REQUESTS' in os.environ:
verify = str(os.environ.get('ASK_VERIFY_REQUESTS', '')).lower()
if verify == 'false':
app.config['ASK_VERIFY_REQUESTS'] = False
app.run(debug=DEBUG, host="0.0.0.0")
# vim: ts=4 expandtab