fixed a bug with multicommand on S19 where it doesnt work with the '+'.join(*commands)
This commit is contained in:
@@ -36,6 +36,7 @@ class BaseMinerAPI:
|
||||
commands = [*commands]
|
||||
for item in commands:
|
||||
if item not in self.get_commands():
|
||||
print(f"Removing command: {item}")
|
||||
commands.remove(item)
|
||||
command = "+".join(commands)
|
||||
return await self.send_command(command)
|
||||
@@ -83,6 +84,22 @@ class BaseMinerAPI:
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
|
||||
if not self.validate_command_output(data):
|
||||
try:
|
||||
data = {}
|
||||
for cmd in command.split("+"):
|
||||
data[cmd] = []
|
||||
data[cmd].append(await self.send_command(cmd))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
# check again after second try
|
||||
if not self.validate_command_output(data):
|
||||
raise APIError(data["STATUS"][0]["Msg"])
|
||||
|
||||
return data
|
||||
|
||||
def validate_command_output(self, data):
|
||||
# check if the data returned is correct or an error
|
||||
# if status isn't a key, it is a multicommand
|
||||
if "STATUS" not in data.keys():
|
||||
@@ -93,12 +110,11 @@ class BaseMinerAPI:
|
||||
if "STATUS" in data.keys():
|
||||
if data[key][0]["STATUS"][0]["STATUS"] not in ["S", "I"]:
|
||||
# this is an error
|
||||
raise APIError(data["STATUS"][0]["Msg"])
|
||||
return False
|
||||
else:
|
||||
# make sure the command succeeded
|
||||
if data["STATUS"][0]["STATUS"] not in ("S", "I"):
|
||||
# this is an error
|
||||
raise APIError(data["STATUS"][0]["Msg"])
|
||||
|
||||
# return the data
|
||||
return data
|
||||
if data["STATUS"][0]["STATUS"] not in ("S", "I"):
|
||||
return False
|
||||
return True
|
||||
|
||||
16
main.py
16
main.py
@@ -3,7 +3,7 @@ from miners.bosminer import BOSminer
|
||||
import asyncio
|
||||
|
||||
|
||||
async def main():
|
||||
async def good_boards():
|
||||
miner_network = MinerNetwork('192.168.1.1')
|
||||
miners = await miner_network.scan_network_for_miners()
|
||||
# print("\n".join([str(miner.ip) for miner in miners]))
|
||||
@@ -13,7 +13,7 @@ async def main():
|
||||
# print('\n'.join([f"{str(miner.ip)}" for miner in miners]))
|
||||
|
||||
|
||||
async def main_bad():
|
||||
async def bad_boards():
|
||||
miner_network = MinerNetwork('192.168.1.1')
|
||||
miners = await miner_network.scan_network_for_miners()
|
||||
bad_list = list(filter(None, await asyncio.gather(*[miner.get_bad_boards() for miner in miners if isinstance(miner, BOSminer)])))
|
||||
@@ -31,5 +31,15 @@ async def braiins_update():
|
||||
results = await asyncio.gather(*tasks)
|
||||
print(results)
|
||||
|
||||
async def test_command():
|
||||
miner_network = MinerNetwork('192.168.1.1')
|
||||
miners = await miner_network.scan_network_for_miners()
|
||||
tasks = miners[0].api.multicommand("summary", "pools", "tunerstatus")
|
||||
data = await asyncio.gather(tasks)
|
||||
print(data)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.new_event_loop().run_until_complete(braiins_update())
|
||||
asyncio.new_event_loop().run_until_complete(test_command())
|
||||
|
||||
Reference in New Issue
Block a user