Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1587f65196 | ||
|
|
5ff10c0cdd | ||
|
|
aa0a028564 | ||
|
|
82f6d2f274 | ||
|
|
833de3ab43 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ pyvenv.cfg
|
||||
.env/
|
||||
bin/
|
||||
lib/
|
||||
.idea/
|
||||
|
||||
@@ -18,6 +18,7 @@ import ipaddress
|
||||
import warnings
|
||||
import logging
|
||||
from typing import Union
|
||||
import re
|
||||
|
||||
from pyasic.errors import APIError, APIWarning
|
||||
|
||||
@@ -223,6 +224,10 @@ If you are sure you want to use this command please use API.send_command("{comma
|
||||
if not str_data.endswith("}"):
|
||||
str_data = ",".join(str_data.split(",")[:-1]) + "}"
|
||||
|
||||
# fix a really nasty bug with whatsminer API v2.0.4 where they return a list structured like a dict
|
||||
if re.search(r"\"error_code\":\[\".+\"\]", str_data):
|
||||
str_data = str_data.replace("[", "{").replace("]", "}")
|
||||
|
||||
# parse the json
|
||||
try:
|
||||
parsed_data = json.loads(str_data)
|
||||
|
||||
@@ -768,3 +768,17 @@ class BTMinerAPI(BaseMinerAPI):
|
||||
</details>
|
||||
"""
|
||||
return await self.send_command("get_miner_info")
|
||||
|
||||
async def get_error_code(self) -> dict:
|
||||
"""Get a list of error codes from the miner.
|
||||
|
||||
<details>
|
||||
<summary>Expand</summary>
|
||||
Get a list of error codes from the miner. Replaced `summary` as the location of error codes with API version 2.0.4.
|
||||
|
||||
Returns:
|
||||
|
||||
A list of error codes on the miner.
|
||||
</details>
|
||||
"""
|
||||
return await self.send_command("get_error_code")
|
||||
|
||||
@@ -158,17 +158,37 @@ class BTMiner(BaseMiner):
|
||||
|
||||
async def get_errors(self) -> List[MinerErrorData]:
|
||||
data = []
|
||||
|
||||
summary_data = await self.api.summary()
|
||||
if summary_data[0].get("Error Code Count"):
|
||||
for i in range(summary_data[0]["Error Code Count"]):
|
||||
if summary_data[0].get(f"Error Code {i}"):
|
||||
if not summary_data[0][f"Error Code {i}"] == "":
|
||||
data.append(
|
||||
WhatsminerError(
|
||||
error_code=summary_data[0][f"Error Code {i}"]
|
||||
try:
|
||||
err_data = await self.api.get_error_code()
|
||||
if err_data:
|
||||
if err_data.get("Msg"):
|
||||
if err_data["Msg"].get("error_code"):
|
||||
for err in err_data["Msg"]["error_code"]:
|
||||
if isinstance(err, dict):
|
||||
for code in err:
|
||||
data.append(
|
||||
WhatsminerError(
|
||||
error_code=int(code)
|
||||
)
|
||||
)
|
||||
else:
|
||||
data.append(
|
||||
WhatsminerError(
|
||||
error_code=int(err)
|
||||
)
|
||||
)
|
||||
except APIError:
|
||||
summary_data = await self.api.summary()
|
||||
if summary_data[0].get("Error Code Count"):
|
||||
for i in range(summary_data[0]["Error Code Count"]):
|
||||
if summary_data[0].get(f"Error Code {i}"):
|
||||
if not summary_data[0][f"Error Code {i}"] == "":
|
||||
data.append(
|
||||
WhatsminerError(
|
||||
error_code=summary_data[0][f"Error Code {i}"]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
async def reboot(self) -> bool:
|
||||
@@ -278,6 +298,10 @@ class BTMiner(BaseMiner):
|
||||
psu_data = await self.api.get_psu()
|
||||
except APIError:
|
||||
psu_data = None
|
||||
try:
|
||||
err_data = await self.api.get_error_code()
|
||||
except APIError:
|
||||
err_data = None
|
||||
|
||||
if summary:
|
||||
summary_data = summary.get("SUMMARY")
|
||||
@@ -330,6 +354,24 @@ class BTMiner(BaseMiner):
|
||||
if psu.get("fan_speed"):
|
||||
data.fan_psu = psu["fan_speed"]
|
||||
|
||||
if err_data:
|
||||
if err_data.get("Msg"):
|
||||
if err_data["Msg"].get("error_code"):
|
||||
for err in err_data["Msg"]["error_code"]:
|
||||
if isinstance(err, dict):
|
||||
for code in err:
|
||||
data.errors.append(
|
||||
WhatsminerError(
|
||||
error_code=int(code)
|
||||
)
|
||||
)
|
||||
else:
|
||||
data.errors.append(
|
||||
WhatsminerError(
|
||||
error_code=int(err)
|
||||
)
|
||||
)
|
||||
|
||||
if devs:
|
||||
temp_data = devs.get("DEVS")
|
||||
if temp_data:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "pyasic"
|
||||
version = "0.18.6"
|
||||
version = "0.19.1"
|
||||
description = "A set of modules for interfacing with many common types of ASIC bitcoin miners, using both their API and SSH."
|
||||
authors = ["UpstreamData <brett@upstreamdata.ca>"]
|
||||
repository = "https://github.com/UpstreamData/pyasic"
|
||||
|
||||
Reference in New Issue
Block a user