-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_handlers.py
40 lines (36 loc) · 1.03 KB
/
message_handlers.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
"""! Handlers for various messages"""
import logging
def handle_message(topic, payload):
"""! Main entry point to the module """
if topic == "play":
play_audio(payload)
if topic == "config":
handle_config(payload)
def play_audio(payload):
"""! Handle the queueing up of audio """
from audio import audio # pylint: disable=import-outside-toplevel
try:
platform = payload['platform']
audio_type = payload['audio']
except KeyError:
# Invalid message
logging.debug("Invalid message: %s", payload)
return
left = False
right = False
if platform == 0:
# Play on both platforms
left = True
right = True
elif platform == 1:
# Just platform 1
left = True
elif platform == 2:
# Just platform 2
right = True
else:
# Invalid platform selection
return
audio.queue_audio(audio_type, left, right)
def handle_config(payload):
"""! Handle the changing of config"""