fixed a bug with suspended whatsminers

This commit is contained in:
UpstreamData
2022-05-16 14:06:23 -06:00
parent 85e8ac63f1
commit e091863aa7
6 changed files with 50 additions and 24 deletions

View File

@@ -7,6 +7,7 @@ from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES
class BMMiner(BaseMiner):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
self.api = BMMinerAPI(ip)
self.api_type = "BMMiner"
self.uname = "root"

View File

@@ -10,6 +10,7 @@ import asyncssh
class BOSMiner(BaseMiner):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
self.api = BOSMinerAPI(ip)
self.api_type = "BOSMiner"
self.uname = "root"
@@ -379,7 +380,6 @@ class BOSMinerOld(BaseMiner):
self.uname = "root"
self.pwd = "admin"
async def send_ssh_command(self, cmd: str) -> str or None:
"""Send a command to the miner over ssh.
@@ -406,9 +406,6 @@ class BOSMinerOld(BaseMiner):
# return the result, either command output or None
return str(result)
async def update_to_plus(self):
result = await self.send_ssh_command("opkg update && opkg install bos_plus")
return result

View File

@@ -8,6 +8,7 @@ from settings import MINER_FACTORY_GET_VERSION_RETRIES as DATA_RETRIES
class BTMiner(BaseMiner):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
self.api = BTMinerAPI(ip)
self.api_type = "BTMiner"
@@ -93,8 +94,15 @@ class BTMiner(BaseMiner):
"Pool 2 User": "",
}
model = await self.get_model()
hostname = await self.get_hostname()
try:
model = await self.get_model()
hostname = await self.get_hostname()
except APIError:
logging.warning(f"Failed to get hostname and model: {self}")
model = None
data["Model"] = "Whatsminer"
hostname = None
data["Hostname"] = "Whatsminer"
if model:
data["Model"] = model
@@ -103,9 +111,12 @@ class BTMiner(BaseMiner):
data["Hostname"] = hostname
miner_data = None
for i in range(DATA_RETRIES):
miner_data = await self.api.multicommand("summary", "devs", "pools")
if miner_data:
break
try:
miner_data = await self.api.multicommand("summary", "devs", "pools")
if miner_data:
break
except APIError:
pass
if not miner_data:
return data

View File

@@ -8,6 +8,7 @@ import logging
class CGMiner(BaseMiner):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
self.api = CGMinerAPI(ip)
self.api_type = "CGMiner"
self.uname = "root"

View File

@@ -4,6 +4,7 @@ from miners._backends import BMMiner
class Hiveon(BMMiner):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
self.api_type = "Hiveon"
self.uname = "root"
self.pwd = "admin"

View File

@@ -5,6 +5,7 @@ from miners.avalonminer import *
from miners._backends.cgminer import CGMiner
from miners._backends.bmminer import BMMiner
from miners._backends.bosminer import BOSMiner
from miners._backends.btminer import BTMiner
from miners._backends.bosminer import BOSMinerOld
from miners.unknown import UnknownMiner
@@ -245,10 +246,13 @@ class MinerFactory(metaclass=Singleton):
if api:
if "BOSMiner+" in api:
miner = BOSMiner(str(ip))
if "BOSMiner" in api:
elif "BOSMiner" in api:
miner = BOSMinerOld(str(ip))
elif "CGMiner" in api:
miner = CGMiner(str(ip))
elif "BTMiner" in api:
miner = BTMiner(str(ip))
print(miner)
elif "BMMiner" in api:
miner = BMMiner(str(ip))
@@ -288,11 +292,15 @@ class MinerFactory(metaclass=Singleton):
devdetails = await self._send_api_command(str(ip), "devdetails")
validation = await self._validate_command(devdetails)
if not validation[0]:
devdetails = None
version = await self._send_api_command(str(ip), "version")
validation = await self._validate_command(version)
if not validation[0]:
raise APIError(validation[1])
version = await self._send_api_command(str(ip), "get_version")
validation = await self._validate_command(version)
if not validation[0]:
raise APIError(validation[1])
except APIError as e:
logging.warning(f"{ip}: API Command Error: {e}")
return None, None
@@ -313,22 +321,29 @@ class MinerFactory(metaclass=Singleton):
model = "Antminer S9"
if version:
# check if there are any BMMiner strings in any of the dict keys
if any("BMMiner" in string for string in version["VERSION"][0].keys()):
api = "BMMiner"
if "VERSION" in version.keys():
# check if there are any BMMiner strings in any of the dict keys
if any("BMMiner" in string for string in version["VERSION"][0].keys()):
api = "BMMiner"
# check if there are any CGMiner strings in any of the dict keys
elif any("CGMiner" in string for string in version["VERSION"][0].keys()):
api = "CGMiner"
# check if there are any CGMiner strings in any of the dict keys
elif any(
"CGMiner" in string for string in version["VERSION"][0].keys()
):
api = "CGMiner"
# check if there are any BOSMiner strings in any of the dict keys
elif any("BOSminer" in string for string in version["VERSION"][0].keys()):
api = "BOSMiner"
if "plus" in version["VERSION"][0]["BOSminer"]:
api = "BOSMiner+"
# check if there are any BOSMiner strings in any of the dict keys
elif any(
"BOSminer" in string for string in version["VERSION"][0].keys()
):
api = "BOSMiner"
if "plus" in version["VERSION"][0]["BOSminer"]:
api = "BOSMiner+"
# if all that fails, check the Description to see if it is a whatsminer
if version.get("Description") and "whatsminer" in version.get("Description"):
if version.get("Description") and "whatsminer" in version.get(
"Description"
):
api = "BTMiner"
if version and not model:
if (