소스 검색

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

master
Dirk Alders 10 달 전
부모
커밋
6388afa835
1개의 변경된 파일13개의 추가작업 그리고 11개의 파일을 삭제
  1. 13
    11
      bt-audioparser/bt-audioparser.py

+ 13
- 11
bt-audioparser/bt-audioparser.py 파일 보기

@@ -50,17 +50,19 @@ def on_property_changed(interface, changed, invalidated):
50 50
 
51 51
 
52 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 67
 if __name__ == "__main__":
66 68
     report.stdoutLoggingConfigure(((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter)

Loading…
취소
저장