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)
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

8
app.py
View File

@@ -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