aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/main.py b/main.py
index 0fca35e..489a2f6 100644
--- a/main.py
+++ b/main.py
@@ -1,5 +1,6 @@
from evdev import InputDevice, list_devices, ecodes
from urllib.request import urlopen
+from urllib.error import HTTPError, URLError
SCANCODES = {0x11A: "up", 0x148: "down", 0x147: "left", 0x107: "right", 0x106: "ok", 0x141: "play/pause", 0x11c: "power", 0x103: "vol+", 0x142: "vol-"}
@@ -7,8 +8,19 @@ device = None
last = 0x00
def homelab_request(request: str):
- with urlopen(f"http://192.168.1.96/automate/{request}") as resp:
- print(f"homelab request {request} response {resp.status}")
+ url = f"http://192.168.1.96/automate/{request}"
+
+ try:
+ with urlopen(url, timeout=5) as resp:
+ print(f"homelab request {request} response {resp.status}")
+ print(resp.read().decode())
+
+ except HTTPError as e:
+ print(f"homelab request {request} response {e.code}")
+ print(e.read().decode())
+
+ except URLError as e:
+ print(f"homelab request failed: {e.reason}")
def do_action(action: str):
if action == "ok":