set up an API error class
This commit is contained in:
18
main.py
18
main.py
@@ -2,6 +2,20 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class APIError(Exception):
|
||||||
|
def __init__(self, *args):
|
||||||
|
if args:
|
||||||
|
self.message = args[0]
|
||||||
|
else:
|
||||||
|
self.message = None
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
if self.message:
|
||||||
|
return f"{self.message}"
|
||||||
|
else:
|
||||||
|
return "Incorrect API parameters."
|
||||||
|
|
||||||
|
|
||||||
class API:
|
class API:
|
||||||
def __init__(self, port, ip):
|
def __init__(self, port, ip):
|
||||||
self.port = port
|
self.port = port
|
||||||
@@ -90,7 +104,6 @@ class BMMiner(API):
|
|||||||
return self.send_command("lcd")
|
return self.send_command("lcd")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BOSMiner(API):
|
class BOSMiner(API):
|
||||||
def __init__(self, ip, port):
|
def __init__(self, ip, port):
|
||||||
super().__init__(ip, port)
|
super().__init__(ip, port)
|
||||||
@@ -142,3 +155,6 @@ class BOSMiner(API):
|
|||||||
|
|
||||||
def tunerstatus(self):
|
def tunerstatus(self):
|
||||||
return self.send_command("tunerstatus")
|
return self.send_command("tunerstatus")
|
||||||
|
|
||||||
|
|
||||||
|
raise APIError
|
||||||
|
|||||||
Reference in New Issue
Block a user