fix some bugs and start adding bmminer get_data function

This commit is contained in:
UpstreamData
2022-05-05 10:52:18 -06:00
parent e6ea8d3e16
commit a13f5dd2d1
3 changed files with 31 additions and 7 deletions

View File

@@ -44,6 +44,8 @@ class BMMiner(BaseMiner):
:return: The hostname of the miner as a string or "?"
"""
if self.hostname:
return self.hostname
try:
# open an ssh connection
async with (await self._get_ssh_connection()) as conn:
@@ -55,7 +57,8 @@ class BMMiner(BaseMiner):
# return hostname data
logging.debug(f"Found hostname for {self.ip}: {host}")
return host
self.hostname = host
return self.hostname
else:
# return ? if we fail to get hostname with no ssh connection
logging.warning(f"Failed to get hostname for miner: {self}")
@@ -114,3 +117,23 @@ class BMMiner(BaseMiner):
logging.debug(f"{self}: Sending reboot command.")
await self.send_ssh_command("reboot")
logging.debug(f"{self}: Reboot command completed.")
async def get_data(self):
data = {
"IP": str(self.ip),
"Model": "Unknown",
"Hostname": "Unknown",
"Hashrate": 0,
"Temperature": 0,
"Pool User": "Unknown",
"Wattage": 0,
"Split": 0,
"Pool 1": "Unknown",
"Pool 1 User": "Unknown",
"Pool 2": "",
"Pool 2 User": "",
}
data = await self.api.multicommand(
"summary", "devs", "temps", "tunerstatus", "pools", "stats"
)
print(data)

View File

@@ -313,7 +313,7 @@ class BOSMiner(BaseMiner):
data["Pool 2 User"] = pool_2_user
if quota:
data["Quota"] = quota
data["Split"] = quota
if tunerstatus:
tuner = tunerstatus.get("TUNERSTATUS")

View File

@@ -214,13 +214,11 @@ class MinerFactory:
version = data["version"][0]
except APIError as e:
logging.warning(f"{ip}: API Command Error: {e}")
data = None
if not data:
try:
devdetails = await self._send_api_command(str(ip), "devdetails")
validation = await self._validate_command(devdetails)
if not validation[0]:
version = await self._send_api_command(str(ip), "version")
@@ -260,11 +258,14 @@ class MinerFactory:
# if all that fails, check the Description to see if it is a whatsminer
elif version.get("Description") and "whatsminer" in version.get("Description"):
api = "BTMiner"
if version and not model:
if "VERSION" in version.keys() and not version["DEVDETAILS"] == []:
if (
"VERSION" in version.keys()
and version.get("VERSION")
and not version.get("VERSION") == []
):
model = version["VERSION"][0]["Type"]
print("done")
return model, api
async def _validate_command(self, data: dict) -> tuple: