add get_config to ePIC backend

This commit is contained in:
John-Paul Compagnone
2023-12-21 01:33:46 -05:00
parent b89ea1fa92
commit 6f6f5743cf
6 changed files with 83 additions and 0 deletions

View File

@@ -160,6 +160,13 @@ class MinerConfig:
temperature=TemperatureConfig.from_bosminer(toml_conf),
power_scaling=PowerScalingConfig.from_bosminer(toml_conf),
)
@classmethod
def from_epic(cls, web_conf: dict) -> "MinerConfig":
return cls(pools=PoolConfig.from_epic(web_conf),
fan_mode=FanModeConfig.from_epic(web_conf),
temperature=TemperatureConfig.from_epic(web_conf),
mining_mode=MiningModeConfig.from_epic(web_conf))
def merge(a: dict, b: dict) -> dict:

View File

@@ -115,6 +115,17 @@ class FanModeConfig(MinerConfigOption):
return cls.normal()
else:
return cls.default()
@classmethod
def from_epic(cls, web_conf: dict):
if web_conf.get("Fans") is not None:
fan_mode = web_conf["Fans"]["Fan Mode"]
if fan_mode.get("Manual") is not None:
return cls.manual(speed=fan_mode.get("Manual"))
else:
return cls.normal()
else:
return cls.default()
@classmethod
def from_bosminer(cls, toml_conf: dict):

View File

@@ -185,6 +185,19 @@ class MiningModeConfig(MinerConfigOption):
elif int(work_mode) == 3:
return cls.low()
return cls.default()
@classmethod
def from_epic(cls, web_conf: dict):
if web_conf.get("PerpetualTune") is not None:
work_mode = web_conf["PerpetualTune"]
if work_mode["Running"] == True:
if web_conf["PerpetualTune"]["Algorithm"].get("VoltageOptimizer") is not None:
return cls.hashrate_tuning(web_conf["PerpetualTune"]["Algorithm"]["VoltageOptimizer"].get("Target"))
else:
return cls.hashrate_tuning()
else:
return cls.normal()
return cls.default()
@classmethod
def from_bosminer(cls, toml_conf: dict):

View File

@@ -107,6 +107,10 @@ class Pool(MinerConfigValue):
@classmethod
def from_api(cls, api_pool: dict) -> "Pool":
return cls(url=api_pool["URL"], user=api_pool["User"], password="x")
@classmethod
def from_epic(cls, api_pool: dict) -> "Pool":
return cls(url=api_pool["pool"].replace("stratum+tcp://", ""), user=api_pool["login"], password=api_pool["password"])
@classmethod
def from_am_modern(cls, web_pool: dict) -> "Pool":
@@ -236,6 +240,13 @@ class PoolGroup(MinerConfigValue):
for pool in api_pool_list:
pools.append(Pool.from_api(pool))
return cls(pools=pools)
@classmethod
def from_epic(cls, api_pool_list: list) -> "PoolGroup":
pools = []
for pool in api_pool_list:
pools.append(Pool.from_epic(pool))
return cls(pools=pools)
@classmethod
def from_am_modern(cls, web_pool_list: list) -> "PoolGroup":
@@ -333,6 +344,11 @@ class PoolConfig(MinerConfigValue):
pool_data = sorted(pool_data, key=lambda x: int(x["POOL"]))
return cls([PoolGroup.from_api(pool_data)])
@classmethod
def from_epic(cls, web_conf: dict) -> "PoolConfig":
pool_data = web_conf["StratumConfigs"]
return cls([PoolGroup.from_epic(pool_data)])
@classmethod
def from_am_modern(cls, web_conf: dict) -> "PoolConfig":

View File

@@ -56,3 +56,21 @@ class TemperatureConfig(MinerConfigValue):
hot=temp_control.get("hot_temp"),
danger=temp_control.get("dangerous_temp"),
)
@classmethod
def from_epic(cls, web_conf: dict) -> "TemperatureConfig":
## we only have a target temp if we are in auto-fan mode, so
## we need to check for that
if web_conf.get("Misc") is not None:
target_temp = web_conf["Misc"]["Shutdown Temp"]
hot_temp = web_conf["Misc"]["Shutdown Temp"]
dangerous_temp = web_conf["Misc"]["Shutdown Temp"]
if web_conf["Fans"]["Fan Mode"].get("Auto") is not None:
target_temp = web_conf["Fans"]["Fan Mode"]["Auto"]["Target Temperature"]
if web_conf.get("Misc") is not None:
return cls(
target=target_temp,
hot=hot_temp,
danger=dangerous_temp
)

View File

@@ -18,6 +18,7 @@ from typing import List, Optional, Tuple, Union
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, X19Error
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.errors import APIError
from pyasic.logger import logger
from pyasic.miners.backends.bmminer import BMMiner
@@ -73,7 +74,24 @@ class ePIC(BMMiner):
if self.model is not None:
return self.model + " (ePIC)"
return "? (ePIC)"
async def get_config(self) -> MinerConfig:
summary = None
try:
summary = await self.web.summary()
except APIError as e:
logger.warning(e)
except LookupError:
pass
if summary is not None:
cfg = MinerConfig.from_epic(summary)
else:
cfg = MinerConfig()
self.config = cfg
return self.config
async def restart_backend(self) -> bool:
data = await self.web.restart_epic()
if data: