format: update a bunch of formatting and remove a lot of useless imports.

This commit is contained in:
UpstreamData
2023-02-28 09:35:11 -07:00
parent 6f1c1e0290
commit d222912e30
26 changed files with 73 additions and 97 deletions

View File

@@ -92,7 +92,9 @@ class BaseMinerAPI:
async def send_privileged_command(self, *args, **kwargs) -> dict: async def send_privileged_command(self, *args, **kwargs) -> dict:
return await self.send_command(*args, **kwargs) return await self.send_command(*args, **kwargs)
async def multicommand(self, *commands: str, allow_warning: bool = True) -> dict: async def multicommand(
self, *commands: str, ignore_errors: bool = False, allow_warning: bool = True
) -> dict:
"""Creates and sends multiple commands as one command to the miner. """Creates and sends multiple commands as one command to the miner.
Parameters: Parameters:
@@ -107,7 +109,9 @@ class BaseMinerAPI:
# standard format doesn't work for X19 # standard format doesn't work for X19
command = "+".join(commands) command = "+".join(commands)
try: try:
data = await self.send_command(command, allow_warning=allow_warning) data = await self.send_command(
command, allow_warning=allow_warning, ignore_errors=ignore_errors
)
except APIError: except APIError:
return {command: [{}] for command in commands} return {command: [{}] for command in commands}
logging.debug(f"{self} - (Multicommand) - Received data") logging.debug(f"{self} - (Multicommand) - Received data")

View File

@@ -246,7 +246,7 @@ class BTMinerAPI(BaseMinerAPI):
logging.debug(f"{self} - (Send Privileged Command) - Sending") logging.debug(f"{self} - (Send Privileged Command) - Sending")
try: try:
data = await self._send_bytes(enc_command, timeout) data = await self._send_bytes(enc_command, timeout)
except (asyncio.CancelledError, asyncio.TimeoutError) as e: except (asyncio.CancelledError, asyncio.TimeoutError):
if ignore_errors: if ignore_errors:
return {} return {}
raise APIError("No data was returned from the API.") raise APIError("No data was returned from the API.")

View File

@@ -62,7 +62,7 @@ class CGMinerAPI(BaseMinerAPI):
for cmd in commands: for cmd in commands:
data[cmd] = [] data[cmd] = []
data[cmd].append(await self.send_command(cmd, allow_warning=True)) data[cmd].append(await self.send_command(cmd, allow_warning=True))
except APIError as e: except APIError:
pass pass
except Exception as e: except Exception as e:
logging.warning( logging.warning(

View File

@@ -14,14 +14,13 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import json
import logging import logging
import random import random
import string import string
import time import time
from dataclasses import asdict, dataclass, fields from dataclasses import asdict, dataclass, fields
from enum import IntEnum from enum import IntEnum
from typing import Dict, List, Literal from typing import List, Literal
import toml import toml
import yaml import yaml
@@ -202,17 +201,23 @@ class _PoolGroup:
pools[f"{key}{idx+1}"] = pool_data[key] pools[f"{key}{idx+1}"] = pool_data[key]
return pools return pools
def as_wm(self, user_suffix: str = None) -> List[dict]: def as_wm(self, user_suffix: str = None) -> dict:
"""Convert the data in this class to a list usable by a Whatsminer device. """Convert the data in this class to a list usable by a Whatsminer device.
Parameters: Parameters:
user_suffix: The suffix to append to username. user_suffix: The suffix to append to username.
""" """
pools = [] pools = {}
for pool in self.pools[:3]: for i in range(1, 4):
pools.append(pool.as_wm(user_suffix=user_suffix)) if i <= len(self.pools):
while len(pools) < 3: pool_wm = self.pools[i - 1].as_wm(user_suffix)
pools.append({"url": None, "user": None, "pass": None}) pools[f"pool_{i}"] = pool_wm["url"]
pools[f"worker_{i}"] = pool_wm["user"]
pools[f"passwd_{i}"] = pool_wm["pass"]
else:
pools[f"pool_{i}"] = None
pools[f"worker_{i}"] = None
pools[f"passwd_{i}"] = None
return pools return pools
def as_avalon(self, user_suffix: str = None) -> str: def as_avalon(self, user_suffix: str = None) -> str:
@@ -434,7 +439,7 @@ class MinerConfig:
logging.debug(f"MinerConfig - (From YAML) - Loading YAML config") logging.debug(f"MinerConfig - (From YAML) - Loading YAML config")
return self.from_dict(yaml.load(data, Loader=yaml.SafeLoader)) return self.from_dict(yaml.load(data, Loader=yaml.SafeLoader))
def as_wm(self, user_suffix: str = None) -> Dict[str, int]: def as_wm(self, user_suffix: str = None) -> dict:
"""Convert the data in this class to a config usable by a Whatsminer device. """Convert the data in this class to a config usable by a Whatsminer device.
Parameters: Parameters:

View File

@@ -15,17 +15,25 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import asyncio import asyncio
import logging
from typing import List, Union from typing import List, Union
# from pyasic.errors import PhaseBalancingError
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners import AnyMiner from pyasic.miners import AnyMiner
from pyasic.miners._backends import X19, BOSMiner, BTMiner from pyasic.miners._backends import ( # noqa - Ignore access to _module
from pyasic.miners._types import S9, S17, T17, S17e, S17Plus, S17Pro, T17e, T17Plus X19,
BOSMiner,
# from pprint import pprint as print BTMiner,
)
from pyasic.miners._types import ( # noqa - Ignore access to _module
S9,
S17,
T17,
S17e,
S17Plus,
S17Pro,
T17e,
T17Plus,
)
FAN_USAGE = 50 # 50 W per fan FAN_USAGE = 50 # 50 W per fan

View File

@@ -17,17 +17,16 @@
import ipaddress import ipaddress
import logging import logging
from collections import namedtuple from collections import namedtuple
from typing import List, Optional, Tuple, Union from typing import List, Optional, Tuple
import asyncssh import asyncssh
from pyasic.API.bmminer import BMMinerAPI from pyasic.API.bmminer import BMMinerAPI
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData from pyasic.data.error_codes import MinerErrorData
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners.base import BaseMiner from pyasic.miners.base import BaseMiner
from pyasic.settings import PyasicSettings
class BMMiner(BaseMiner): class BMMiner(BaseMiner):

View File

@@ -26,11 +26,10 @@ import toml
from pyasic.API.bosminer import BOSMinerAPI from pyasic.API.bosminer import BOSMinerAPI
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import BraiinsOSError, MinerErrorData from pyasic.data.error_codes import BraiinsOSError, MinerErrorData
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners.base import BaseMiner from pyasic.miners.base import BaseMiner
from pyasic.settings import PyasicSettings
class BOSMiner(BaseMiner): class BOSMiner(BaseMiner):
@@ -839,7 +838,6 @@ class BOSMiner(BaseMiner):
api_devs = await self.api.devs() api_devs = await self.api.devs()
except APIError: except APIError:
pass pass
nom_hr = 0
if api_devs: if api_devs:
try: try:

View File

@@ -16,8 +16,7 @@
import ipaddress import ipaddress
import logging import logging
from collections import namedtuple from typing import List, Optional, Tuple
from typing import List, Optional, Tuple, Union
import asyncssh import asyncssh
@@ -180,5 +179,5 @@ class BOSMinerOld(BaseMiner):
async def get_nominal_hashrate(self) -> Optional[float]: async def get_nominal_hashrate(self) -> Optional[float]:
return None return None
async def get_data(self, allow_warning: bool = False) -> MinerData: async def get_data(self, allow_warning: bool = False, **kwargs) -> MinerData:
return MinerData(ip=str(self.ip)) return MinerData(ip=str(self.ip))

View File

@@ -18,15 +18,14 @@ import ipaddress
import logging import logging
import warnings import warnings
from collections import namedtuple from collections import namedtuple
from typing import List, Optional, Tuple, Union from typing import List, Optional, Tuple
from pyasic.API.btminer import BTMinerAPI from pyasic.API.btminer import BTMinerAPI
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, WhatsminerError from pyasic.data.error_codes import MinerErrorData, WhatsminerError
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners.base import BaseMiner from pyasic.miners.base import BaseMiner
from pyasic.settings import PyasicSettings
class BTMiner(BaseMiner): class BTMiner(BaseMiner):
@@ -122,17 +121,7 @@ class BTMiner(BaseMiner):
pools_conf = conf["pools"] pools_conf = conf["pools"]
try: try:
await self.api.update_pools( await self.api.update_pools(**pools_conf)
pools_conf[0]["url"],
pools_conf[0]["user"],
pools_conf[0]["pass"],
pools_conf[1]["url"],
pools_conf[1]["user"],
pools_conf[1]["pass"],
pools_conf[2]["url"],
pools_conf[2]["user"],
pools_conf[2]["pass"],
)
except APIError: except APIError:
pass pass
try: try:
@@ -546,8 +535,6 @@ class BTMiner(BaseMiner):
pass pass
async def get_fault_light(self, api_get_miner_info: dict = None) -> bool: async def get_fault_light(self, api_get_miner_info: dict = None) -> bool:
data = None
if not api_get_miner_info: if not api_get_miner_info:
try: try:
api_get_miner_info = await self.api.get_miner_info() api_get_miner_info = await self.api.get_miner_info()

View File

@@ -17,17 +17,16 @@
import ipaddress import ipaddress
import logging import logging
from collections import namedtuple from collections import namedtuple
from typing import List, Optional, Tuple, Union from typing import List, Optional, Tuple
import asyncssh import asyncssh
from pyasic.API.cgminer import CGMinerAPI from pyasic.API.cgminer import CGMinerAPI
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData from pyasic.data.error_codes import MinerErrorData
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners.base import BaseMiner from pyasic.miners.base import BaseMiner
from pyasic.settings import PyasicSettings
class CGMiner(BaseMiner): class CGMiner(BaseMiner):

View File

@@ -14,20 +14,15 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import ipaddress
import logging import logging
import re import re
from collections import namedtuple from typing import List, Optional
from typing import List, Optional, Tuple, Union
from pyasic.API.cgminer import CGMinerAPI
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard, MinerData from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData from pyasic.data.error_codes import MinerErrorData
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners._backends import CGMiner from pyasic.miners._backends import CGMiner
from pyasic.miners.base import BaseMiner
from pyasic.settings import PyasicSettings
class CGMinerAvalon(CGMiner): class CGMinerAvalon(CGMiner):
@@ -79,7 +74,7 @@ class CGMinerAvalon(CGMiner):
logging.debug(f"{self}: Sending config.") # noqa - This doesnt work... logging.debug(f"{self}: Sending config.") # noqa - This doesnt work...
conf = config.as_avalon(user_suffix=user_suffix) conf = config.as_avalon(user_suffix=user_suffix)
try: try:
data = await self.api.ascset( data = await self.api.ascset( # noqa
0, "setpool", f"root,root,{conf}" 0, "setpool", f"root,root,{conf}"
) # this should work but doesn't ) # this should work but doesn't
except APIError: except APIError:

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19 # noqa - Ignore access to _module from pyasic.miners._types import S19 # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19Pro # noqa - Ignore access to _module from pyasic.miners._types import S19Pro # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19XP # noqa - Ignore access to _module from pyasic.miners._types import S19XP # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19a # noqa - Ignore access to _module from pyasic.miners._types import S19a # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19aPro # noqa - Ignore access to _module from pyasic.miners._types import S19aPro # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19j # noqa - Ignore access to _module from pyasic.miners._types import S19j # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import S19jPro # noqa - Ignore access to _module from pyasic.miners._types import S19jPro # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,7 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from pyasic.miners._backends import X19 from pyasic.miners._backends import X19 # noqa - Ignore access to _module
from pyasic.miners._types import T19 # noqa - Ignore access to _module from pyasic.miners._types import T19 # noqa - Ignore access to _module
# noqa - Ignore access to _module # noqa - Ignore access to _module

View File

@@ -14,10 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import json from typing import Union
from typing import Optional, Union
import httpx
from pyasic.miners._backends import BMMiner # noqa - Ignore access to _module from pyasic.miners._backends import BMMiner # noqa - Ignore access to _module
from pyasic.miners._types import S9 # noqa - Ignore access to _module from pyasic.miners._types import S9 # noqa - Ignore access to _module

View File

@@ -18,11 +18,10 @@ from typing import List, Optional
import asyncssh import asyncssh
from pyasic.data import HashBoard, MinerData from pyasic.data import HashBoard
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners._backends import Hiveon # noqa - Ignore access to _module from pyasic.miners._backends import Hiveon # noqa - Ignore access to _module
from pyasic.miners._types import T9 # noqa - Ignore access to _module from pyasic.miners._types import T9 # noqa - Ignore access to _module
from pyasic.settings import PyasicSettings
class HiveonT9(Hiveon, T9): class HiveonT9(Hiveon, T9):

View File

@@ -33,6 +33,8 @@ class BaseMiner(ABC):
self.ip = None self.ip = None
self.api = None self.api = None
self.web = None self.web = None
self.uname = None
self.pwd = None
self.api_type = None self.api_type = None
self.api_ver = None self.api_ver = None
self.fw_ver = None self.fw_ver = None

View File

@@ -13,13 +13,8 @@
# See the License for the specific language governing permissions and - # See the License for the specific language governing permissions and -
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import json
import logging import logging
import warnings from typing import List, Optional
from collections import namedtuple
from typing import List, Optional, Tuple, Union
import httpx
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard from pyasic.data import Fan, HashBoard
@@ -27,7 +22,6 @@ from pyasic.data.error_codes import InnosiliconError, MinerErrorData
from pyasic.errors import APIError from pyasic.errors import APIError
from pyasic.miners._backends import CGMiner # noqa - Ignore access to _module from pyasic.miners._backends import CGMiner # noqa - Ignore access to _module
from pyasic.miners._types import InnosiliconT3HPlus # noqa - Ignore access to _module from pyasic.miners._types import InnosiliconT3HPlus # noqa - Ignore access to _module
from pyasic.settings import PyasicSettings
from pyasic.web.Inno import InnosiliconWebAPI from pyasic.web.Inno import InnosiliconWebAPI
@@ -84,9 +78,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
################################################## ##################################################
async def get_mac( async def get_mac(
self, self, web_get_all: dict = None, web_overview: dict = None
web_get_all: dict = None, # noqa
web_overview: dict = None, # noqa: named this way for automatic functionality
) -> Optional[str]: ) -> Optional[str]:
if not web_get_all and not web_overview: if not web_get_all and not web_overview:
try: try:
@@ -127,9 +119,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
pass pass
async def get_hashrate( async def get_hashrate(
self, self, api_summary: dict = None, web_get_all: dict = None
api_summary: dict = None,
web_get_all: dict = None, # noqa: named this way for automatic functionality
) -> Optional[float]: ) -> Optional[float]:
if not api_summary and not web_get_all: if not api_summary and not web_get_all:
try: try:
@@ -152,9 +142,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
pass pass
async def get_hashboards( async def get_hashboards(
self, self, api_stats: dict = None, web_get_all: dict = None
api_stats: dict = None,
web_get_all: dict = None, # noqa: named this way for automatic functionality
) -> List[HashBoard]: ) -> List[HashBoard]:
hashboards = [ hashboards = [
HashBoard(slot=i, expected_chips=self.nominal_chips) HashBoard(slot=i, expected_chips=self.nominal_chips)
@@ -209,9 +197,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
return hashboards return hashboards
async def get_wattage( async def get_wattage(
self, self, web_get_all: dict = None, api_stats: dict = None
web_get_all: dict = None,
api_stats: dict = None, # noqa: named this way for automatic functionality
) -> Optional[int]: ) -> Optional[int]:
if not web_get_all: if not web_get_all:
try: try:
@@ -244,10 +230,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
wattage = int(wattage) wattage = int(wattage)
return wattage return wattage
async def get_fans( async def get_fans(self, web_get_all: dict = None) -> List[Fan]:
self,
web_get_all: dict = None, # noqa: named this way for automatic functionality
) -> List[Fan]:
if not web_get_all: if not web_get_all:
try: try:
web_get_all = await self.web.get_all() web_get_all = await self.web.get_all()

View File

@@ -27,7 +27,8 @@ class _MinerListener:
def connection_made(self, transport): def connection_made(self, transport):
self.transport = transport self.transport = transport
def datagram_received(self, data, _addr): @staticmethod
def datagram_received(data, _addr):
m = data.decode() m = data.decode()
if "," in m: if "," in m:
ip, mac = m.split(",") ip, mac = m.split(",")

View File

@@ -14,7 +14,6 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
from collections import namedtuple
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from pyasic.API.unknown import UnknownAPI from pyasic.API.unknown import UnknownAPI
@@ -26,7 +25,9 @@ from pyasic.miners.base import BaseMiner
class UnknownMiner(BaseMiner): class UnknownMiner(BaseMiner):
def __init__(self, ip: str, *args, **kwargs) -> None: def __init__(
self, ip: str, *args, **kwargs
) -> None: # noqa - ignore *args and **kwargs for signature consistency
super().__init__() super().__init__()
self.ip = ip self.ip = ip
self.api = UnknownAPI(ip) self.api = UnknownAPI(ip)

View File

@@ -19,7 +19,6 @@ from abc import ABC, abstractmethod
from typing import Union from typing import Union
from pyasic.errors import APIWarning from pyasic.errors import APIWarning
from pyasic.settings import PyasicSettings
class BaseWebAPI(ABC): class BaseWebAPI(ABC):