refactor: rename API to rpc, and classes from {X}API to {X}RPCAPI to clarify naming.

This commit is contained in:
UpstreamData
2024-01-15 15:09:51 -07:00
parent 4ed49c2321
commit aab8825997
27 changed files with 86 additions and 86 deletions

View File

@@ -4,24 +4,24 @@ Each miner has a unique API that is used to communicate with it.
Each of these API types has commands that differ between them, and some commands have data that others do not.
Each miner that is a subclass of [`BaseMiner`][pyasic.miners.BaseMiner] should have an API linked to it as `Miner.api`.
All API implementations inherit from [`BaseMinerAPI`][pyasic.API.BaseMinerAPI], which implements the basic communications protocols.
All API implementations inherit from [`BaseMinerRPCAPI`][pyasic.API.BaseMinerRPCAPI], which implements the basic communications protocols.
[`BaseMinerAPI`][pyasic.API.BaseMinerAPI] should never be used unless inheriting to create a new miner API class for a new type of miner (which should be exceedingly rare).
[`BaseMinerAPI`][pyasic.API.BaseMinerAPI] cannot be instantiated directly, it will raise a `TypeError`.
[`BaseMinerRPCAPI`][pyasic.API.BaseMinerRPCAPI] should never be used unless inheriting to create a new miner API class for a new type of miner (which should be exceedingly rare).
[`BaseMinerRPCAPI`][pyasic.API.BaseMinerRPCAPI] cannot be instantiated directly, it will raise a `TypeError`.
Use these instead -
#### [BFGMiner API][pyasic.API.bfgminer.BFGMinerAPI]
#### [BMMiner API][pyasic.API.bmminer.BMMinerAPI]
#### [BOSMiner API][pyasic.API.bosminer.BOSMinerAPI]
#### [BTMiner API][pyasic.API.btminer.BTMinerAPI]
#### [CGMiner API][pyasic.API.cgminer.CGMinerAPI]
#### [LUXMiner API][pyasic.API.luxminer.LUXMinerAPI]
#### [Unknown API][pyasic.API.unknown.UnknownAPI]
#### [BFGMiner API][pyasic.API.bfgminer.BFGMinerRPCAPI]
#### [BMMiner API][pyasic.API.bmminer.BMMinerRPCAPI]
#### [BOSMiner API][pyasic.API.bosminer.BOSMinerRPCAPI]
#### [BTMiner API][pyasic.API.btminer.BTMinerRPCAPI]
#### [CGMiner API][pyasic.API.cgminer.CGMinerRPCAPI]
#### [LUXMiner API][pyasic.API.luxminer.LUXMinerRPCAPI]
#### [Unknown API][pyasic.API.unknown.UnknownRPCAPI]
<br>
## BaseMinerAPI
::: pyasic.API.BaseMinerAPI
## BaseMinerRPCAPI
::: pyasic.API.BaseMinerRPCAPI
handler: python
options:
heading_level: 4

View File

@@ -1,6 +1,6 @@
# pyasic
## BFGMinerAPI
::: pyasic.API.bfgminer.BFGMinerAPI
## BFGMinerRPCAPI
::: pyasic.API.bfgminer.BFGMinerRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -1,6 +1,6 @@
# pyasic
## BMMinerAPI
::: pyasic.API.bmminer.BMMinerAPI
## BMMinerRPCAPI
::: pyasic.API.bmminer.BMMinerRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -1,6 +1,6 @@
# pyasic
## BOSMinerAPI
::: pyasic.API.bosminer.BOSMinerAPI
## BOSMinerRPCAPI
::: pyasic.API.bosminer.BOSMinerRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -1,6 +1,6 @@
# pyasic
## BTMinerAPI
::: pyasic.API.btminer.BTMinerAPI
## BTMinerRPCAPI
::: pyasic.API.btminer.BTMinerRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -1,6 +1,6 @@
# pyasic
## CGMinerAPI
::: pyasic.API.cgminer.CGMinerAPI
## CGMinerRPCAPI
::: pyasic.API.cgminer.CGMinerRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -1,6 +1,6 @@
# pyasic
## LUXMinerAPI
::: pyasic.API.luxminer.LUXMinerAPI
## LUXMinerRPCAPI
::: pyasic.API.luxminer.LUXMinerRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -1,6 +1,6 @@
# pyasic
## UnknownAPI
::: pyasic.API.unknown.UnknownAPI
## UnknownRPCAPI
::: pyasic.API.unknown.UnknownRPCAPI
handler: python
options:
show_root_heading: false

