Compare commits

...

5 Commits

Author SHA1 Message Date
Upstream Data
2d057ca9f6 version: bump version number. 2023-02-11 19:45:03 -07:00
Upstream Data
b71b23d2a0 bug: add a check for power_on in reboot check. 2023-02-11 19:44:26 -07:00
UpstreamData
b32649435d version: bump version number. 2023-02-09 15:48:49 -07:00
UpstreamData
c0096126df bug: Reverse check for whatsminer fault light as it was backwards. 2023-02-09 15:47:11 -07:00
UpstreamData
d632360932 version: bump version number. 2023-02-09 10:37:19 -07:00
3 changed files with 50 additions and 48 deletions

View File

@@ -245,13 +245,13 @@ class BTMinerAPI(BaseMinerAPI):
try: try:
data = await self._send_bytes(enc_command, timeout) data = await self._send_bytes(enc_command, timeout)
except (asyncio.CancelledError, asyncio.TimeoutError) as e: except (asyncio.CancelledError, asyncio.TimeoutError) as e:
if command["cmd"] in ["reboot", "restart"]: if command["cmd"] in ["reboot", "restart", "power_on"]:
logging.info( logging.info(
f"{self} - (reboot/restart) - Whatsminers currently break this. " f"{self} - (reboot/restart/power_on) - Whatsminers currently break this. "
f"Ignoring exception. Command probably worked." f"Ignoring exception. Command probably worked."
) )
# FAKING IT HERE # FAKING IT HERE
data = b'{"STATUS": "S", "When": 1670966423, "Code": 131, "Msg": "API command OK", "Description": "Reboot"}' data = b'{"STATUS": "S", "When": 1670966423, "Code": 131, "Msg": "API command OK", "Description": "Reboot/restart/power_on"}'
else: else:
raise APIError("No data was returned from the API.") raise APIError("No data was returned from the API.")

View File

@@ -172,17 +172,17 @@ class BTMiner(BaseMiner):
################################################## ##################################################
async def get_mac( async def get_mac(
self, api_summary: dict = None, api_miner_info: dict = None self, api_summary: dict = None, api_get_miner_info: dict = None
) -> Optional[str]: ) -> Optional[str]:
if not api_miner_info: if not api_get_miner_info:
try: try:
api_miner_info = await self.api.get_miner_info() api_get_miner_info = await self.api.get_miner_info()
except APIError: except APIError:
pass pass
if api_miner_info: if api_get_miner_info:
try: try:
mac = api_miner_info["Msg"]["mac"] mac = api_get_miner_info["Msg"]["mac"]
return str(mac).upper() return str(mac).upper()
except KeyError: except KeyError:
pass pass
@@ -223,29 +223,31 @@ class BTMiner(BaseMiner):
return None return None
async def get_version( async def get_version(
self, api_version: dict = None, api_summary: dict = None self, api_get_version: dict = None, api_summary: dict = None
) -> Tuple[Optional[str], Optional[str]]: ) -> Tuple[Optional[str], Optional[str]]:
miner_version = namedtuple("MinerVersion", "api_ver fw_ver") miner_version = namedtuple("MinerVersion", "api_ver fw_ver")
api_ver = await self.get_api_ver(api_version=api_version) api_ver = await self.get_api_ver(api_get_version=api_get_version)
fw_ver = await self.get_fw_ver(api_version=api_version, api_summary=api_summary) fw_ver = await self.get_fw_ver(
api_get_version=api_get_version, api_summary=api_summary
)
return miner_version(api_ver, fw_ver) return miner_version(api_ver, fw_ver)
async def get_api_ver(self, api_version: dict = None) -> Optional[str]: async def get_api_ver(self, api_get_version: dict = None) -> Optional[str]:
# Check to see if the version info is already cached # Check to see if the version info is already cached
if self.api_ver: if self.api_ver:
return self.api_ver return self.api_ver
if not api_version: if not api_get_version:
try: try:
api_version = await self.api.get_version() api_get_version = await self.api.get_version()
except APIError: except APIError:
pass pass
if api_version: if api_get_version:
if "Code" in api_version.keys(): if "Code" in api_get_version.keys():
if api_version["Code"] == 131: if api_get_version["Code"] == 131:
try: try:
api_ver = api_version["Msg"] api_ver = api_get_version["Msg"]
if not isinstance(api_ver, str): if not isinstance(api_ver, str):
api_ver = api_ver["api_ver"] api_ver = api_ver["api_ver"]
self.api_ver = api_ver.replace("whatsminer v", "") self.api_ver = api_ver.replace("whatsminer v", "")
@@ -258,23 +260,23 @@ class BTMiner(BaseMiner):
return self.api_ver return self.api_ver
async def get_fw_ver( async def get_fw_ver(
self, api_version: dict = None, api_summary: dict = None self, api_get_version: dict = None, api_summary: dict = None
) -> Optional[str]: ) -> Optional[str]:
# Check to see if the version info is already cached # Check to see if the version info is already cached
if self.fw_ver: if self.fw_ver:
return self.fw_ver return self.fw_ver
if not api_version: if not api_get_version:
try: try:
api_version = await self.api.get_version() api_get_version = await self.api.get_version()
except APIError: except APIError:
pass pass
if api_version: if api_get_version:
if "Code" in api_version.keys(): if "Code" in api_get_version.keys():
if api_version["Code"] == 131: if api_get_version["Code"] == 131:
try: try:
self.fw_ver = api_version["Msg"]["fw_ver"] self.fw_ver = api_get_version["Msg"]["fw_ver"]
except (KeyError, TypeError): except (KeyError, TypeError):
pass pass
else: else:
@@ -296,19 +298,19 @@ class BTMiner(BaseMiner):
return self.fw_ver return self.fw_ver
async def get_hostname(self, api_miner_info: dict = None) -> Optional[str]: async def get_hostname(self, api_get_miner_info: dict = None) -> Optional[str]:
if self.hostname: if self.hostname:
return self.hostname return self.hostname
if not api_miner_info: if not api_get_miner_info:
try: try:
api_miner_info = await self.api.get_miner_info() api_get_miner_info = await self.api.get_miner_info()
except APIError: except APIError:
return None # only one way to get this return None # only one way to get this
if api_miner_info: if api_get_miner_info:
try: try:
self.hostname = api_miner_info["Msg"]["hostname"] self.hostname = api_get_miner_info["Msg"]["hostname"]
except KeyError: except KeyError:
return None return None
@@ -403,7 +405,7 @@ class BTMiner(BaseMiner):
pass pass
async def get_fans( async def get_fans(
self, api_summary: dict = None, api_psu: dict = None self, api_summary: dict = None, api_get_psu: dict = None
) -> List[Fan]: ) -> List[Fan]:
if not api_summary: if not api_summary:
try: try:
@@ -427,7 +429,7 @@ class BTMiner(BaseMiner):
return fans return fans
async def get_fan_psu( async def get_fan_psu(
self, api_summary: dict = None, api_psu: dict = None self, api_summary: dict = None, api_get_psu: dict = None
) -> Optional[int]: ) -> Optional[int]:
if not api_summary: if not api_summary:
try: try:
@@ -441,15 +443,15 @@ class BTMiner(BaseMiner):
except (KeyError, IndexError): except (KeyError, IndexError):
pass pass
if not api_psu: if not api_get_psu:
try: try:
api_psu = await self.api.get_psu() api_get_psu = await self.api.get_psu()
except APIError: except APIError:
pass pass
if api_psu: if api_get_psu:
try: try:
return int(api_psu["Msg"]["fan_speed"]) return int(api_get_psu["Msg"]["fan_speed"])
except (KeyError, TypeError): except (KeyError, TypeError):
pass pass
@@ -480,10 +482,10 @@ class BTMiner(BaseMiner):
return groups return groups
async def get_errors( async def get_errors(
self, api_summary: dict = None, api_error_codes: dict = None self, api_summary: dict = None, api_get_error_code: dict = None
) -> List[MinerErrorData]: ) -> List[MinerErrorData]:
errors = [] errors = []
if not api_summary and not api_error_codes: if not api_summary and not api_get_error_code:
try: try:
api_summary = await self.api.summary() api_summary = await self.api.summary()
except APIError: except APIError:
@@ -498,14 +500,14 @@ class BTMiner(BaseMiner):
except (KeyError, IndexError, ValueError, TypeError): except (KeyError, IndexError, ValueError, TypeError):
pass pass
if not api_error_codes: if not api_get_error_code:
try: try:
api_error_codes = await self.api.get_error_code() api_get_error_code = await self.api.get_error_code()
except APIError: except APIError:
pass pass
if api_error_codes: if api_get_error_code:
for err in api_error_codes["Msg"]["error_code"]: for err in api_get_error_code["Msg"]["error_code"]:
if isinstance(err, dict): if isinstance(err, dict):
for code in err: for code in err:
errors.append(WhatsminerError(error_code=int(code))) errors.append(WhatsminerError(error_code=int(code)))
@@ -529,19 +531,19 @@ class BTMiner(BaseMiner):
except (KeyError, IndexError): except (KeyError, IndexError):
pass pass
async def get_fault_light(self, api_miner_info: dict = None) -> bool: async def get_fault_light(self, api_get_miner_info: dict = None) -> bool:
data = None data = None
if not api_miner_info: if not api_get_miner_info:
try: try:
api_miner_info = await self.api.get_miner_info() api_get_miner_info = await self.api.get_miner_info()
except APIError: except APIError:
if not self.light: if not self.light:
self.light = False self.light = False
if api_miner_info: if api_get_miner_info:
try: try:
self.light = api_miner_info["Msg"]["ledstat"] == "auto" self.light = not (api_get_miner_info["Msg"]["ledstat"] == "auto")
except KeyError: except KeyError:
pass pass

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "pyasic" name = "pyasic"
version = "0.27.0" version = "0.27.3"
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"