Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Commit 1a8928d

Browse files
committed
feature: add retries to elphapex
1 parent bce0058 commit 1a8928d

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

pyasic/web/elphapex.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,28 @@ async def _handle_multicommand(
120120
"""
121121
auth = httpx.DigestAuth(self.username, self.pwd)
122122

123-
try:
124-
url = f"http://{self.ip}/cgi-bin/{command}.cgi"
125-
ret = await client.get(url, auth=auth)
126-
except httpx.HTTPError:
127-
pass
128-
else:
129-
if ret.status_code == 200:
130-
try:
131-
json_data = ret.json()
132-
return {command: json_data}
133-
except json.decoder.JSONDecodeError:
134-
pass
123+
async def _send():
124+
try:
125+
url = f"http://{self.ip}/cgi-bin/{command}.cgi"
126+
ret = await client.get(url, auth=auth)
127+
except httpx.HTTPError:
128+
pass
129+
else:
130+
if ret.status_code == 200:
131+
try:
132+
json_data = ret.json()
133+
if json_data.get("STATUS", {}).get("STATUS") not in ["S", "I"]:
134+
return None
135+
return {command: json_data}
136+
except json.decoder.JSONDecodeError:
137+
pass
138+
return None
139+
140+
# retry 3 times
141+
for i in range(3):
142+
res = await _send()
143+
if res is not None:
144+
return res
135145
return {command: {}}
136146

137147
async def get_miner_conf(self) -> dict:

0 commit comments

Comments
 (0)