feature: Update get and send config methods for most miners, and add as_inno.

This commit is contained in:
Upstream Data
2023-12-10 10:10:55 -07:00
parent b22b506d55
commit 9ee63cc3ab
11 changed files with 45 additions and 26 deletions

View File

@@ -88,7 +88,6 @@ class MinerConfig:
}
def as_bosminer(self, user_suffix: str = None):
return {
**merge(self.fan_mode.as_bosminer(), self.temperature.as_bosminer()),
**self.mining_mode.as_bosminer(),
@@ -105,7 +104,7 @@ class MinerConfig:
return cls(
pools=PoolConfig.from_am_modern(web_conf),
mining_mode=MiningModeConfig.from_am_modern(web_conf),
fan_mode=FanModeConfig.from_am_modern(web_conf)
fan_mode=FanModeConfig.from_am_modern(web_conf),
)
@classmethod
@@ -114,9 +113,11 @@ class MinerConfig:
@classmethod
def from_goldshell(cls, web_conf: dict):
return cls(
pools=PoolConfig.from_am_modern(web_conf),
)
return cls(pools=PoolConfig.from_am_modern(web_conf))
@classmethod
def from_inno(cls, web_pools: dict):
return cls(pools=PoolConfig.from_inno(web_pools))
def merge(a: dict, b: dict):

View File

@@ -108,12 +108,20 @@ class Pool(MinerConfigValue):
url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]
)
# TODO: check if this is accurate, user/username, pass/password
@classmethod
def from_goldshell(cls, web_pool: dict):
return cls(
url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]
)
# TODO: check if this is accurate, user/username, pass/password
@classmethod
def from_inno(cls, web_pool: dict):
return cls(
url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]
)
@dataclass
class PoolGroup(MinerConfigValue):
@@ -194,7 +202,7 @@ class PoolGroup(MinerConfigValue):
pool.as_bosminer(user_suffix=user_suffix) for pool in self.pools
],
}
return {"name": "Group", "quota": 1, "pool": [Pool.as_bosminer()]}
return {"name": "Group", "quota": 1, "pool": []}
@classmethod
def from_api(cls, api_pool_list: list):
@@ -214,6 +222,10 @@ class PoolGroup(MinerConfigValue):
def from_goldshell(cls, web_pools: list):
return cls([Pool.from_goldshell(p) for p in web_pools])
@classmethod
def from_inno(cls, web_pools: list):
return cls([Pool.from_inno(p) for p in web_pools])
@dataclass
class PoolConfig(MinerConfigValue):
@@ -285,3 +297,9 @@ class PoolConfig(MinerConfigValue):
@classmethod
def from_goldshell(cls, web_pools: list):
return cls([PoolGroup.from_goldshell(web_pools)])
@classmethod
def from_inno(cls, web_pools: list):
return cls([PoolGroup.from_inno(web_pools)])

View File

@@ -18,7 +18,7 @@ import asyncio
from typing import List, Optional, Union
from pyasic.API import APIError
from pyasic.config import MinerConfig
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, X19Error
from pyasic.miners.backends.bmminer import BMMiner
@@ -120,13 +120,13 @@ class AntminerModern(BMMiner):
async def stop_mining(self) -> bool:
cfg = await self.get_config()
cfg.miner_mode = X19PowerMode.Sleep
cfg.miner_mode = MiningModeConfig.sleep
await self.send_config(cfg)
return True
async def resume_mining(self) -> bool:
cfg = await self.get_config()
cfg.miner_mode = X19PowerMode.Normal
cfg.miner_mode = MiningModeConfig.normal
await self.send_config(cfg)
return True

View File

@@ -72,7 +72,7 @@ class BFGMiner(BaseMiner):
except APIError:
return self.config
self.config = MinerConfig().from_api(pools["POOLS"])
self.config = MinerConfig.from_api(pools)
return self.config
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:

View File

@@ -64,7 +64,14 @@ class BFGMinerGoldshell(BFGMiner):
self.data_locations = GOLDSHELL_DATA_LOC
async def get_config(self) -> MinerConfig:
return MinerConfig.from_goldshell(await self.web.pools())
# get pool data
try:
pools = await self.web.pools()
except APIError:
return self.config
self.config = MinerConfig.from_goldshell(pools)
return self.config
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
pools_data = await self.web.pools()

View File

@@ -104,7 +104,7 @@ class BMMiner(BaseMiner):
except APIError:
return self.config
self.config = MinerConfig().from_api(pools["POOLS"])
self.config = MinerConfig.from_api(pools)
return self.config
async def reboot(self) -> bool:

View File

@@ -316,7 +316,7 @@ class BOSMiner(BaseMiner):
(await conn.run("cat /etc/bosminer.toml")).stdout
)
logging.debug(f"{self}: Converting config file.")
cfg = MinerConfig().from_raw(toml_data)
cfg = MinerConfig.from_raw(toml_data)
self.config = cfg
return self.config

View File

@@ -197,10 +197,7 @@ class BTMiner(BaseMiner):
try:
await self.api.update_pools(**pools_conf)
except APIError:
pass
try:
if conf["mode"] == "normal":
await self.api.set_normal_power()
elif conf["mode"] == "high":

View File

@@ -143,10 +143,13 @@ class CGMiner(BaseMiner):
return True
async def get_config(self) -> MinerConfig:
api_pools = await self.api.pools()
# get pool data
try:
pools = await self.api.pools()
except APIError:
return self.config
if api_pools:
self.config = MinerConfig().from_api(api_pools["POOLS"])
self.config = MinerConfig.from_api(pools)
return self.config
async def fault_light_off(self) -> bool:

View File

@@ -100,7 +100,6 @@ class CGMinerAvalon(CGMiner):
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
"""Configures miner with yaml config."""
self.config = config
return None
logging.debug(f"{self}: Sending config.") # noqa - This doesnt work...

View File

@@ -196,15 +196,9 @@ class LUXMiner(BaseMiner):
return False
async def get_config(self) -> MinerConfig:
"""Gets the config for the miner and sets it as `self.config`.
Returns:
The config from `self.config`.
"""
return self.config
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
"""Configures miner with yaml config."""
pass
async def set_power_limit(self, wattage: int) -> bool: