Button reliability and web request timeouts

This commit is contained in:
2024-05-21 21:15:55 +01:00
parent f5c6e9e0aa
commit c657df8090
2 changed files with 6 additions and 6 deletions

4
api.py
View File

@@ -11,7 +11,7 @@ def getReq(endpoint) -> dict:
} }
print("GET " + endpoint) print("GET " + endpoint)
try: try:
response = get(HASS_URL + endpoint, headers=headers) response = get(HASS_URL + endpoint, headers=headers, timeout=2)
return response.json() return response.json()
except: except:
return {} return {}
@@ -24,7 +24,7 @@ def postReq(endpoint, d) -> bool:
} }
print("POST " + endpoint) print("POST " + endpoint)
try: 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 return response.status_code == 200
except: except:
return False return False

8
app.py
View File

@@ -118,13 +118,12 @@ class App:
keyX = self.lcd.keyX["v"] keyX = self.lcd.keyX["v"]
keyY = self.lcd.keyY["v"] keyY = self.lcd.keyY["v"]
self.__resetButtonStatuses() 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): if (o):
c = self.s.handleButtons(up, down, left, right, keyA, keyB, keyX, keyY, ctrl) c = self.s.handleButtons(up, down, left, right, keyA, keyB, keyX, keyY, ctrl)
if (c): self.last_cng = time()
return c return c
c = up or down or left or right or keyA or keyB or keyX or keyY or ctrl return a
if (c): self.last_cng = time()
return c
def __manageScreen(self) -> None: def __manageScreen(self) -> None:
started = False started = False
@@ -171,6 +170,7 @@ class App:
else: else:
self.must_draw = self.s.update(self.lcd) self.must_draw = self.s.update(self.lcd)
else: else:
sleep(0.2)
if (self.handleButtons(False)): if (self.handleButtons(False)):
LCD.setDuty() LCD.setDuty()
active = True active = True