From c657df80900e3f50d67f0a6150187e8db8573ebb Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Tue, 21 May 2024 21:15:55 +0100 Subject: [PATCH] Button reliability and web request timeouts --- api.py | 4 ++-- app.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api.py b/api.py index 98f819b..9352422 100644 --- a/api.py +++ b/api.py @@ -11,7 +11,7 @@ def getReq(endpoint) -> dict: } print("GET " + endpoint) try: - response = get(HASS_URL + endpoint, headers=headers) + response = get(HASS_URL + endpoint, headers=headers, timeout=2) return response.json() except: return {} @@ -24,7 +24,7 @@ def postReq(endpoint, d) -> bool: } print("POST " + endpoint) try: - response = post(HASS_URL + endpoint, headers=headers, json=d) + response = post(HASS_URL + endpoint, headers=headers, json=d, timeout=2) return response.status_code == 200 except: return False diff --git a/app.py b/app.py index 9a01126..f7ce8a7 100644 --- a/app.py +++ b/app.py @@ -118,13 +118,12 @@ class App: keyX = self.lcd.keyX["v"] keyY = self.lcd.keyY["v"] self.__resetButtonStatuses() + a = up or down or left or right or keyA or keyB or keyX or keyY or ctrl + if (a): self.last_cng = time() if (o): c = self.s.handleButtons(up, down, left, right, keyA, keyB, keyX, keyY, ctrl) - if (c): self.last_cng = time() return c - c = up or down or left or right or keyA or keyB or keyX or keyY or ctrl - if (c): self.last_cng = time() - return c + return a def __manageScreen(self) -> None: started = False @@ -171,6 +170,7 @@ class App: else: self.must_draw = self.s.update(self.lcd) else: + sleep(0.2) if (self.handleButtons(False)): LCD.setDuty() active = True