added multicommand function
This commit is contained in:
@@ -21,6 +21,10 @@ class BaseMinerAPI:
|
|||||||
self.port = port
|
self.port = port
|
||||||
self.ip = ip
|
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):
|
async def send_command(self, command, parameters: dict = None):
|
||||||
# get reader and writer streams
|
# get reader and writer streams
|
||||||
reader, writer = await asyncio.open_connection(self.ip, self.port)
|
reader, writer = await asyncio.open_connection(self.ip, self.port)
|
||||||
@@ -51,10 +55,19 @@ class BaseMinerAPI:
|
|||||||
await writer.wait_closed()
|
await writer.wait_closed()
|
||||||
|
|
||||||
# check if the data returned is correct or an error
|
# check if the data returned is correct or an error
|
||||||
if not data["STATUS"][0]["STATUS"] in ("S", "I"):
|
# 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
|
# this is an error
|
||||||
print(cmd)
|
|
||||||
print(data)
|
|
||||||
raise APIError(data["STATUS"][0]["Msg"])
|
raise APIError(data["STATUS"][0]["Msg"])
|
||||||
|
|
||||||
# return the data
|
# return the data
|
||||||
|
|||||||
6
main.py
6
main.py
@@ -4,8 +4,10 @@ import asyncio
|
|||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
bosminer = BOSMinerAPI("172.16.1.199")
|
bosminer = BOSMinerAPI("172.16.1.199")
|
||||||
data = await bosminer.edevs(old=True)
|
data_normal = await bosminer.asccount()
|
||||||
print(data)
|
data_multi = await bosminer.multicommand("version", "config")
|
||||||
|
print(data_normal)
|
||||||
|
print(data_multi)
|
||||||
|
|
||||||
|
|
||||||
asyncio.get_event_loop().run_until_complete(main())
|
asyncio.get_event_loop().run_until_complete(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user