fixed a bug with multicommand on S19 where it doesnt work with the '+'.join(*commands)

This commit is contained in:
UpstreamData
2021-11-03 11:41:12 -06:00
parent 9c3faca667
commit 027423242d
2 changed files with 34 additions and 8 deletions

View File

@@ -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