feature: add retries to elphapex

This commit is contained in:
Brett Rowan
2025-08-16 10:06:46 -06:00
parent bce0058930
commit 1a8928de18

View File

@@ -120,18 +120,28 @@ class ElphapexWebAPI(BaseWebAPI):
""" """
auth = httpx.DigestAuth(self.username, self.pwd) auth = httpx.DigestAuth(self.username, self.pwd)
try: async def _send():
url = f"http://{self.ip}/cgi-bin/{command}.cgi" try:
ret = await client.get(url, auth=auth) url = f"http://{self.ip}/cgi-bin/{command}.cgi"
except httpx.HTTPError: ret = await client.get(url, auth=auth)
pass except httpx.HTTPError:
else: pass
if ret.status_code == 200: else:
try: if ret.status_code == 200:
json_data = ret.json() try:
return {command: json_data} json_data = ret.json()
except json.decoder.JSONDecodeError: if json_data.get("STATUS", {}).get("STATUS") not in ["S", "I"]:
pass return None
return {command: json_data}
except json.decoder.JSONDecodeError:
pass
return None
# retry 3 times
for i in range(3):
res = await _send()
if res is not None:
return res
return {command: {}} return {command: {}}
async def get_miner_conf(self) -> dict: async def get_miner_conf(self) -> dict: