浏览代码

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

正在加载...
取消
保存