made fault lights and async generator to make them much faster

This commit is contained in:
UpstreamData
2022-05-26 15:41:41 -06:00
parent a8ce73c3d6
commit 96801f93d1

View File

@@ -3,6 +3,7 @@ from tools.cfg_util.layout import window, update_prog_bar
from tools.cfg_util.tables import TableManager from tools.cfg_util.tables import TableManager
from tools.cfg_util.decorators import disable_buttons from tools.cfg_util.decorators import disable_buttons
from settings import CFG_UTIL_CONFIG_THREADS as COMMAND_THREADS from settings import CFG_UTIL_CONFIG_THREADS as COMMAND_THREADS
from typing import Tuple
import asyncio import asyncio
@@ -12,21 +13,32 @@ async def btn_light(ip_idxs: list):
table_manager = TableManager() table_manager = TableManager()
_table = window["cmd_table"].Widget _table = window["cmd_table"].Widget
iids = _table.get_children() iids = _table.get_children()
tasks = []
vals = {}
for idx in ip_idxs: for idx in ip_idxs:
item = _table.item(iids[idx]) item = _table.item(iids[idx])
ip = item["values"][0] ip = item["values"][0]
new_light_val = not table_manager.data[ip]["Light"] new_light_val = not table_manager.data[ip]["Light"]
miner = await MinerFactory().get_miner(ip) tasks.append(_fault_light(ip, new_light_val))
if new_light_val: vals[ip] = new_light_val
success = await miner.fault_light_on()
else: for task in asyncio.as_completed(tasks):
success = await miner.fault_light_off() ip, success = await task
if success: if success:
table_manager.data[ip]["Light"] = new_light_val table_manager.data[ip]["Light"] = vals[ip]
table_manager.data[ip]["Output"] = "Fault Light command succeeded." table_manager.data[ip]["Output"] = "Fault Light command succeeded."
else: else:
table_manager.data[ip]["Output"] = "Fault Light command failed." table_manager.data[ip]["Output"] = "Fault Light command failed."
table_manager.update_tables() table_manager.update_tables()
async def _fault_light(ip: str, on: bool) -> Tuple[str, bool]:
miner = await MinerFactory().get_miner(ip)
if on:
success = await miner.fault_light_on()
else:
success = await miner.fault_light_off()
return miner.ip, success
@disable_buttons("Rebooting") @disable_buttons("Rebooting")