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,6 +120,7 @@ class ElphapexWebAPI(BaseWebAPI):
"""
auth = httpx.DigestAuth(self.username, self.pwd)
async def _send():
try:
url = f"http://{self.ip}/cgi-bin/{command}.cgi"
ret = await client.get(url, auth=auth)
@@ -129,9 +130,18 @@ class ElphapexWebAPI(BaseWebAPI):
if ret.status_code == 200:
try:
json_data = ret.json()
if json_data.get("STATUS", {}).get("STATUS") not in ["S", "I"]:
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: {}}
async def get_miner_conf(self) -> dict: