feature: add retries to elphapex
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user