feature: add allow_warning to get_data to allow suppressing warnings.

This commit is contained in:
Upstream Data
2022-11-07 20:35:23 -07:00
parent 2c7e0e3efe
commit 997a1bbe31
15 changed files with 30 additions and 28 deletions

View File

@@ -72,11 +72,12 @@ If you are sure you want to use this command please use API.send_command("{comma
) )
return return_commands return return_commands
async def multicommand(self, *commands: str) -> dict: async def multicommand(self, *commands: str, 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:
*commands: The commands to send as a multicommand to the miner. *commands: The commands to send as a multicommand to the miner.
allow_warning: A boolean to supress APIWarnings.
""" """
logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}") logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}")
# make sure we can actually run each command, otherwise they will fail # make sure we can actually run each command, otherwise they will fail
@@ -85,7 +86,7 @@ If you are sure you want to use this command please use API.send_command("{comma
# doesn't work for S19 which uses the backup _x19_multicommand # doesn't work for S19 which uses the backup _x19_multicommand
command = "+".join(commands) command = "+".join(commands)
try: try:
data = await self.send_command(command) data = await self.send_command(command, allow_warning=allow_warning)
except APIError: except APIError:
return {} return {}
logging.debug(f"{self.ip}: Received multicommand data.") logging.debug(f"{self.ip}: Received multicommand data.")

View File

@@ -39,7 +39,7 @@ class BMMinerAPI(BaseMinerAPI):
super().__init__(ip, port) super().__init__(ip, port)
async def multicommand( async def multicommand(
self, *commands: str, ignore_x19_error: bool = False self, *commands: str, allow_warning: bool = True
) -> dict: ) -> dict:
logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}") logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}")
# make sure we can actually run each command, otherwise they will fail # make sure we can actually run each command, otherwise they will fail
@@ -48,7 +48,7 @@ class BMMinerAPI(BaseMinerAPI):
# doesn't work for S19 which uses the backup _x19_multicommand # doesn't work for S19 which uses the backup _x19_multicommand
command = "+".join(commands) command = "+".join(commands)
try: try:
data = await self.send_command(command, allow_warning=not ignore_x19_error) data = await self.send_command(command, allow_warning=allow_warning)
except APIError: except APIError:
logging.debug(f"{self.ip}: Handling X19 multicommand.") logging.debug(f"{self.ip}: Handling X19 multicommand.")
data = await self._x19_multicommand(*command.split("+")) data = await self._x19_multicommand(*command.split("+"))

View File

@@ -39,7 +39,7 @@ class CGMinerAPI(BaseMinerAPI):
super().__init__(ip, port) super().__init__(ip, port)
async def multicommand( async def multicommand(
self, *commands: str, ignore_x19_error: bool = False self, *commands: str, allow_warning: bool = True
) -> dict: ) -> dict:
logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}") logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}")
# make sure we can actually run each command, otherwise they will fail # make sure we can actually run each command, otherwise they will fail
@@ -48,7 +48,7 @@ class CGMinerAPI(BaseMinerAPI):
# doesnt work for S19 which uses the backup _x19_multicommand # doesnt work for S19 which uses the backup _x19_multicommand
command = "+".join(commands) command = "+".join(commands)
try: try:
data = await self.send_command(command, allow_warning=ignore_x19_error) data = await self.send_command(command, allow_warning=allow_warning)
except APIError: except APIError:
logging.debug(f"{self.ip}: Handling X19 multicommand.") logging.debug(f"{self.ip}: Handling X19 multicommand.")
data = await self._x19_multicommand(*command.split("+")) data = await self._x19_multicommand(*command.split("+"))

View File

@@ -185,7 +185,7 @@ class BMMiner(BaseMiner):
async def resume_mining(self) -> bool: async def resume_mining(self) -> bool:
return False return False
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = False) -> MinerData:
"""Get data from the miner. """Get data from the miner.
Returns: Returns:
@@ -223,7 +223,7 @@ class BMMiner(BaseMiner):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"summary", "pools", "stats", ignore_x19_error=True "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -297,7 +297,7 @@ class BOSMiner(BaseMiner):
) )
return errors return errors
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = True) -> MinerData:
"""Get data from the miner. """Get data from the miner.
Returns: Returns:
@@ -342,6 +342,7 @@ class BOSMiner(BaseMiner):
"devdetails", "devdetails",
"fans", "fans",
"devs", "devs",
allow_warning=allow_warning
) )
except APIError as e: except APIError as e:
if str(e.message) == "Not ready": if str(e.message) == "Not ready":

View File

@@ -241,7 +241,7 @@ class BTMiner(BaseMiner):
cfg = cfg.from_api(pools["POOLS"]) cfg = cfg.from_api(pools["POOLS"])
return cfg return cfg
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = True) -> MinerData:
"""Get data from the miner. """Get data from the miner.
Returns: Returns:
@@ -280,7 +280,7 @@ class BTMiner(BaseMiner):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
try: try:
miner_data = await self.api.multicommand("summary", "devs", "pools") miner_data = await self.api.multicommand("summary", "devs", "pools", allow_warning=allow_warning)
if miner_data: if miner_data:
break break
except APIError: except APIError:

