refactor: fix hashrate return typing.
This commit is contained in:
@@ -19,6 +19,8 @@ from typing import List, Optional, Union
|
||||
from pyasic.config import MinerConfig, MiningModeConfig
|
||||
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
|
||||
from pyasic.data.error_codes import MinerErrorData, X19Error
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
from pyasic.errors import APIError
|
||||
from pyasic.miners.backends.bmminer import BMMiner
|
||||
from pyasic.miners.backends.cgminer import CGMiner
|
||||
from pyasic.miners.data import (
|
||||
@@ -31,8 +33,6 @@ from pyasic.miners.data import (
|
||||
from pyasic.rpc.antminer import AntminerRPCAPI
|
||||
from pyasic.ssh.antminer import AntminerModernSSH
|
||||
from pyasic.web.antminer import AntminerModernWebAPI, AntminerOldWebAPI
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
from pyasic.errors import APIError
|
||||
|
||||
ANTMINER_MODERN_DATA_LOC = DataLocations(
|
||||
**{
|
||||
@@ -95,7 +95,7 @@ class AntminerModern(BMMiner):
|
||||
web: AntminerModernWebAPI
|
||||
|
||||
_rpc_cls = AntminerRPCAPI
|
||||
web: AntminerRPCAPI
|
||||
rpc: AntminerRPCAPI
|
||||
|
||||
_ssh_cls = AntminerModernSSH
|
||||
ssh: AntminerModernSSH
|
||||
@@ -156,7 +156,7 @@ class AntminerModern(BMMiner):
|
||||
await self.send_config(cfg)
|
||||
return True
|
||||
|
||||
async def _get_hostname(self, web_get_system_info: dict = None) -> Union[str, None]:
|
||||
async def _get_hostname(self, web_get_system_info: dict = None) -> Optional[str]:
|
||||
if web_get_system_info is None:
|
||||
try:
|
||||
web_get_system_info = await self.web.get_system_info()
|
||||
@@ -169,7 +169,7 @@ class AntminerModern(BMMiner):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
async def _get_mac(self, web_get_system_info: dict = None) -> Union[str, None]:
|
||||
async def _get_mac(self, web_get_system_info: dict = None) -> Optional[str]:
|
||||
if web_get_system_info is None:
|
||||
try:
|
||||
web_get_system_info = await self.web.get_system_info()
|
||||
@@ -264,7 +264,9 @@ class AntminerModern(BMMiner):
|
||||
pass
|
||||
return self.light
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_stats: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_stats: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if rpc_stats is None:
|
||||
try:
|
||||
rpc_stats = await self.rpc.stats()
|
||||
@@ -377,8 +379,7 @@ class AntminerModern(BMMiner):
|
||||
alive=pool_info.get("Status") == "Alive",
|
||||
url=pool_info.get("URL"),
|
||||
user=pool_info.get("User"),
|
||||
index=pool_info.get("POOL")
|
||||
|
||||
index=pool_info.get("POOL"),
|
||||
)
|
||||
pools_data.append(pool_data)
|
||||
except LookupError:
|
||||
@@ -446,7 +447,7 @@ class AntminerOld(CGMiner):
|
||||
self.config = config
|
||||
await self.web.set_miner_conf(config.as_am_old(user_suffix=user_suffix))
|
||||
|
||||
async def _get_mac(self) -> Union[str, None]:
|
||||
async def _get_mac(self) -> Optional[str]:
|
||||
try:
|
||||
data = await self.web.get_system_info()
|
||||
if data:
|
||||
|
||||
@@ -236,7 +236,7 @@ class Auradine(StockFirmware):
|
||||
except LookupError:
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
|
||||
@@ -173,7 +173,7 @@ class AvalonMiner(CGMiner):
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self, rpc_devs: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_devs: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_devs is None:
|
||||
try:
|
||||
rpc_devs = await self.rpc.devs()
|
||||
@@ -238,7 +238,9 @@ class AvalonMiner(CGMiner):
|
||||
|
||||
return hashboards
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_stats: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_stats: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if rpc_stats is None:
|
||||
try:
|
||||
rpc_stats = await self.rpc.stats()
|
||||
|
||||
@@ -105,7 +105,7 @@ class BFGMiner(StockFirmware):
|
||||
|
||||
return self.fw_ver
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
# get hr from API
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
@@ -207,7 +207,9 @@ class BFGMiner(StockFirmware):
|
||||
|
||||
return fans
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_stats: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_stats: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
# X19 method, not sure compatibility
|
||||
if rpc_stats is None:
|
||||
try:
|
||||
|
||||
@@ -109,7 +109,7 @@ class BMMiner(StockFirmware):
|
||||
|
||||
return self.fw_ver
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
# get hr from API
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
@@ -223,7 +223,9 @@ class BMMiner(StockFirmware):
|
||||
|
||||
return fans
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_stats: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_stats: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
# X19 method, not sure compatibility
|
||||
if rpc_stats is None:
|
||||
try:
|
||||
|
||||
@@ -26,6 +26,7 @@ from pyasic.config import MinerConfig
|
||||
from pyasic.config.mining import MiningModePowerTune
|
||||
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
|
||||
from pyasic.data.error_codes import BraiinsOSError, MinerErrorData
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
from pyasic.errors import APIError
|
||||
from pyasic.miners.data import (
|
||||
DataFunction,
|
||||
@@ -39,7 +40,6 @@ from pyasic.rpc.bosminer import BOSMinerRPCAPI
|
||||
from pyasic.ssh.braiins_os import BOSMinerSSH
|
||||
from pyasic.web.braiins_os import BOSerWebAPI, BOSMinerWebAPI
|
||||
from pyasic.web.braiins_os.proto.braiins.bos.v1 import SaveAction
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
|
||||
BOSMINER_DATA_LOC = DataLocations(
|
||||
**{
|
||||
@@ -349,7 +349,7 @@ class BOSMiner(BraiinsOSFirmware):
|
||||
return None
|
||||
return hostname
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
@@ -525,7 +525,9 @@ class BOSMiner(BraiinsOSFirmware):
|
||||
except (TypeError, AttributeError):
|
||||
return self.light
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_devs: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_devs: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if rpc_devs is None:
|
||||
try:
|
||||
rpc_devs = await self.rpc.devs()
|
||||
@@ -600,14 +602,12 @@ class BOSMiner(BraiinsOSFirmware):
|
||||
url=pool_info.get("URL"),
|
||||
user=pool_info.get("User"),
|
||||
index=pool_info.get("POOL"),
|
||||
|
||||
)
|
||||
pools_data.append(pool_data)
|
||||
except LookupError:
|
||||
pass
|
||||
return pools_data
|
||||
|
||||
|
||||
async def upgrade_firmware(self, file: Path):
|
||||
"""
|
||||
Upgrade the firmware of the BOSMiner device.
|
||||
@@ -866,7 +866,7 @@ class BOSer(BraiinsOSFirmware):
|
||||
except LookupError:
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
@@ -883,7 +883,7 @@ class BOSer(BraiinsOSFirmware):
|
||||
|
||||
async def _get_expected_hashrate(
|
||||
self, grpc_miner_details: dict = None
|
||||
) -> Optional[float]:
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if grpc_miner_details is None:
|
||||
try:
|
||||
grpc_miner_details = await self.web.get_miner_details()
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
import logging
|
||||
from typing import List, Optional
|
||||
import aiofiles
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
import aiofiles
|
||||
|
||||
from pyasic.config import MinerConfig, MiningModeConfig
|
||||
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
|
||||
@@ -388,7 +389,7 @@ class BTMiner(StockFirmware):
|
||||
|
||||
return hostname
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
@@ -564,7 +565,9 @@ class BTMiner(StockFirmware):
|
||||
pass
|
||||
return errors
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_summary: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
@@ -675,17 +678,24 @@ class BTMiner(StockFirmware):
|
||||
|
||||
result = await self.rpc.update_firmware(upgrade_contents)
|
||||
|
||||
logging.info("Firmware upgrade process completed successfully for Whatsminer.")
|
||||
logging.info(
|
||||
"Firmware upgrade process completed successfully for Whatsminer."
|
||||
)
|
||||
return result
|
||||
except FileNotFoundError as e:
|
||||
logging.error(f"File not found during the firmware upgrade process: {e}")
|
||||
raise
|
||||
except ValueError as e:
|
||||
logging.error(f"Validation error occurred during the firmware upgrade process: {e}")
|
||||
logging.error(
|
||||
f"Validation error occurred during the firmware upgrade process: {e}"
|
||||
)
|
||||
raise
|
||||
except OSError as e:
|
||||
logging.error(f"OS error occurred during the firmware upgrade process: {e}")
|
||||
raise
|
||||
except Exception as e:
|
||||
logging.error(f"An unexpected error occurred during the firmware upgrade process: {e}", exc_info=True)
|
||||
logging.error(
|
||||
f"An unexpected error occurred during the firmware upgrade process: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
raise
|
||||
|
||||
@@ -109,7 +109,7 @@ class CGMiner(StockFirmware):
|
||||
|
||||
return self.fw_ver
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
|
||||
@@ -19,9 +19,9 @@ from typing import List, Optional
|
||||
from pyasic.config import MinerConfig
|
||||
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
|
||||
from pyasic.data.error_codes import MinerErrorData, X19Error
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
from pyasic.errors import APIError
|
||||
from pyasic.logger import logger
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, WebAPICommand
|
||||
from pyasic.miners.device.firmware import ePICFirmware
|
||||
from pyasic.web.epic import ePICWebAPI
|
||||
@@ -220,7 +220,7 @@ class ePIC(ePICFirmware):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self, web_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, web_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if web_summary is None:
|
||||
try:
|
||||
web_summary = await self.web.summary()
|
||||
@@ -239,7 +239,9 @@ class ePIC(ePICFirmware):
|
||||
except (LookupError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
async def _get_expected_hashrate(self, web_summary: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, web_summary: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if web_summary is None:
|
||||
try:
|
||||
web_summary = await self.web.summary()
|
||||
|
||||
@@ -169,7 +169,7 @@ class Innosilicon(CGMiner):
|
||||
|
||||
async def _get_hashrate(
|
||||
self, rpc_summary: dict = None, web_get_all: dict = None
|
||||
) -> Optional[float]:
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if web_get_all:
|
||||
web_get_all = web_get_all["all"]
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ class LUXMiner(LuxOSFirmware):
|
||||
|
||||
return mac
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
rpc_summary = await self.rpc.summary()
|
||||
@@ -263,7 +263,9 @@ class LUXMiner(LuxOSFirmware):
|
||||
fans.append(Fan())
|
||||
return fans
|
||||
|
||||
async def _get_expected_hashrate(self, rpc_stats: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, rpc_stats: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if rpc_stats is None:
|
||||
try:
|
||||
rpc_stats = await self.rpc.stats()
|
||||
|
||||
@@ -225,7 +225,7 @@ class MaraMiner(MaraFirmware):
|
||||
except LookupError:
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self, web_brief: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, web_brief: dict = None) -> Optional[AlgoHashRate]:
|
||||
if web_brief is None:
|
||||
try:
|
||||
web_brief = await self.web.brief()
|
||||
@@ -271,7 +271,9 @@ class MaraMiner(MaraFirmware):
|
||||
pass
|
||||
return False
|
||||
|
||||
async def _get_expected_hashrate(self, web_brief: dict = None) -> Optional[float]:
|
||||
async def _get_expected_hashrate(
|
||||
self, web_brief: dict = None
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if web_brief is None:
|
||||
try:
|
||||
web_brief = await self.web.brief()
|
||||
@@ -288,7 +290,7 @@ class MaraMiner(MaraFirmware):
|
||||
|
||||
async def _get_wattage_limit(
|
||||
self, web_miner_config: dict = None
|
||||
) -> Optional[float]:
|
||||
) -> Optional[AlgoHashRate]:
|
||||
if web_miner_config is None:
|
||||
try:
|
||||
web_miner_config = await self.web.get_miner_config()
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from pyasic.config import MinerConfig
|
||||
from pyasic.data import Fan, HashBoard
|
||||
from pyasic.data import AlgoHashRate, Fan, HashBoard
|
||||
from pyasic.data.error_codes import MinerErrorData
|
||||
from pyasic.miners.base import BaseMiner
|
||||
from pyasic.rpc.unknown import UnknownRPCAPI
|
||||
@@ -80,7 +80,7 @@ class UnknownMiner(BaseMiner):
|
||||
async def _get_hostname(self) -> Optional[str]:
|
||||
return None
|
||||
|
||||
async def _get_hashrate(self) -> Optional[float]:
|
||||
async def _get_hashrate(self) -> Optional[AlgoHashRate]:
|
||||
return None
|
||||
|
||||
async def _get_hashboards(self) -> List[HashBoard]:
|
||||
@@ -113,7 +113,7 @@ class UnknownMiner(BaseMiner):
|
||||
async def _get_fault_light(self) -> bool:
|
||||
return False
|
||||
|
||||
async def _get_expected_hashrate(self) -> Optional[float]:
|
||||
async def _get_expected_hashrate(self) -> Optional[AlgoHashRate]:
|
||||
return None
|
||||
|
||||
async def _is_mining(self, *args, **kwargs) -> Optional[bool]:
|
||||
|
||||
@@ -193,7 +193,7 @@ class VNish(VNishFirmware, BMMiner):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[float]:
|
||||
async def _get_hashrate(self, rpc_summary: dict = None) -> Optional[AlgoHashRate]:
|
||||
# get hr from API
|
||||
if rpc_summary is None:
|
||||
try:
|
||||
|
||||
@@ -19,7 +19,7 @@ import warnings
|
||||
from typing import List, Optional, Protocol, Tuple, Type, TypeVar, Union
|
||||
|
||||
from pyasic.config import MinerConfig
|
||||
from pyasic.data import Fan, HashBoard, MinerData
|
||||
from pyasic.data import AlgoHashRate, Fan, HashBoard, MinerData
|
||||
from pyasic.data.device import DeviceInfo
|
||||
from pyasic.data.error_codes import MinerErrorData
|
||||
from pyasic.data.pools import PoolMetrics
|
||||
@@ -238,7 +238,7 @@ class MinerProtocol(Protocol):
|
||||
"""
|
||||
return await self._get_hostname()
|
||||
|
||||
async def get_hashrate(self) -> Optional[float]:
|
||||
async def get_hashrate(self) -> Optional[AlgoHashRate]:
|
||||
"""Get the hashrate of the miner and return it as a float in TH/s.
|
||||
|
||||
Returns:
|
||||
@@ -318,7 +318,7 @@ class MinerProtocol(Protocol):
|
||||
"""
|
||||
return await self._get_fault_light()
|
||||
|
||||
async def get_expected_hashrate(self) -> Optional[float]:
|
||||
async def get_expected_hashrate(self) -> Optional[AlgoHashRate]:
|
||||
"""Get the nominal hashrate from factory if available.
|
||||
|
||||
Returns:
|
||||
@@ -362,7 +362,7 @@ class MinerProtocol(Protocol):
|
||||
async def _get_hostname(self) -> Optional[str]:
|
||||
pass
|
||||
|
||||
async def _get_hashrate(self) -> Optional[float]:
|
||||
async def _get_hashrate(self) -> Optional[AlgoHashRate]:
|
||||
pass
|
||||
|
||||
async def _get_hashboards(self) -> List[HashBoard]:
|
||||
@@ -392,7 +392,7 @@ class MinerProtocol(Protocol):
|
||||
async def _get_fault_light(self) -> Optional[bool]:
|
||||
pass
|
||||
|
||||
async def _get_expected_hashrate(self) -> Optional[float]:
|
||||
async def _get_expected_hashrate(self) -> Optional[AlgoHashRate]:
|
||||
pass
|
||||
|
||||
async def _is_mining(self) -> Optional[bool]:
|
||||
@@ -561,4 +561,4 @@ class BaseMiner(MinerProtocol):
|
||||
self.ssh = self._ssh_cls(ip)
|
||||
|
||||
|
||||
AnyMiner = TypeVar("AnyMiner", bound=BaseMiner)
|
||||
AnyMiner = TypeVar("AnyMiner", bound=BaseMiner)
|
||||
|
||||
@@ -55,7 +55,6 @@ class MinersTest(unittest.TestCase):
|
||||
"expected_hashrate",
|
||||
"uptime",
|
||||
"wattage",
|
||||
"voltage",
|
||||
"wattage_limit",
|
||||
"pools",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user