feature: Update get and send config methods for most miners, and add as_inno.
This commit is contained in:
@@ -88,7 +88,6 @@ class MinerConfig:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def as_bosminer(self, user_suffix: str = None):
|
def as_bosminer(self, user_suffix: str = None):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
**merge(self.fan_mode.as_bosminer(), self.temperature.as_bosminer()),
|
**merge(self.fan_mode.as_bosminer(), self.temperature.as_bosminer()),
|
||||||
**self.mining_mode.as_bosminer(),
|
**self.mining_mode.as_bosminer(),
|
||||||
@@ -105,7 +104,7 @@ class MinerConfig:
|
|||||||
return cls(
|
return cls(
|
||||||
pools=PoolConfig.from_am_modern(web_conf),
|
pools=PoolConfig.from_am_modern(web_conf),
|
||||||
mining_mode=MiningModeConfig.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
|
@classmethod
|
||||||
@@ -114,9 +113,11 @@ class MinerConfig:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_goldshell(cls, web_conf: dict):
|
def from_goldshell(cls, web_conf: dict):
|
||||||
return cls(
|
return cls(pools=PoolConfig.from_am_modern(web_conf))
|
||||||
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):
|
def merge(a: dict, b: dict):
|
||||||
|
|||||||
@@ -108,12 +108,20 @@ class Pool(MinerConfigValue):
|
|||||||
url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]
|
url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: check if this is accurate, user/username, pass/password
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_goldshell(cls, web_pool: dict):
|
def from_goldshell(cls, web_pool: dict):
|
||||||
return cls(
|
return cls(
|
||||||
url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]
|
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
|
@dataclass
|
||||||
class PoolGroup(MinerConfigValue):
|
class PoolGroup(MinerConfigValue):
|
||||||
@@ -194,7 +202,7 @@ class PoolGroup(MinerConfigValue):
|
|||||||
pool.as_bosminer(user_suffix=user_suffix) for pool in self.pools
|
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
|
@classmethod
|
||||||
def from_api(cls, api_pool_list: list):
|
def from_api(cls, api_pool_list: list):
|
||||||
@@ -214,6 +222,10 @@ class PoolGroup(MinerConfigValue):
|
|||||||
def from_goldshell(cls, web_pools: list):
|
def from_goldshell(cls, web_pools: list):
|
||||||
return cls([Pool.from_goldshell(p) for p in web_pools])
|
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
|
@dataclass
|
||||||
class PoolConfig(MinerConfigValue):
|
class PoolConfig(MinerConfigValue):
|
||||||
@@ -285,3 +297,9 @@ class PoolConfig(MinerConfigValue):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_goldshell(cls, web_pools: list):
|
def from_goldshell(cls, web_pools: list):
|
||||||
return cls([PoolGroup.from_goldshell(web_pools)])
|
return cls([PoolGroup.from_goldshell(web_pools)])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_inno(cls, web_pools: list):
|
||||||
|
return cls([PoolGroup.from_inno(web_pools)])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import asyncio
|
|||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pyasic.API import APIError
|
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 import Fan, HashBoard
|
||||||
from pyasic.data.error_codes import MinerErrorData, X19Error
|
from pyasic.data.error_codes import MinerErrorData, X19Error
|
||||||
from pyasic.miners.backends.bmminer import BMMiner
|
from pyasic.miners.backends.bmminer import BMMiner
|
||||||
@@ -120,13 +120,13 @@ class AntminerModern(BMMiner):
|
|||||||
|
|
||||||
async def stop_mining(self) -> bool:
|
async def stop_mining(self) -> bool:
|
||||||
cfg = await self.get_config()
|
cfg = await self.get_config()
|
||||||
cfg.miner_mode = X19PowerMode.Sleep
|
cfg.miner_mode = MiningModeConfig.sleep
|
||||||
await self.send_config(cfg)
|
await self.send_config(cfg)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def resume_mining(self) -> bool:
|
async def resume_mining(self) -> bool:
|
||||||
cfg = await self.get_config()
|
cfg = await self.get_config()
|
||||||
cfg.miner_mode = X19PowerMode.Normal
|
cfg.miner_mode = MiningModeConfig.normal
|
||||||
await self.send_config(cfg)
|
await self.send_config(cfg)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class BFGMiner(BaseMiner):
|
|||||||
except APIError:
|
except APIError:
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
self.config = MinerConfig().from_api(pools["POOLS"])
|
self.config = MinerConfig.from_api(pools)
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
||||||
|
|||||||
@@ -64,7 +64,14 @@ class BFGMinerGoldshell(BFGMiner):
|
|||||||
self.data_locations = GOLDSHELL_DATA_LOC
|
self.data_locations = GOLDSHELL_DATA_LOC
|
||||||
|
|
||||||
async def get_config(self) -> MinerConfig:
|
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:
|
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
||||||
pools_data = await self.web.pools()
|
pools_data = await self.web.pools()
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class BMMiner(BaseMiner):
|
|||||||
except APIError:
|
except APIError:
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
self.config = MinerConfig().from_api(pools["POOLS"])
|
self.config = MinerConfig.from_api(pools)
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
async def reboot(self) -> bool:
|
async def reboot(self) -> bool:
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ class BOSMiner(BaseMiner):
|
|||||||
(await conn.run("cat /etc/bosminer.toml")).stdout
|
(await conn.run("cat /etc/bosminer.toml")).stdout
|
||||||
)
|
)
|
||||||
logging.debug(f"{self}: Converting config file.")
|
logging.debug(f"{self}: Converting config file.")
|
||||||
cfg = MinerConfig().from_raw(toml_data)
|
cfg = MinerConfig.from_raw(toml_data)
|
||||||
self.config = cfg
|
self.config = cfg
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
|
|||||||
@@ -197,10 +197,7 @@ class BTMiner(BaseMiner):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await self.api.update_pools(**pools_conf)
|
await self.api.update_pools(**pools_conf)
|
||||||
except APIError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
if conf["mode"] == "normal":
|
if conf["mode"] == "normal":
|
||||||
await self.api.set_normal_power()
|
await self.api.set_normal_power()
|
||||||
elif conf["mode"] == "high":
|
elif conf["mode"] == "high":
|
||||||
|
|||||||
@@ -143,10 +143,13 @@ class CGMiner(BaseMiner):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def get_config(self) -> MinerConfig:
|
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(pools)
|
||||||
self.config = MinerConfig().from_api(api_pools["POOLS"])
|
|
||||||
return self.config
|
return self.config
|
||||||
|
|
||||||
async def fault_light_off(self) -> bool:
|
async def fault_light_off(self) -> bool:
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ class CGMinerAvalon(CGMiner):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
||||||
"""Configures miner with yaml config."""
|
|
||||||
self.config = config
|
self.config = config
|
||||||
return None
|
return None
|
||||||
logging.debug(f"{self}: Sending config.") # noqa - This doesnt work...
|
logging.debug(f"{self}: Sending config.") # noqa - This doesnt work...
|
||||||
|
|||||||
@@ -196,15 +196,9 @@ class LUXMiner(BaseMiner):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async def get_config(self) -> MinerConfig:
|
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
|
return self.config
|
||||||
|
|
||||||
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
||||||
"""Configures miner with yaml config."""
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def set_power_limit(self, wattage: int) -> bool:
|
async def set_power_limit(self, wattage: int) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user