Browse Source

Exception handling for BT-Player control, if no player available

master
Dirk Alders 10 months ago
parent
commit
6388afa835
1 changed files with 13 additions and 11 deletions
  1. 13
    11
      bt-audioparser/bt-audioparser.py

+ 13
- 11
bt-audioparser/bt-audioparser.py View File

50
 
50
 
51
 
51
 
52
 def on_mqtt_ctrl(client, userdata, message):
52
 def on_mqtt_ctrl(client, userdata, message):
53
-    if message.topic == config.MQTT_TOPIC + "/PLAY":
54
-        player_iface.Play()
55
-    elif message.topic == config.MQTT_TOPIC + "/PAUSE":
56
-        player_iface.Pause()
57
-    elif message.topic == config.MQTT_TOPIC + "/TRACK_PREV":
58
-        player_iface.Previous()
59
-    elif message.topic == config.MQTT_TOPIC + "/TRACK_NEXT":
60
-        player_iface.Next()
61
-    else:
62
-        logger.info(message.topic)
63
-
53
+    try:
54
+        if message.topic == config.MQTT_TOPIC + "/PLAY":
55
+            player_iface.Play()
56
+        elif message.topic == config.MQTT_TOPIC + "/PAUSE":
57
+            player_iface.Pause()
58
+        elif message.topic == config.MQTT_TOPIC + "/TRACK_PREV":
59
+            player_iface.Previous()
60
+        elif message.topic == config.MQTT_TOPIC + "/TRACK_NEXT":
61
+            player_iface.Next()
62
+        else:
63
+            logger.info(message.topic)
64
+    except AttributeError:
65
+        logger.warning("Player control impossible due to no player available.")
64
 
66
 
65
 if __name__ == "__main__":
67
 if __name__ == "__main__":
66
     report.stdoutLoggingConfigure(((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter)
68
     report.stdoutLoggingConfigure(((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter)

Loading…
Cancel
Save