added multicommand function
This commit is contained in:
@@ -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
|
||||
|
||||
6
main.py
6
main.py
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user