From 1a8928de1821563f4e08a18a7c2d40cbaacf33b4 Mon Sep 17 00:00:00 2001 From: Brett Rowan <121075405+b-rowan@users.noreply.github.com> Date: Sat, 16 Aug 2025 10:06:46 -0600 Subject: [PATCH] feature: add retries to elphapex --- pyasic/web/elphapex.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pyasic/web/elphapex.py b/pyasic/web/elphapex.py index b2f0204c..2f456c00 100644 --- a/pyasic/web/elphapex.py +++ b/pyasic/web/elphapex.py @@ -120,18 +120,28 @@ class ElphapexWebAPI(BaseWebAPI): """ auth = httpx.DigestAuth(self.username, self.pwd) - try: - url = f"http://{self.ip}/cgi-bin/{command}.cgi" - ret = await client.get(url, auth=auth) - except httpx.HTTPError: - pass - else: - if ret.status_code == 200: - try: - json_data = ret.json() - return {command: json_data} - except json.decoder.JSONDecodeError: - pass + async def _send(): + try: + url = f"http://{self.ip}/cgi-bin/{command}.cgi" + ret = await client.get(url, auth=auth) + except httpx.HTTPError: + pass + else: + 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: