fully implemented fault light command
This commit is contained in:
@@ -55,6 +55,12 @@ class BaseMiner:
|
||||
# logging.warning(f"{self} raised an exception: {e}")
|
||||
raise e
|
||||
|
||||
async def fault_light_on(self) -> bool:
|
||||
return False
|
||||
|
||||
async def fault_light_off(self) -> bool:
|
||||
return False
|
||||
|
||||
async def send_file(self, src, dest):
|
||||
async with (await self._get_ssh_connection()) as conn:
|
||||
await asyncssh.scp(src, (conn, dest))
|
||||
|
||||
@@ -42,21 +42,27 @@ class BOSMiner(BaseMiner):
|
||||
return
|
||||
continue
|
||||
# return the result, either command output or None
|
||||
return result
|
||||
return str(result)
|
||||
|
||||
async def fault_light_on(self) -> None:
|
||||
async def fault_light_on(self) -> bool:
|
||||
"""Sends command to turn on fault light on the miner."""
|
||||
logging.debug(f"{self}: Sending fault_light on command.")
|
||||
self.light = True
|
||||
await self.send_ssh_command("miner fault_light on")
|
||||
_ret = await self.send_ssh_command("miner fault_light on")
|
||||
logging.debug(f"{self}: fault_light on command completed.")
|
||||
if isinstance(_ret, str):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def fault_light_off(self) -> None:
|
||||
async def fault_light_off(self) -> bool:
|
||||
"""Sends command to turn off fault light on the miner."""
|
||||
logging.debug(f"{self}: Sending fault_light off command.")
|
||||
self.light = False
|
||||
await self.send_ssh_command("miner fault_light off")
|
||||
_ret = await self.send_ssh_command("miner fault_light off")
|
||||
logging.debug(f"{self}: fault_light off command completed.")
|
||||
if isinstance(_ret, str):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def restart_backend(self) -> None:
|
||||
await self.restart_bosminer()
|
||||
|
||||
@@ -77,8 +77,10 @@ class MinerFactory(metaclass=Singleton):
|
||||
for miner in scanned:
|
||||
yield await miner
|
||||
|
||||
async def get_miner(self, ip: ipaddress.ip_address):
|
||||
async def get_miner(self, ip: ipaddress.ip_address or str):
|
||||
"""Decide a miner type using the IP address of the miner."""
|
||||
if isinstance(ip, str):
|
||||
ip = ipaddress.ip_address(ip)
|
||||
# check if the miner already exists in cache
|
||||
if ip in self.miners:
|
||||
return self.miners[ip]
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
from miners.miner_factory import MinerFactory
|
||||
from tools.cfg_util.cfg_util_qt.layout import window
|
||||
from tools.cfg_util.cfg_util_qt.tables import update_tree
|
||||
from tools.cfg_util.cfg_util_qt.imgs import TkImages
|
||||
from tools.cfg_util.cfg_util_qt.tables import TableManager
|
||||
|
||||
|
||||
async def btn_light(ips: list):
|
||||
table_manager = TableManager()
|
||||
_table = window["cmd_table"].Widget
|
||||
data = []
|
||||
iids = _table.get_children()
|
||||
for idx in ips:
|
||||
item = _table.item(iids[idx])
|
||||
data.append(
|
||||
{
|
||||
"IP": item["values"][0],
|
||||
"Model": item["values"][1],
|
||||
"Command Output": item["values"][2],
|
||||
"Light": True,
|
||||
}
|
||||
)
|
||||
await update_tree(data)
|
||||
ip = item["values"][0]
|
||||
new_light_val = not table_manager.data[ip]["Light"]
|
||||
miner = await MinerFactory().get_miner(ip)
|
||||
if new_light_val:
|
||||
success = await miner.fault_light_on()
|
||||
else:
|
||||
success = await miner.fault_light_off()
|
||||
if success:
|
||||
table_manager.data[ip]["Light"] = new_light_val
|
||||
table_manager.data[ip]["Command Output"] = "Fault Light command succeeded."
|
||||
else:
|
||||
table_manager.data[ip]["Command Output"] = "Fault Light command failed."
|
||||
table_manager.update_tables()
|
||||
|
||||
@@ -36,8 +36,11 @@ async def btn_all():
|
||||
async def btn_scan(scan_ip: str):
|
||||
network = MinerNetwork("192.168.1.0")
|
||||
if scan_ip:
|
||||
if "/" in scan_ip:
|
||||
ip, mask = scan_ip.split("/")
|
||||
network = MinerNetwork(ip, mask=mask)
|
||||
else:
|
||||
network = MinerNetwork(scan_ip)
|
||||
asyncio.create_task(_scan_miners(network))
|
||||
|
||||
|
||||
@@ -74,8 +77,7 @@ async def _scan_miners(network: MinerNetwork):
|
||||
_data[key] = ""
|
||||
_data["IP"] = str(miner.ip)
|
||||
_data["Light"] = False
|
||||
resolved_miners_data.append(_data)
|
||||
update_tables(resolved_miners_data)
|
||||
update_tables([_data])
|
||||
progress_bar_len += 1
|
||||
await update_prog_bar(progress_bar_len)
|
||||
progress_bar_len += network_size - len(resolved_miners)
|
||||
|
||||
@@ -4,16 +4,9 @@ from tools.cfg_util.cfg_util_qt.layout import (
|
||||
TABLE_HEADERS,
|
||||
window,
|
||||
)
|
||||
from tools.cfg_util.cfg_util_qt.imgs import TkImages, LIGHT
|
||||
from tools.cfg_util.cfg_util_qt.imgs import TkImages, LIGHT, FAULT_LIGHT
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
||||
def clear_tables():
|
||||
for table in TABLE_KEYS["table"]:
|
||||
window[table].update([])
|
||||
for tree in TABLE_KEYS["tree"]:
|
||||
window[tree].update(sg.TreeData())
|
||||
update_miner_count(0)
|
||||
import ipaddress
|
||||
|
||||
|
||||
def update_miner_count(count):
|
||||
@@ -22,8 +15,11 @@ def update_miner_count(count):
|
||||
|
||||
|
||||
def update_tables(data: list or None = None):
|
||||
table_manager = TableManager()
|
||||
table_manager.update_tables(data)
|
||||
TableManager().update_data(data)
|
||||
|
||||
|
||||
def clear_tables():
|
||||
TableManager().clear_tables()
|
||||
|
||||
|
||||
async def update_tree(data: list):
|
||||
@@ -48,20 +44,41 @@ class TableManager(metaclass=Singleton):
|
||||
|
||||
def __init__(self):
|
||||
self.images = TkImages()
|
||||
self.data = []
|
||||
self.data = {}
|
||||
self.sort_key = "IP"
|
||||
|
||||
def update_tables(self, data: list or None = None):
|
||||
if not data or data == []:
|
||||
data = self.data
|
||||
self.data = data
|
||||
def update_data(self, data: list):
|
||||
if not data:
|
||||
return
|
||||
|
||||
for line in data:
|
||||
self.update_item(line)
|
||||
|
||||
def update_item(self, data: dict):
|
||||
if not data or data == {} or not data.get("IP"):
|
||||
return
|
||||
|
||||
if not data["IP"] in self.data.keys():
|
||||
self.data[data["IP"]] = {}
|
||||
|
||||
for key in data.keys():
|
||||
self.data[data["IP"]][key] = data[key]
|
||||
|
||||
self.update_tables()
|
||||
|
||||
def update_tables(self):
|
||||
tables = {
|
||||
"SCAN": [["" for _ in TABLE_HEADERS["SCAN"]] for _ in data],
|
||||
"CMD": [["" for _ in TABLE_HEADERS["CMD"]] for _ in data],
|
||||
"POOLS": [["" for _ in TABLE_HEADERS["POOLS"]] for _ in data],
|
||||
"CONFIG": [["" for _ in TABLE_HEADERS["CONFIG"]] for _ in data],
|
||||
"SCAN": [["" for _ in TABLE_HEADERS["SCAN"]] for _ in self.data],
|
||||
"CMD": [["" for _ in TABLE_HEADERS["CMD"]] for _ in self.data],
|
||||
"POOLS": [["" for _ in TABLE_HEADERS["POOLS"]] for _ in self.data],
|
||||
"CONFIG": [["" for _ in TABLE_HEADERS["CONFIG"]] for _ in self.data],
|
||||
}
|
||||
for data_idx, item in enumerate(data):
|
||||
for data_idx, key in enumerate(
|
||||
sorted(self.data.keys(), key=lambda x: self._get_sort(x))
|
||||
):
|
||||
item = self.data[key]
|
||||
keys = item.keys()
|
||||
|
||||
if "Hashrate" in keys:
|
||||
if not isinstance(item["Hashrate"], str):
|
||||
item[
|
||||
@@ -79,11 +96,31 @@ class TableManager(metaclass=Singleton):
|
||||
|
||||
treedata = sg.TreeData()
|
||||
for idx, item in enumerate(tables["CMD"]):
|
||||
treedata.insert("", idx, "", item, icon=LIGHT)
|
||||
ico = LIGHT
|
||||
if self.data[item[0]]["Light"]:
|
||||
ico = FAULT_LIGHT
|
||||
treedata.insert("", idx, "", item, icon=ico)
|
||||
|
||||
window["cmd_table"].update(treedata)
|
||||
|
||||
update_miner_count(len(data))
|
||||
update_miner_count(len(self.data))
|
||||
|
||||
def _get_sort(self, data_key: str):
|
||||
if self.sort_key == "IP":
|
||||
return ipaddress.ip_address(self.data[data_key]["IP"])
|
||||
|
||||
if self.sort_key == "Hashrate":
|
||||
return self.data[data_key]["Hashrate"].replace(" ", "").replace("TH/s", "")
|
||||
|
||||
return self.data[data_key][self.sort_key]
|
||||
|
||||
def clear_tables(self):
|
||||
self.data = {}
|
||||
for table in TABLE_KEYS["table"]:
|
||||
window[table].update([])
|
||||
for tree in TABLE_KEYS["tree"]:
|
||||
window[tree].update(sg.TreeData())
|
||||
update_miner_count(0)
|
||||
|
||||
def update_tree_by_key(self, data: dict, key: str = "IP"):
|
||||
for idx, item in enumerate(self.data):
|
||||
|
||||
Reference in New Issue
Block a user