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/
|
.env/
|
||||||
bin/
|
bin/
|
||||||
lib/
|
lib/
|
||||||
|
.idea/
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import ipaddress
|
|||||||
import warnings
|
import warnings
|
||||||
import logging
|
import logging
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
import re
|
||||||
|
|
||||||
from pyasic.errors import APIError, APIWarning
|
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("}"):
|
if not str_data.endswith("}"):
|
||||||
str_data = ",".join(str_data.split(",")[:-1]) + "}"
|
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
|
# parse the json
|
||||||
try:
|
try:
|
||||||
parsed_data = json.loads(str_data)
|
parsed_data = json.loads(str_data)
|
||||||
|
|||||||
@@ -768,3 +768,17 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
</details>
|
</details>
|
||||||
"""
|
"""
|
||||||
return await self.send_command("get_miner_info")
|
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]:
|
async def get_errors(self) -> List[MinerErrorData]:
|
||||||
data = []
|
data = []
|
||||||
|
try:
|
||||||
summary_data = await self.api.summary()
|
err_data = await self.api.get_error_code()
|
||||||
if summary_data[0].get("Error Code Count"):
|
if err_data:
|
||||||
for i in range(summary_data[0]["Error Code Count"]):
|
if err_data.get("Msg"):
|
||||||
if summary_data[0].get(f"Error Code {i}"):
|
if err_data["Msg"].get("error_code"):
|
||||||
if not summary_data[0][f"Error Code {i}"] == "":
|
for err in err_data["Msg"]["error_code"]:
|
||||||
data.append(
|
if isinstance(err, dict):
|
||||||
WhatsminerError(
|
for code in err:
|
||||||
error_code=summary_data[0][f"Error Code {i}"]
|
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
|
return data
|
||||||
|
|
||||||
async def reboot(self) -> bool:
|
async def reboot(self) -> bool:
|
||||||
@@ -278,6 +298,10 @@ class BTMiner(BaseMiner):
|
|||||||
psu_data = await self.api.get_psu()
|
psu_data = await self.api.get_psu()
|
||||||
except APIError:
|
except APIError:
|
||||||
psu_data = None
|
psu_data = None
|
||||||
|
try:
|
||||||
|
err_data = await self.api.get_error_code()
|
||||||
|
except APIError:
|
||||||
|
err_data = None
|
||||||
|
|
||||||
if summary:
|
if summary:
|
||||||
summary_data = summary.get("SUMMARY")
|
summary_data = summary.get("SUMMARY")
|
||||||
@@ -330,6 +354,24 @@ class BTMiner(BaseMiner):
|
|||||||
if psu.get("fan_speed"):
|
if psu.get("fan_speed"):
|
||||||
data.fan_psu = psu["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:
|
if devs:
|
||||||
temp_data = devs.get("DEVS")
|
temp_data = devs.get("DEVS")
|
||||||
if temp_data:
|
if temp_data:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "pyasic"
|
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."
|
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>"]
|
authors = ["UpstreamData <brett@upstreamdata.ca>"]
|
||||||
repository = "https://github.com/UpstreamData/pyasic"
|
repository = "https://github.com/UpstreamData/pyasic"
|
||||||
|
|||||||
Reference in New Issue
Block a user