improved format and readability

This commit is contained in:
UpstreamData
2021-10-20 13:47:58 -06:00
parent 62ea4578a2
commit ea2ec6463e
14 changed files with 77 additions and 56 deletions

View File

@@ -18,18 +18,25 @@ class APIError(Exception):
class BaseMinerAPI:
def __init__(self, ip: str, port: int):
def __init__(self, ip: str, port: int) -> None:
self.port = port
self.ip = ipaddress.ip_address(ip)
def get_commands(self):
return [func for func in dir(self) if callable(getattr(self, func)) and not func.startswith("__") and func not in [func for func in dir(BaseMinerAPI) if callable(getattr(BaseMinerAPI, func))]]
def get_commands(self) -> list:
return [func for func in
dir(self) if callable(getattr(self, func)) and
not func.startswith("__") and
func not in
[func for func in
dir(BaseMinerAPI) if callable(getattr(BaseMinerAPI, func))
]
]
async def multicommand(self, *commands: str) -> dict:
command = "+".join(commands)
return await self.send_command(command)
async def send_command(self, command: str, parameters: str = None) -> dict:
async def send_command(self, command: str, parameters: str or int or bool = None) -> dict:
try:
# get reader and writer streams
reader, writer = await asyncio.open_connection(str(self.ip), self.port)