fixed minor bugs in the API implmentation
This commit is contained in:
@@ -21,14 +21,14 @@ class BaseMinerAPI:
|
|||||||
self.port = port
|
self.port = port
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
|
|
||||||
async def send_command(self, command, parameters=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)
|
||||||
|
|
||||||
# create the command
|
# create the command
|
||||||
cmd = {"command": command}
|
cmd = {"command": command}
|
||||||
if parameters:
|
if parameters is not None:
|
||||||
cmd["parameters"] = parameters
|
cmd["parameter"] = parameters
|
||||||
|
|
||||||
# send the command
|
# send the command
|
||||||
writer.write(json.dumps(cmd).encode('utf-8'))
|
writer.write(json.dumps(cmd).encode('utf-8'))
|
||||||
@@ -53,6 +53,8 @@ class BaseMinerAPI:
|
|||||||
# 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 not data["STATUS"][0]["STATUS"] 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
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class BMMinerAPI(BaseMinerAPI):
|
|||||||
return await self.send_command("enablepool", parameters=n)
|
return await self.send_command("enablepool", parameters=n)
|
||||||
|
|
||||||
async def addpool(self, url: str, username: str, password: str):
|
async def addpool(self, url: str, username: str, password: str):
|
||||||
return await self.send_command("enablepool", parameters=f"{url}, {username}, {password}")
|
return await self.send_command("addpool", parameters=f"{url}, {username}, {password}")
|
||||||
|
|
||||||
async def poolpriority(self, *n: int):
|
async def poolpriority(self, *n: int):
|
||||||
return await self.send_command("poolpriority", parameters=f"{','.join(n)}")
|
return await self.send_command("poolpriority", parameters=f"{','.join(n)}")
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class BOSMinerAPI(BaseMinerAPI):
|
|||||||
return await self.send_command("disablepool", parameters=n)
|
return await self.send_command("disablepool", parameters=n)
|
||||||
|
|
||||||
async def addpool(self, url: str, username: str, password: str):
|
async def addpool(self, url: str, username: str, password: str):
|
||||||
return await self.send_command("enablepool", parameters=f"{url}, {username}, {password}")
|
return await self.send_command("addpool", parameters=f"{url}, {username}, {password}")
|
||||||
|
|
||||||
async def removepool(self, n: int):
|
async def removepool(self, n: int):
|
||||||
return await self.send_command("removepool", parameters=n)
|
return await self.send_command("removepool", parameters=n)
|
||||||
|
|||||||
Reference in New Issue
Block a user