-
Notifications
You must be signed in to change notification settings - Fork 0
/
action-snips_TV.py
executable file
·79 lines (64 loc) · 2.81 KB
/
action-snips_TV.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from hermes_python.hermes import Hermes, MqttOptions
import paho.mqtt.client as mqtt
import json
MQTT_TOPIC = 'cmnd/sonoff/IRSend'
MQTT_BROKER_ADDRESS = 'localhost:1883'
MQTT_MSG = {}
MQTT_MSG['power_on_AMP'] = json.dumps({"Protocol": "NEC", "Bits": 32, "Data": "0x616E02FD"})
MQTT_MSG['0'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E08877"})
MQTT_MSG['1'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E020DF"})
MQTT_MSG['2'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E0A05F"})
MQTT_MSG['3'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E0609F"})
MQTT_MSG['4'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E010EF"})
MQTT_MSG['5'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E0906F"})
MQTT_MSG['6'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E050AF"})
MQTT_MSG['7'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E030CF"})
MQTT_MSG['8'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E0B04F"})
MQTT_MSG['9'] = json.dumps({"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E0708F"})
PROGRAM_KEY_MAP = {}
PROGRAM_KEY_MAP['daserste'] = [1]
PROGRAM_KEY_MAP['zdf'] = [2]
PROGRAM_KEY_MAP['arte'] = [3]
PROGRAM_KEY_MAP['sat1'] = [4]
PROGRAM_KEY_MAP['rtl'] = [5]
PROGRAM_KEY_MAP['rtl2'] = [6]
PROGRAM_KEY_MAP['pro7'] = [7]
PROGRAM_KEY_MAP['vox'] = [8]
PROGRAM_KEY_MAP['sixx'] = [9]
PROGRAM_KEY_MAP['tele5'] = [1,0]
PROGRAM_KEY_MAP['kabel1'] = [1,1]
PROGRAM_KEY_MAP['servustv'] = [1,2]
PROGRAM_KEY_MAP['pro7maxx'] = [1,3]
PROGRAM_KEY_MAP['one'] = [1,4]
PROGRAM_KEY_MAP['superrtl'] = [1,5]
PROGRAM_KEY_MAP['nitro'] = [1,6]
PROGRAM_KEY_MAP['sat1gold'] = [1,7]
PROGRAM_KEY_MAP['rtlplus'] = [1,8]
PROGRAM_KEY_MAP['rbb'] = [1,9]
PROGRAM_KEY_MAP['ndr'] = [2,0]
PROGRAM_KEY_MAP['hrfernsehen'] = [2,1]
PROGRAM_KEY_MAP['eurosport1'] = [3,6]
PROGRAM_KEY_MAP['ntv'] = [4,1]
PROGRAM_KEY_MAP['radio1'] = [6,5]
PROGRAM_KEY_MAP['cosmo'] = [1,0,7]
PROGRAM_KEY_MAP['jamfm'] = [1,2,0]
PROGRAM_KEY_MAP['fluxfm'] = [1,2,1]
PROGRAM_KEY_MAP['paradiso'] = [1,2,2]
def subscribe_intent_callback(hermes, intent_message):
intentname = intent_message.intent.intent_name
mqttc = mqtt.Client()
mqttc.connect('localhost', 1883)
if intentname == "sbogun:TV_on":
mqttc.publish(MQTT_TOPIC, payload = MQTT_MSG['power_on_AMP'])
elif intentname == "sbogun:TV_program":
station_name = intent_message.slots.station_name.first()
if station_name in PROGRAM_KEY_MAP.keys():
for i in PROGRAM_KEY_MAP[station_name]:
mqttc.publish(MQTT_TOPIC, payload = MQTT_MSG[str(i)])
mqttc.disconnect()
if __name__ == "__main__":
mqtt_opts = MqttOptions(broker_address=MQTT_BROKER_ADDRESS)
with Hermes(mqtt_options=mqtt_opts) as h:
h.subscribe_intents(subscribe_intent_callback).start()