fixes, changes, and formatting

This commit is contained in:
John-Paul Compagnone
2023-12-23 15:01:42 -05:00
parent 07f92557c6
commit 2e28060e05
10 changed files with 166 additions and 121 deletions

View File

@@ -160,13 +160,15 @@ 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))
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,16 +115,16 @@ 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:
try:
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:
except KeyError:
return cls.default()
@classmethod

View File

@@ -185,19 +185,29 @@ 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"))
try:
work_mode = web_conf["PerpetualTune"]["Running"]
if work_mode:
if (
web_conf["PerpetualTune"]["Algorithm"].get("VoltageOptimizer")
is not None
):
return cls.hashrate_tuning(
web_conf["PerpetualTune"]["Algorithm"]["VoltageOptimizer"][
"Target"
]
)
else:
return cls.hashrate_tuning(web_conf["PerpetualTune"]["Algorithm"]["ChipTune"].get("Target"))
return cls.hashrate_tuning(
web_conf["PerpetualTune"]["Algorithm"]["ChipTune"]["Target"]
)
else:
return cls.normal()
return cls.default()
except KeyError:
return cls.default()
@classmethod
def from_bosminer(cls, toml_conf: dict):

View File

@@ -107,10 +107,12 @@ 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"])
return cls(
url=api_pool["pool"], user=api_pool["login"], password=api_pool["password"]
)
@classmethod
def from_am_modern(cls, web_pool: dict) -> "Pool":
@@ -240,7 +242,7 @@ 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 = []
@@ -344,7 +346,7 @@ 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"]

View File

@@ -56,21 +56,18 @@ 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"]
dangerous_temp = None
try:
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:
except KeyError:
hot_temp = None
# Need to do this in two blocks to avoid KeyError if one is missing
try:
target_temp = web_conf["Fans"]["Fan Mode"]["Auto"]["Target Temperature"]
except KeyError:
target_temp = None
if web_conf.get("Misc") is not None:
return cls(
target=target_temp,
hot=hot_temp,
danger=dangerous_temp
)
return cls(target=target_temp, hot=hot_temp, danger=dangerous_temp)

View File

@@ -161,9 +161,9 @@ class MinerData:
percent_expected_wattage: float = field(init=False)
nominal: bool = field(init=False)
config: MinerConfig = None
errors: List[
Union[WhatsminerError, BraiinsOSError, X19Error, InnosiliconError]
] = field(default_factory=list)
errors: List[Union[WhatsminerError, BraiinsOSError, X19Error, InnosiliconError]] = (
field(default_factory=list)
)
fault_light: Union[bool, None] = None
efficiency: int = field(init=False)
is_mining: bool = True

View File

@@ -537,7 +537,7 @@ class BOSMiner(BaseMiner):
pass
try:
async with (await self._get_ssh_connection()) as conn:
async with await self._get_ssh_connection() as conn:
if conn is not None:
data = await conn.run("cat /proc/sys/kernel/hostname")
host = data.stdout.strip()

View File

@@ -74,12 +74,12 @@ 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:
except APIError as e:
logger.warning(e)
except LookupError:
pass
@@ -91,7 +91,7 @@ class ePIC(BMMiner):
self.config = cfg
return self.config
async def restart_backend(self) -> bool:
data = await self.web.restart_epic()
if data:

View File

@@ -189,11 +189,13 @@ class BOSMinerGQLAPI:
await client.post(
url,
json={
"query": 'mutation{auth{login(username:"'
+ "root"
+ '", password:"'
+ self.pwd
+ '"){__typename}}}'
"query": (
'mutation{auth{login(username:"'
+ "root"
+ '", password:"'
+ self.pwd
+ '"){__typename}}}'
)
},
)
@@ -233,7 +235,9 @@ class BOSMinerLuCIAPI:
login = {"luci_username": self.username, "luci_password": self.pwd}
url = f"http://{self.ip}/cgi-bin/luci"
headers = {
"User-Agent": "BTC Tools v0.1", # only seems to respond if this user-agent is set
"User-Agent": (
"BTC Tools v0.1"
), # only seems to respond if this user-agent is set
"Content-Type": "application/x-www-form-urlencoded",
}
await session.post(url, headers=headers, data=login)

View File

