added multicommand function

This commit is contained in:
UpstreamData
2021-09-23 12:03:34 -06:00
parent 315b6d2fb9
commit 5ba768d0bc
2 changed files with 22 additions and 7 deletions

View File

@@ -21,6 +21,10 @@ class BaseMinerAPI:
self.port = port
self.ip = ip
async def multicommand(self, *commands: str):
command = "+".join(commands)
return await self.send_command(command)
async def send_command(self, command, parameters: dict = None):
# get reader and writer streams
reader, writer = await asyncio.open_connection(self.ip, self.port)
@@ -51,11 +55,20 @@ class BaseMinerAPI:
await writer.wait_closed()
# check if the data returned is correct or an error
if not data["STATUS"][0]["STATUS"] in ("S", "I"):
# this is an error
print(cmd)
print(data)
raise APIError(data["STATUS"][0]["Msg"])
# if status isn't a key, it is a multicommand
if "STATUS" not in data.keys():
for key in data.keys():
# make sure not to try to turn id into a dict
if not key == "id":
# make sure they succeeded
if data[key][0]["STATUS"][0]["STATUS"] not in ["S", "I"]:
# this is an error
raise APIError(data["STATUS"][0]["Msg"])
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

View File

@@ -4,8 +4,10 @@ import asyncio
async def main():
bosminer = BOSMinerAPI("172.16.1.199")
data = await bosminer.edevs(old=True)
print(data)
data_normal = await bosminer.asccount()
data_multi = await bosminer.multicommand("version", "config")
print(data_normal)
print(data_multi)
asyncio.get_event_loop().run_until_complete(main())