feature: add set_power_limit to all miners that support it.

This commit is contained in:
UpstreamData
2022-11-30 10:47:45 -07:00
parent e9f54eec0a
commit 16399510fa
9 changed files with 58 additions and 4 deletions

View File

@@ -117,10 +117,11 @@ These functions are
[`get_hostname`](#get-hostname),
[`get_model`](#get-model),
[`reboot`](#reboot),
[`restart_backend`](#restart-backend), and
[`stop_mining`](#stop-mining), and
[`resume_mining`](#resume-mining), and
[`send_config`](#send-config).
[`restart_backend`](#restart-backend),
[`stop_mining`](#stop-mining),
[`resume_mining`](#resume-mining),
[`send_config`](#send-config), and
[`set_power_limit`](#set-power-limit).
<br>
@@ -228,6 +229,14 @@ These functions are
<br>
### Set Power Limit
::: pyasic.miners.BaseMiner.set_power_limit
handler: python
options:
heading_level: 4
<br>
## [`MinerConfig`][pyasic.config.MinerConfig] and [`MinerData`][pyasic.data.MinerData]
Pyasic implements a few dataclasses as helpers to make data return types consistent across different miners and miner APIs. The different fields of these dataclasses can all be viewed with the classmethod `cls.fields()`.

View File

@@ -349,3 +349,7 @@ class BMMiner(BaseMiner):
data.pool_split = str(quota)
return data
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -671,3 +671,14 @@ class BOSMiner(BaseMiner):
async def get_mac(self):
result = await self.send_ssh_command("cat /sys/class/net/eth0/address")
return result.upper().strip()
async def set_power_limit(self, wattage: int) -> bool:
try:
cfg = await self.get_config()
cfg.autotuning_wattage = wattage
await self.send_config(cfg)
except Exception as e:
logging.warning(f"{self} set_power_limit: {e}")
return False
else:
return True

View File

@@ -106,3 +106,6 @@ class BOSMinerOld(BaseMiner):
async def get_data(self, **kwargs) -> MinerData:
return MinerData(ip=str(self.ip))
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -438,3 +438,13 @@ class BTMiner(BaseMiner):
data.mac = mac
return data
async def set_power_limit(self, wattage: int) -> bool:
try:
await self.api.adjust_power_limit(wattage)
except Exception as e:
logging.warning(f"{self} set_power_limit: {e}")
return False
else:
return True

View File

@@ -335,3 +335,6 @@ class CGMiner(BaseMiner):
data.pool_split = str(quota)
return data
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -61,3 +61,6 @@ class Hiveon(BMMiner):
bad_boards[board] = []
bad_boards[board].append(chain)
return bad_boards
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -216,4 +216,12 @@ class BaseMiner(ABC):
pass
@abstractmethod
async def set_power_limit(self, wattage: int) -> bool:
"""Set the power limit to be used by the miner.
Returns:
A boolean value of the success of setting the power limit.
"""
AnyMiner = TypeVar("AnyMiner", bound=BaseMiner)

View File

@@ -74,3 +74,6 @@ class UnknownMiner(BaseMiner):
async def get_data(self, allow_warning: bool = False) -> MinerData:
return MinerData(ip=str(self.ip))
async def set_power_limit(self, wattage: int) -> bool:
return False