fixed some bugs with canaan miners not responding properly and returning empty bytes
This commit is contained in:
@@ -192,10 +192,12 @@ async def get_formatted_data(ip: ipaddress.ip_address):
|
|||||||
try:
|
try:
|
||||||
miner_data = await miner.api.multicommand("summary", "devs", "temps", "tunerstatus", "pools", "stats")
|
miner_data = await miner.api.multicommand("summary", "devs", "temps", "tunerstatus", "pools", "stats")
|
||||||
except APIError:
|
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()
|
host = await miner.get_hostname()
|
||||||
model = await miner.get_model()
|
model = await miner.get_model()
|
||||||
temps = 0
|
temps = 0
|
||||||
|
if miner_data:
|
||||||
if "summary" in miner_data.keys():
|
if "summary" in miner_data.keys():
|
||||||
if "Temperature" in miner_data['summary'][0]['SUMMARY'][0].keys():
|
if "Temperature" in miner_data['summary'][0]['SUMMARY'][0].keys():
|
||||||
if not round(miner_data['summary'][0]['SUMMARY'][0]["Temperature"]) == 0:
|
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")
|
wattage = await safe_parse_api_data(miner_data, "summary", 0, 'SUMMARY', 0, "Power")
|
||||||
else:
|
else:
|
||||||
wattage = 0
|
wattage = 0
|
||||||
|
else:
|
||||||
|
th5s = 0
|
||||||
|
user = "Unknown"
|
||||||
|
wattage = 0
|
||||||
|
if not model:
|
||||||
|
model = "Error"
|
||||||
return {'TH/s': th5s, 'IP': str(miner.ip), 'model': model,
|
return {'TH/s': th5s, 'IP': str(miner.ip), 'model': model,
|
||||||
'temp': round(temps), 'host': host, 'user': user,
|
'temp': round(temps), 'host': host, 'user': user,
|
||||||
'wattage': wattage}
|
'wattage': wattage}
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ class MinerFactory:
|
|||||||
model = None
|
model = None
|
||||||
try:
|
try:
|
||||||
data = await self._send_api_command(str(ip), "devdetails")
|
data = await self._send_api_command(str(ip), "devdetails")
|
||||||
|
if data:
|
||||||
if data.get("STATUS"):
|
if data.get("STATUS"):
|
||||||
if not isinstance(data["STATUS"], str):
|
if not isinstance(data["STATUS"], str):
|
||||||
if data["STATUS"][0].get("STATUS") not in ["I", "S"]:
|
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()
|
# fix an error with a bmminer return not having a specific comma that breaks json.loads()
|
||||||
str_data = str_data.replace("}{", "},{")
|
str_data = str_data.replace("}{", "},{")
|
||||||
# parse the json
|
# parse the json
|
||||||
parsed_data = json.loads(str_data)
|
data = json.loads(str_data)
|
||||||
# handle bad json
|
# handle bad json
|
||||||
except json.decoder.JSONDecodeError as e:
|
except json.decoder.JSONDecodeError as e:
|
||||||
print(e)
|
# raise APIError(f"Decode Error: {data}")
|
||||||
raise APIError(f"Decode Error: {data}")
|
data = None
|
||||||
data = parsed_data
|
|
||||||
|
|
||||||
# close the connection
|
# close the connection
|
||||||
writer.close()
|
writer.close()
|
||||||
@@ -195,6 +195,7 @@ class MinerFactory:
|
|||||||
api = None
|
api = None
|
||||||
try:
|
try:
|
||||||
data = await self._send_api_command(str(ip), "version")
|
data = await self._send_api_command(str(ip), "version")
|
||||||
|
if data:
|
||||||
if data.get("STATUS") and not data.get("STATUS") == "E":
|
if data.get("STATUS") and not data.get("STATUS") == "E":
|
||||||
if data["STATUS"][0].get("STATUS") in ["I", "S"]:
|
if data["STATUS"][0].get("STATUS") in ["I", "S"]:
|
||||||
if any("BMMiner" in string for string in data["VERSION"][0].keys()):
|
if any("BMMiner" in string for string in data["VERSION"][0].keys()):
|
||||||
|
|||||||
Reference in New Issue
Block a user