瀏覽代碼

amplifier: Exception handling for missing connection

84582af
Dirk Alders 4 年之前
父節點
當前提交
5dfda18440
共有 1 個檔案被更改,包括 7 行新增4 行删除
  1. 7
    4
      amplifier

+ 7
- 4
amplifier 查看文件

@@ -1,6 +1,7 @@
1 1
 #!/usr/bin/env python2
2 2
 import subprocess
3 3
 import time
4
+from requests.exceptions import ConnectionError
4 5
 from kodijson import Kodi	# sudo pip install kodi-json
5 6
 
6 7
 def monitor_state():
@@ -9,10 +10,12 @@ def monitor_state():
9 10
 
10 11
 
11 12
 def kodi_state():
12
-    kodi = Kodi("http://tv:8080/jsonrpc")
13
-    ap = kodi.Player.GetActivePlayers()
14
-    print(ap)
15
-    return len(ap['result']) > 0
13
+        try:
14
+            kodi = Kodi("http://tv:8080/jsonrpc")
15
+            ap = kodi.Player.GetActivePlayers()
16
+            return len(ap['result']) > 0
17
+        except ConnectionError:             # This is a dirty trick, if kodi is not yet ready to answer requests
18
+            return False
16 19
 
17 20
 
18 21
 prev_state = None

Loading…
取消
儲存