@@ -2357,17 +2357,21 @@ class ActionsServiceBase(ServiceBase):
RebootRequest,
RebootResponse,
),
"/braiins.bos.v1.ActionsService/SetLocateDeviceStatus": grpclib.const.Handler(
self.__rpc_set_locate_device_status,
grpclib.const.Cardinality.UNARY_UNARY,
SetLocateDeviceStatusRequest,
LocateDeviceStatusResponse,
"/braiins.bos.v1.ActionsService/SetLocateDeviceStatus": (
grpclib.const.Handler(
self.__rpc_set_locate_device_status,
grpclib.const.Cardinality.UNARY_UNARY,
SetLocateDeviceStatusRequest,
LocateDeviceStatusResponse,
)
),
"/braiins.bos.v1.ActionsService/GetLocateDeviceStatus": grpclib.const.Handler(
self.__rpc_get_locate_device_status,
grpclib.const.Cardinality.UNARY_UNARY,
GetLocateDeviceStatusRequest,
LocateDeviceStatusResponse,
"/braiins.bos.v1.ActionsService/GetLocateDeviceStatus": (
grpclib.const.Handler(
self.__rpc_get_locate_device_status,
grpclib.const.Cardinality.UNARY_UNARY,
GetLocateDeviceStatusRequest,
LocateDeviceStatusResponse,
)
),
}
@@ -2644,17 +2648,21 @@ class PerformanceServiceBase(ServiceBase):
GetTunerStateRequest,
GetTunerStateResponse,
),
"/braiins.bos.v1.PerformanceService/ListTargetProfiles": grpclib.const.Handler(
self.__rpc_list_target_profiles,
grpclib.const.Cardinality.UNARY_UNARY,
ListTargetProfilesRequest,
ListTargetProfilesResponse,
"/braiins.bos.v1.PerformanceService/ListTargetProfiles": (
grpclib.const.Handler(
self.__rpc_list_target_profiles,
grpclib.const.Cardinality.UNARY_UNARY,
ListTargetProfilesRequest,
ListTargetProfilesResponse,
)
),
"/braiins.bos.v1.PerformanceService/SetDefaultPowerTarget": grpclib.const.Handler(
self.__rpc_set_default_power_target,
grpclib.const.Cardinality.UNARY_UNARY,
SetDefaultPowerTargetRequest,
SetPowerTargetResponse,
"/braiins.bos.v1.PerformanceService/SetDefaultPowerTarget": (
grpclib.const.Handler(
self.__rpc_set_default_power_target,
grpclib.const.Cardinality.UNARY_UNARY,
SetDefaultPowerTargetRequest,
SetPowerTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/SetPowerTarget": grpclib.const.Handler(
self.__rpc_set_power_target,
@@ -2662,41 +2670,53 @@ class PerformanceServiceBase(ServiceBase):
SetPowerTargetRequest,
SetPowerTargetResponse,
),
"/braiins.bos.v1.PerformanceService/IncrementPowerTarget": grpclib.const.Handler(
self.__rpc_increment_power_target,
grpclib.const.Cardinality.UNARY_UNARY,
IncrementPowerTargetRequest,
SetPowerTargetResponse,
"/braiins.bos.v1.PerformanceService/IncrementPowerTarget": (
grpclib.const.Handler(
self.__rpc_increment_power_target,
grpclib.const.Cardinality.UNARY_UNARY,
IncrementPowerTargetRequest,
SetPowerTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/DecrementPowerTarget": grpclib.const.Handler(
self.__rpc_decrement_power_target,
grpclib.const.Cardinality.UNARY_UNARY,
DecrementPowerTargetRequest,
SetPowerTargetResponse,
"/braiins.bos.v1.PerformanceService/DecrementPowerTarget": (
grpclib.const.Handler(
self.__rpc_decrement_power_target,
grpclib.const.Cardinality.UNARY_UNARY,
DecrementPowerTargetRequest,
SetPowerTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/SetDefaultHashrateTarget": grpclib.const.Handler(
self.__rpc_set_default_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
SetDefaultHashrateTargetRequest,
SetHashrateTargetResponse,
"/braiins.bos.v1.PerformanceService/SetDefaultHashrateTarget": (
grpclib.const.Handler(
self.__rpc_set_default_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
SetDefaultHashrateTargetRequest,
SetHashrateTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/SetHashrateTarget": grpclib.const.Handler(
self.__rpc_set_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
SetHashrateTargetRequest,
SetHashrateTargetResponse,
"/braiins.bos.v1.PerformanceService/SetHashrateTarget": (
grpclib.const.Handler(
self.__rpc_set_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
SetHashrateTargetRequest,
SetHashrateTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/IncrementHashrateTarget": grpclib.const.Handler(
self.__rpc_increment_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
IncrementHashrateTargetRequest,
SetHashrateTargetResponse,
"/braiins.bos.v1.PerformanceService/IncrementHashrateTarget": (
grpclib.const.Handler(
self.__rpc_increment_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
IncrementHashrateTargetRequest,
SetHashrateTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/DecrementHashrateTarget": grpclib.const.Handler(
self.__rpc_decrement_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
DecrementHashrateTargetRequest,
SetHashrateTargetResponse,
"/braiins.bos.v1.PerformanceService/DecrementHashrateTarget": (
grpclib.const.Handler(
self.__rpc_decrement_hashrate_target,
grpclib.const.Cardinality.UNARY_UNARY,
DecrementHashrateTargetRequest,
SetHashrateTargetResponse,
)
),
"/braiins.bos.v1.PerformanceService/SetDPS": grpclib.const.Handler(
self.__rpc_set_dps,
@@ -2704,23 +2724,29 @@ class PerformanceServiceBase(ServiceBase):
SetDpsRequest,
SetDpsResponse,
),
"/braiins.bos.v1.PerformanceService/SetPerformanceMode": grpclib.const.Handler(
self.__rpc_set_performance_mode,
grpclib.const.Cardinality.UNARY_UNARY,
SetPerformanceModeRequest,
PerformanceMode,
"/braiins.bos.v1.PerformanceService/SetPerformanceMode": (
grpclib.const.Handler(
self.__rpc_set_performance_mode,
grpclib.const.Cardinality.UNARY_UNARY,
SetPerformanceModeRequest,
PerformanceMode,
)
),
"/braiins.bos.v1.PerformanceService/GetActivePerformanceMode": grpclib.const.Handler(
self.__rpc_get_active_performance_mode,
grpclib.const.Cardinality.UNARY_UNARY,
GetPerformanceModeRequest,
PerformanceMode,
"/braiins.bos.v1.PerformanceService/GetActivePerformanceMode": (
grpclib.const.Handler(
self.__rpc_get_active_performance_mode,
grpclib.const.Cardinality.UNARY_UNARY,
GetPerformanceModeRequest,
PerformanceMode,
)
),
"/braiins.bos.v1.PerformanceService/RemoveTunedProfiles": grpclib.const.Handler(
self.__rpc_remove_tuned_profiles,
grpclib.const.Cardinality.UNARY_UNARY,
RemoveTunedProfilesRequest,
RemoveTunedProfilesResponse,
"/braiins.bos.v1.PerformanceService/RemoveTunedProfiles": (
grpclib.const.Handler(
self.__rpc_remove_tuned_profiles,
grpclib.const.Cardinality.UNARY_UNARY,
RemoveTunedProfilesRequest,
RemoveTunedProfilesResponse,
)
),
}
@@ -2836,17 +2862,21 @@ class ConfigurationServiceBase(ServiceBase):
def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
return {
"/braiins.bos.v1.ConfigurationService/GetMinerConfiguration": grpclib.const.Handler(
self.__rpc_get_miner_configuration,
grpclib.const.Cardinality.UNARY_UNARY,
GetMinerConfigurationRequest,
GetMinerConfigurationResponse,
"/braiins.bos.v1.ConfigurationService/GetMinerConfiguration": (
grpclib.const.Handler(
self.__rpc_get_miner_configuration,
grpclib.const.Cardinality.UNARY_UNARY,
GetMinerConfigurationRequest,
GetMinerConfigurationResponse,
)
),
"/braiins.bos.v1.ConfigurationService/GetConstraints": grpclib.const.Handler(
self.__rpc_get_constraints,
grpclib.const.Cardinality.UNARY_UNARY,
GetConstraintsRequest,
GetConstraintsResponse,
"/braiins.bos.v1.ConfigurationService/GetConstraints": (
grpclib.const.Handler(
self.__rpc_get_constraints,
grpclib.const.Cardinality.UNARY_UNARY,
GetConstraintsRequest,
GetConstraintsResponse,
)
),
}