fixed some bugs with canaan miners not responding properly and returning empty bytes

This commit is contained in:
UpstreamData
2022-01-08 14:33:05 -07:00
parent 2734caa9da
commit d8bccbccaa
2 changed files with 75 additions and 66 deletions

View File

@@ -192,10 +192,12 @@ async def get_formatted_data(ip: ipaddress.ip_address):
try:
miner_data = await miner.api.multicommand("summary", "devs", "temps", "tunerstatus", "pools", "stats")
except APIError:
return {'TH/s': "Unknown", 'IP': str(miner.ip), 'host': "Unknown", 'user': "Unknown", 'wattage': 0}
return {'TH/s': 0, 'IP': str(miner.ip), 'model': 'Unknown', 'temp': 0, 'host': 'Unknown', 'user': 'Unknown', 'wattage': 0}
host = await miner.get_hostname()
model = await miner.get_model()
temps = 0
if miner_data:
if "summary" in miner_data.keys():
if "Temperature" in miner_data['summary'][0]['SUMMARY'][0].keys():
if not round(miner_data['summary'][0]['SUMMARY'][0]["Temperature"]) == 0:
@@ -243,6 +245,12 @@ async def get_formatted_data(ip: ipaddress.ip_address):
wattage = await safe_parse_api_data(miner_data, "summary", 0, 'SUMMARY', 0, "Power")
else:
wattage = 0
else:
th5s = 0
user = "Unknown"
wattage = 0
if not model:
model = "Error"
return {'TH/s': th5s, 'IP': str(miner.ip), 'model': model,
'temp': round(temps), 'host': host, 'user': user,
'wattage': wattage}

View File

@@ -106,6 +106,7 @@ class MinerFactory:
model = None
try:
data = await self._send_api_command(str(ip), "devdetails")
if data:
if data.get("STATUS"):
if not isinstance(data["STATUS"], str):
if data["STATUS"][0].get("STATUS") not in ["I", "S"]:
@@ -176,12 +177,11 @@ class MinerFactory:
# fix an error with a bmminer return not having a specific comma that breaks json.loads()
str_data = str_data.replace("}{", "},{")
# parse the json
parsed_data = json.loads(str_data)
data = json.loads(str_data)
# handle bad json
except json.decoder.JSONDecodeError as e:
print(e)
raise APIError(f"Decode Error: {data}")
data = parsed_data
# raise APIError(f"Decode Error: {data}")
data = None
# close the connection
writer.close()
@@ -195,6 +195,7 @@ class MinerFactory:
api = None
try:
data = await self._send_api_command(str(ip), "version")
if data:
if data.get("STATUS") and not data.get("STATUS") == "E":
if data["STATUS"][0].get("STATUS") in ["I", "S"]:
if any("BMMiner" in string for string in data["VERSION"][0].keys()):