View File

@@ -173,7 +173,7 @@ class CGMiner(BaseMiner):
async def get_mac(self) -> str: async def get_mac(self) -> str:
return "00:00:00:00:00:00" return "00:00:00:00:00:00"
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = False) -> MinerData:
"""Get data from the miner. """Get data from the miner.
Returns: Returns:
@@ -206,7 +206,7 @@ class CGMiner(BaseMiner):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"summary", "pools", "stats", "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -33,7 +33,7 @@ class HiveonT9(Hiveon, T9):
) )
return mac return mac
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = False) -> MinerData:
"""Get data from the miner. """Get data from the miner.
Returns: Returns:
@@ -71,7 +71,7 @@ class HiveonT9(Hiveon, T9):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"summary", "pools", "stats", ignore_x19_error=True "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -14,7 +14,7 @@
from pyasic.miners._backends import CGMiner # noqa - Ignore access to _module from pyasic.miners._backends import CGMiner # noqa - Ignore access to _module
from pyasic.data import MinerData from pyasic.data import MinerData, HashBoard
from pyasic.settings import PyasicSettings from pyasic.settings import PyasicSettings
import re import re
from pyasic.config import MinerConfig from pyasic.config import MinerConfig
@@ -80,7 +80,7 @@ class CGMinerA10X(CGMiner):
) )
return mac return mac
async def get_data(self): async def get_data(self, allow_warning: bool = True):
data = MinerData( data = MinerData(
ip=str(self.ip), ip=str(self.ip),
ideal_chips=self.nominal_chips * self.ideal_hashboards, ideal_chips=self.nominal_chips * self.ideal_hashboards,
@@ -100,7 +100,7 @@ class CGMinerA10X(CGMiner):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"version", "summary", "pools", "stats" "version", "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -80,7 +80,7 @@ class CGMinerA7X(CGMiner):
) )
return mac return mac
async def get_data(self): async def get_data(self, allow_warning: bool = True):
data = MinerData( data = MinerData(
ip=str(self.ip), ip=str(self.ip),
ideal_chips=self.nominal_chips * self.ideal_hashboards, ideal_chips=self.nominal_chips * self.ideal_hashboards,
@@ -100,7 +100,7 @@ class CGMinerA7X(CGMiner):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"version", "summary", "pools", "stats" "version", "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -80,7 +80,7 @@ class CGMinerA8X(CGMiner):
) )
return mac return mac
async def get_data(self): async def get_data(self, allow_warning: bool = True):
data = MinerData( data = MinerData(
ip=str(self.ip), ip=str(self.ip),
ideal_chips=self.nominal_chips * self.ideal_hashboards, ideal_chips=self.nominal_chips * self.ideal_hashboards,
@@ -100,7 +100,7 @@ class CGMinerA8X(CGMiner):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"version", "summary", "pools", "stats" "version", "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -81,7 +81,7 @@ class CGMinerAvalon921(CGMiner, Avalon921):
) )
return mac return mac
async def get_data(self): async def get_data(self, allow_warning: bool = True):
data = MinerData( data = MinerData(
ip=str(self.ip), ip=str(self.ip),
ideal_chips=self.nominal_chips * self.ideal_hashboards, ideal_chips=self.nominal_chips * self.ideal_hashboards,
@@ -103,7 +103,7 @@ class CGMinerAvalon921(CGMiner, Avalon921):
miner_data = None miner_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"version", "summary", "pools", "stats" "version", "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:
break break

View File

@@ -192,7 +192,7 @@ class BaseMiner(ABC):
pass pass
@abstractmethod @abstractmethod
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = True) -> MinerData:
"""Get data from the miner in the form of [`MinerData`][pyasic.data.MinerData]. """Get data from the miner in the form of [`MinerData`][pyasic.data.MinerData].
Returns: Returns:

View File

@@ -157,7 +157,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
errors.append(InnosiliconError(error_code=err)) errors.append(InnosiliconError(error_code=err))
return errors return errors
async def get_data(self) -> MinerData: async def get_data(self, allow_warning: bool = False) -> MinerData:
data = MinerData( data = MinerData(
ip=str(self.ip), ip=str(self.ip),
ideal_chips=self.nominal_chips * self.ideal_hashboards, ideal_chips=self.nominal_chips * self.ideal_hashboards,
@@ -187,7 +187,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
all_data = None all_data = None
for i in range(PyasicSettings().miner_get_data_retries): for i in range(PyasicSettings().miner_get_data_retries):
miner_data = await self.api.multicommand( miner_data = await self.api.multicommand(
"summary", "pools", "stats", ignore_x19_error=True "summary", "pools", "stats", allow_warning=allow_warning
) )
if miner_data: if miner_data:

View File

@@ -72,5 +72,5 @@ class UnknownMiner(BaseMiner):
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None: async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
return None return None
async def get_data(self) -> MinerData: async def get_data(self, _) -> MinerData:
return MinerData(ip=str(self.ip)) return MinerData(ip=str(self.ip))