View File

@@ -14,11 +14,6 @@
# limitations under the License. -
# ------------------------------------------------------------------------------
from pyasic import settings
from pyasic.API.bmminer import BMMinerAPI
from pyasic.API.bosminer import BOSMinerAPI
from pyasic.API.btminer import BTMinerAPI
from pyasic.API.cgminer import CGMinerAPI
from pyasic.API.unknown import UnknownAPI
from pyasic.config import MinerConfig
from pyasic.data import (
BraiinsOSError,
@@ -33,13 +28,18 @@ from pyasic.miners.base import AnyMiner, DataOptions
from pyasic.miners.miner_factory import MinerFactory, miner_factory
from pyasic.miners.miner_listener import MinerListener
from pyasic.network import MinerNetwork
from pyasic.rpc.bmminer import BMMinerRPCAPI
from pyasic.rpc.bosminer import BOSMinerRPCAPI
from pyasic.rpc.btminer import BTMinerRPCAPI
from pyasic.rpc.cgminer import CGMinerRPCAPI
from pyasic.rpc.unknown import UnknownRPCAPI
__all__ = [
"BMMinerAPI",
"BOSMinerAPI",
"BTMinerAPI",
"CGMinerAPI",
"UnknownAPI",
"BMMinerRPCAPI",
"BOSMinerRPCAPI",
"BTMinerRPCAPI",
"CGMinerRPCAPI",
"UnknownRPCAPI",
"MinerConfig",
"MinerData",
"BraiinsOSError",

View File

@@ -16,7 +16,6 @@
from typing import List, Optional, Union
from pyasic.API import APIError
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, X19Error
@@ -29,6 +28,7 @@ from pyasic.miners.base import (
RPCAPICommand,
WebAPICommand,
)
from pyasic.rpc import APIError
from pyasic.web.antminer import AntminerModernWebAPI, AntminerOldWebAPI
ANTMINER_MODERN_DATA_LOC = DataLocations(

View File

@@ -16,7 +16,6 @@
from typing import List, Optional
from pyasic.API.bfgminer import BFGMinerAPI
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData
@@ -28,6 +27,7 @@ from pyasic.miners.base import (
DataOptions,
RPCAPICommand,
)
from pyasic.rpc.bfgminer import BFGMinerRPCAPI
BFGMINER_DATA_LOC = DataLocations(
**{
@@ -70,7 +70,7 @@ class BFGMiner(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = BFGMinerAPI(ip, api_ver)
self.api = BFGMinerRPCAPI(ip, api_ver)
# static data
self.api_type = "BFGMiner"

View File

@@ -17,7 +17,6 @@
import logging
from typing import List, Optional
from pyasic.API.bmminer import BMMinerAPI
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData
@@ -29,6 +28,7 @@ from pyasic.miners.base import (
DataOptions,
RPCAPICommand,
)
from pyasic.rpc.bmminer import BMMinerRPCAPI
BMMINER_DATA_LOC = DataLocations(
**{
@@ -73,7 +73,7 @@ class BMMiner(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = BMMinerAPI(ip, api_ver)
self.api = BMMinerRPCAPI(ip, api_ver)
# static data
self.api_type = "BMMiner"

View File

@@ -20,7 +20,6 @@ from typing import List, Optional, Union
import toml
from pyasic.API.bosminer import BOSMinerAPI
from pyasic.config import MinerConfig
from pyasic.config.mining import MiningModePowerTune
from pyasic.data import Fan, HashBoard
@@ -35,6 +34,7 @@ from pyasic.miners.base import (
RPCAPICommand,
WebAPICommand,
)
from pyasic.rpc.bosminer import BOSMinerRPCAPI
from pyasic.web.braiins_os import BOSerWebAPI, BOSMinerWebAPI
BOSMINER_DATA_LOC = DataLocations(
@@ -99,7 +99,7 @@ class BOSMiner(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = BOSMinerAPI(ip, api_ver)
self.api = BOSMinerRPCAPI(ip, api_ver)
self.web = BOSMinerWebAPI(ip)
# static data
@@ -715,7 +715,7 @@ class BOSer(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = BOSMinerAPI(ip, api_ver)
self.api = BOSMinerRPCAPI(ip, api_ver)
self.web = BOSerWebAPI(ip)
# static data

View File

@@ -17,7 +17,6 @@
import logging
from typing import List, Optional
from pyasic.API.btminer import BTMinerAPI
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, WhatsminerError
@@ -29,6 +28,7 @@ from pyasic.miners.base import (
DataOptions,
RPCAPICommand,
)
from pyasic.rpc.btminer import BTMinerRPCAPI
BTMINER_DATA_LOC = DataLocations(
**{
@@ -110,7 +110,7 @@ class BTMiner(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = BTMinerAPI(ip, api_ver)
self.api = BTMinerRPCAPI(ip, api_ver)
# static data
self.api_type = "BTMiner"

View File

@@ -17,7 +17,6 @@
import logging
from typing import List, Optional
from pyasic.API.cgminer import CGMinerAPI
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData
@@ -29,6 +28,7 @@ from pyasic.miners.base import (
DataOptions,
RPCAPICommand,
)
from pyasic.rpc.cgminer import CGMinerRPCAPI
CGMINER_DATA_LOC = DataLocations(
**{
@@ -71,7 +71,7 @@ class CGMiner(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = CGMinerAPI(ip, api_ver)
self.api = CGMinerRPCAPI(ip, api_ver)
# static data
self.api_type = "CGMiner"

View File

@@ -15,7 +15,6 @@
# ------------------------------------------------------------------------------
from typing import List, Optional, Tuple, Union
from pyasic.API.luxminer import LUXMinerAPI
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData
@@ -27,6 +26,7 @@ from pyasic.miners.base import (
DataOptions,
RPCAPICommand,
)
from pyasic.rpc.luxminer import LUXMinerRPCAPI
LUXMINER_DATA_LOC = DataLocations(
**{
@@ -69,7 +69,7 @@ class LUXMiner(BaseMiner):
def __init__(self, ip: str, api_ver: str = "0.0.0") -> None:
super().__init__(ip)
# interfaces
self.api = LUXMinerAPI(ip, api_ver)
self.api = LUXMinerRPCAPI(ip, api_ver)
# self.web = BOSMinerWebAPI(ip)
# static data

View File

@@ -16,11 +16,11 @@
from typing import List, Optional, Tuple
from pyasic.API.unknown import UnknownAPI
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData
from pyasic.data.error_codes import MinerErrorData
from pyasic.miners.base import BaseMiner
from pyasic.rpc.unknown import UnknownRPCAPI
class UnknownMiner(BaseMiner):
@@ -32,7 +32,7 @@ class UnknownMiner(BaseMiner):
) -> None:
super().__init__(ip)
self.ip = ip
self.api = UnknownAPI(ip)
self.api = UnknownRPCAPI(ip)
def __repr__(self) -> str:
return f"Unknown: {str(self.ip)}"

View File

@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------
from pyasic.API import APIError
from pyasic.rpc import APIError
class Singleton(type):

View File

@@ -25,7 +25,7 @@ from typing import Union
from pyasic.errors import APIError, APIWarning
class BaseMinerAPI:
class BaseMinerRPCAPI:
def __init__(self, ip: str, port: int = 4028) -> None:
# api port, should be 4028
self.port = port
@@ -35,7 +35,7 @@ class BaseMinerAPI:
self.pwd = "admin"
def __new__(cls, *args, **kwargs):
if cls is BaseMinerAPI:
if cls is BaseMinerRPCAPI:
raise TypeError(f"Only children of '{cls.__name__}' may be instantiated")
return object.__new__(cls)
@@ -164,8 +164,8 @@ class BaseMinerAPI:
func
not in [
func
for func in dir(BaseMinerAPI)
if callable(getattr(BaseMinerAPI, func))
for func in dir(BaseMinerRPCAPI)
if callable(getattr(BaseMinerRPCAPI, func))
]
]

View File

@@ -16,10 +16,10 @@
import asyncio
import logging
from pyasic.API import APIError, BaseMinerAPI
from pyasic.rpc import APIError, BaseMinerRPCAPI
class BFGMinerAPI(BaseMinerAPI):
class BFGMinerRPCAPI(BaseMinerRPCAPI):
"""An abstraction of the BFGMiner API.
Each method corresponds to an API command in BFGMiner.

View File

@@ -16,10 +16,10 @@
import asyncio
import logging
from pyasic.API import APIError, BaseMinerAPI
from pyasic.rpc import APIError, BaseMinerRPCAPI
class BMMinerAPI(BaseMinerAPI):
class BMMinerRPCAPI(BaseMinerRPCAPI):
"""An abstraction of the BMMiner API.
Each method corresponds to an API command in BMMiner.

View File

@@ -14,10 +14,10 @@
# limitations under the License. -
# ------------------------------------------------------------------------------
from pyasic.API import BaseMinerAPI
from pyasic.rpc import BaseMinerRPCAPI
class BOSMinerAPI(BaseMinerAPI):
class BOSMinerRPCAPI(BaseMinerRPCAPI):
"""An abstraction of the BOSMiner API.
Each method corresponds to an API command in BOSMiner.

View File

@@ -28,9 +28,9 @@ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from passlib.handlers.md5_crypt import md5_crypt
from pyasic import settings
from pyasic.API import BaseMinerAPI
from pyasic.errors import APIError
from pyasic.misc import api_min_version
from pyasic.rpc import BaseMinerRPCAPI
### IMPORTANT ###
# you need to change the password of the miners using the Whatsminer
@@ -159,7 +159,7 @@ def create_privileged_cmd(token_data: dict, command: dict) -> bytes:
return api_packet_str.encode("utf-8")
class BTMinerAPI(BaseMinerAPI):
class BTMinerRPCAPI(BaseMinerRPCAPI):
"""An abstraction of the API for MicroBT Whatsminers, BTMiner.
Each method corresponds to an API command in BMMiner.

View File

@@ -16,10 +16,10 @@
import asyncio
import logging
from pyasic.API import APIError, BaseMinerAPI
from pyasic.rpc import APIError, BaseMinerRPCAPI
class CGMinerAPI(BaseMinerAPI):
class CGMinerRPCAPI(BaseMinerRPCAPI):
"""An abstraction of the CGMiner API.
Each method corresponds to an API command in GGMiner.

View File

@@ -15,10 +15,10 @@
# ------------------------------------------------------------------------------
from typing import Literal
from pyasic.API import BaseMinerAPI
from pyasic.rpc import BaseMinerRPCAPI
class LUXMinerAPI(BaseMinerAPI):
class LUXMinerRPCAPI(BaseMinerRPCAPI):
"""An abstraction of the LUXMiner API.
Each method corresponds to an API command in LUXMiner.

View File

@@ -14,10 +14,10 @@
# limitations under the License. -
# ------------------------------------------------------------------------------
from pyasic.API import BaseMinerAPI
from pyasic.rpc import BaseMinerRPCAPI
class UnknownAPI(BaseMinerAPI):
class UnknownRPCAPI(BaseMinerRPCAPI):
"""An abstraction of an API for a miner which is unknown.
This class is designed to try to be an intersection of as many miner APIs

View File

@@ -19,12 +19,12 @@ import unittest
from unittest.mock import patch
from pyasic import APIError
from pyasic.API.bfgminer import BFGMinerAPI
from pyasic.API.bmminer import BMMinerAPI
from pyasic.API.bosminer import BOSMinerAPI
from pyasic.API.btminer import BTMinerAPI
from pyasic.API.cgminer import CGMinerAPI
from pyasic.API.luxminer import LUXMinerAPI
from pyasic.rpc.bfgminer import BFGMinerRPCAPI
from pyasic.rpc.bmminer import BMMinerRPCAPI
from pyasic.rpc.bosminer import BOSMinerRPCAPI
from pyasic.rpc.btminer import BTMinerRPCAPI
from pyasic.rpc.cgminer import CGMinerRPCAPI
from pyasic.rpc.luxminer import LUXMinerRPCAPI
class TestAPIBase(unittest.IsolatedAsyncioTestCase):
@@ -64,7 +64,7 @@ class TestAPIBase(unittest.IsolatedAsyncioTestCase):
}
).encode("utf-8")
@patch("pyasic.API.BaseMinerAPI._send_bytes")
@patch("pyasic.rpc.BaseMinerRPCAPI._send_bytes")
async def test_command_error_raises_api_error(self, mock_send_bytes):
if self.api is None:
return
@@ -73,7 +73,7 @@ class TestAPIBase(unittest.IsolatedAsyncioTestCase):
with self.assertRaises(APIError):
await self.api.send_command("summary")
@patch("pyasic.API.BaseMinerAPI._send_bytes")
@patch("pyasic.rpc.BaseMinerRPCAPI._send_bytes")
async def test_command_error_ignored_by_flag(self, mock_send_bytes):
if self.api is None:
return
@@ -88,7 +88,7 @@ class TestAPIBase(unittest.IsolatedAsyncioTestCase):
f"Expected ignore_errors flag to ignore error in {self.api_str} API"
)
@patch("pyasic.API.BaseMinerAPI._send_bytes")
@patch("pyasic.rpc.BaseMinerRPCAPI._send_bytes")
async def test_all_read_command_success(self, mock_send_bytes):
if self.api is None:
return
@@ -114,37 +114,37 @@ class TestAPIBase(unittest.IsolatedAsyncioTestCase):
class TestBFGMinerAPI(TestAPIBase):
def setUpData(self):
self.api = BFGMinerAPI(self.ip)
self.api = BFGMinerRPCAPI(self.ip)
self.api_str = "BFGMiner"
class TestBMMinerAPI(TestAPIBase):
def setUpData(self):
self.api = BMMinerAPI(self.ip)
self.api = BMMinerRPCAPI(self.ip)
self.api_str = "BMMiner"
class TestBOSMinerAPI(TestAPIBase):
def setUpData(self):
self.api = BOSMinerAPI(self.ip)
self.api = BOSMinerRPCAPI(self.ip)
self.api_str = "BOSMiner"
class TestBTMinerAPI(TestAPIBase):
def setUpData(self):
self.api = BTMinerAPI(self.ip)
self.api = BTMinerRPCAPI(self.ip)
self.api_str = "BTMiner"
class TestCGMinerAPI(TestAPIBase):
def setUpData(self):
self.api = CGMinerAPI(self.ip)
self.api = CGMinerRPCAPI(self.ip)
self.api_str = "CGMiner"
class TestLuxOSAPI(TestAPIBase):
def setUpData(self):
self.api = LUXMinerAPI(self.ip)
self.api = LUXMinerRPCAPI(self.ip)
self.api_str = "LuxOS"