feature: allow dps conversion for bos grpc.
This commit is contained in:
@@ -95,6 +95,15 @@ class MinerConfig:
|
||||
**self.power_scaling.as_bosminer(),
|
||||
}
|
||||
|
||||
def as_bos_grpc(self, user_suffix: str = None):
|
||||
return {
|
||||
**self.fan_mode.as_bos_grpc(),
|
||||
**self.temperature.as_bos_grpc(),
|
||||
**self.mining_mode.as_bos_grpc(),
|
||||
**self.pools.as_bos_grpc(user_suffix=user_suffix),
|
||||
**self.power_scaling.as_bos_grpc(),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_api(cls, api_pools: dict):
|
||||
return cls(pools=PoolConfig.from_api(api_pools))
|
||||
@@ -129,6 +138,7 @@ class MinerConfig:
|
||||
power_scaling=PowerScalingConfig.from_bosminer(toml_conf),
|
||||
)
|
||||
|
||||
|
||||
def merge(a: dict, b: dict):
|
||||
ret = {}
|
||||
for k in a:
|
||||
@@ -163,7 +173,7 @@ if __name__ == "__main__":
|
||||
mining_mode=MiningModeConfig.power_tuning(3000),
|
||||
temperature=TemperatureConfig(hot=100, danger=110),
|
||||
fan_mode=FanModeConfig.manual(minimum_fans=2, speed=70),
|
||||
power_scaling=PowerScalingConfig.enabled(power_step=100, minimum_power=2400)
|
||||
power_scaling=PowerScalingConfig.enabled(power_step=100, minimum_power=2400),
|
||||
)
|
||||
print(config)
|
||||
print("WM:", config.as_wm())
|
||||
@@ -175,6 +185,7 @@ if __name__ == "__main__":
|
||||
print("BOS+ .toml:", config.as_bosminer())
|
||||
print("BOS+ .toml as toml:")
|
||||
print(toml.dumps(config.as_bosminer()))
|
||||
print(config.as_bos_grpc())
|
||||
|
||||
bos_parsed = MinerConfig.from_bosminer(config.as_bosminer())
|
||||
print(bos_parsed)
|
||||
|
||||
@@ -36,7 +36,10 @@ class MinerConfigOption(Enum):
|
||||
return self.value.as_avalon()
|
||||
|
||||
def as_bosminer(self) -> dict:
|
||||
return self.value.as_bos()
|
||||
return self.value.as_bosminer()
|
||||
|
||||
def as_bos_grpc(self) -> dict:
|
||||
return self.value.as_bos_grpc()
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.value(*args, **kwargs)
|
||||
@@ -63,3 +66,6 @@ class MinerConfigValue:
|
||||
|
||||
def as_bosminer(self) -> dict:
|
||||
return {}
|
||||
|
||||
def as_bos_grpc(self) -> dict:
|
||||
return {}
|
||||
|
||||
@@ -131,7 +131,6 @@ class Pool(MinerConfigValue):
|
||||
)
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class PoolGroup(MinerConfigValue):
|
||||
pools: list[Pool] = field(default_factory=list)
|
||||
@@ -301,6 +300,9 @@ class PoolConfig(MinerConfigValue):
|
||||
}
|
||||
return {"group": [PoolGroup().as_bosminer()]}
|
||||
|
||||
def as_bos_grpc(self, user_suffix: str = None) -> dict:
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def from_api(cls, api_pools: dict):
|
||||
pool_data = api_pools["POOLS"]
|
||||
@@ -322,12 +324,9 @@ class PoolConfig(MinerConfigValue):
|
||||
def from_inno(cls, web_pools: list):
|
||||
return cls([PoolGroup.from_inno(web_pools)])
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_bosminer(cls, toml_conf: dict):
|
||||
if toml_conf.get("group") is None:
|
||||
return cls()
|
||||
|
||||
return cls([PoolGroup.from_bosminer(g) for g in toml_conf["group"]])
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from pyasic.config.base import MinerConfigOption, MinerConfigValue
|
||||
from pyasic.web.bosminer.proto.braiins.bos.v1 import DpsPowerTarget, DpsTarget, Hours
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -31,6 +32,14 @@ class PowerScalingShutdownEnabled(MinerConfigValue):
|
||||
|
||||
return cfg
|
||||
|
||||
def as_bos_grpc(self) -> dict:
|
||||
cfg = {"enable_shutdown ": True}
|
||||
|
||||
if self.duration is not None:
|
||||
cfg["shutdown_duration"] = Hours(self.duration)
|
||||
|
||||
return cfg
|
||||
|
||||
|
||||
@dataclass
|
||||
class PowerScalingShutdownDisabled(MinerConfigValue):
|
||||
@@ -39,6 +48,9 @@ class PowerScalingShutdownDisabled(MinerConfigValue):
|
||||
def as_bosminer(self) -> dict:
|
||||
return {"shutdown_enabled": False}
|
||||
|
||||
def as_bos_grpc(self) -> dict:
|
||||
return {"enable_shutdown ": False}
|
||||
|
||||
|
||||
class PowerScalingShutdown(MinerConfigOption):
|
||||
enabled = PowerScalingShutdownEnabled
|
||||
@@ -73,9 +85,7 @@ class PowerScalingEnabled(MinerConfigValue):
|
||||
)
|
||||
|
||||
def as_bosminer(self) -> dict:
|
||||
cfg = {
|
||||
"enabled": True
|
||||
}
|
||||
cfg = {"enabled": True}
|
||||
if self.power_step is not None:
|
||||
cfg["power_step"] = self.power_step
|
||||
if self.minimum_power is not None:
|
||||
@@ -86,6 +96,22 @@ class PowerScalingEnabled(MinerConfigValue):
|
||||
|
||||
return {"power_scaling": cfg}
|
||||
|
||||
def as_bos_grpc(self):
|
||||
cfg = {"enable": True}
|
||||
target_conf = {}
|
||||
if self.power_step is not None:
|
||||
target_conf["power_step"] = self.power_step
|
||||
if self.minimum_power is not None:
|
||||
target_conf["min_power_target"] = self.minimum_power
|
||||
|
||||
cfg["target"] = DpsTarget(power_target=DpsPowerTarget(**target_conf))
|
||||
|
||||
if self.shutdown_enabled is not None:
|
||||
cfg = {**cfg, **self.shutdown_enabled.as_bos_grpc()}
|
||||
|
||||
return {"dps": cfg}
|
||||
|
||||
|
||||
@dataclass
|
||||
class PowerScalingDisabled(MinerConfigValue):
|
||||
mode: str = field(init=False, default="disabled")
|
||||
@@ -110,4 +136,4 @@ class PowerScalingConfig(MinerConfigOption):
|
||||
else:
|
||||
return cls.disabled()
|
||||
|
||||
return cls.default()
|
||||
return cls.default()
|
||||
|
||||
@@ -18,13 +18,15 @@ from datetime import timedelta
|
||||
from typing import Union
|
||||
|
||||
import httpx
|
||||
from betterproto import Message
|
||||
from grpclib.client import Channel
|
||||
|
||||
from pyasic import APIError, settings
|
||||
from pyasic import settings
|
||||
from pyasic.errors import APIError
|
||||
from pyasic.web import BaseWebAPI
|
||||
|
||||
from .proto.braiins.bos import *
|
||||
from .proto.braiins.bos.v1 import *
|
||||
from betterproto import Message
|
||||
|
||||
|
||||
class BOSMinerWebAPI(BaseWebAPI):
|
||||
@@ -534,9 +536,7 @@ class BOSMinerGRPCAPI:
|
||||
)
|
||||
|
||||
async def get_constraints(self):
|
||||
return await self.send_command(
|
||||
"get_constraints", GetConstraintsRequest()
|
||||
)
|
||||
return await self.send_command("get_constraints", GetConstraintsRequest())
|
||||
|
||||
async def get_license_state(self):
|
||||
return await self.send_command("get_license_state", GetLicenseStateRequest())
|
||||
@@ -554,7 +554,9 @@ class BOSMinerGRPCAPI:
|
||||
return await self.send_command("get_hashboards", GetHashboardsRequest())
|
||||
|
||||
async def get_support_archive(self):
|
||||
return await self.send_command("get_support_archive", GetSupportArchiveRequest())
|
||||
return await self.send_command(
|
||||
"get_support_archive", GetSupportArchiveRequest()
|
||||
)
|
||||
|
||||
async def enable_hashboards(
|
||||
self,
|
||||
@@ -562,7 +564,10 @@ class BOSMinerGRPCAPI:
|
||||
save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
|
||||
):
|
||||
return await self.send_command(
|
||||
"enable_hashboards", EnableHashboardsRequest(hashboard_ids=hashboard_ids, save_action=save_action)
|
||||
"enable_hashboards",
|
||||
EnableHashboardsRequest(
|
||||
hashboard_ids=hashboard_ids, save_action=save_action
|
||||
),
|
||||
)
|
||||
|
||||
async def disable_hashboards(
|
||||
@@ -571,5 +576,8 @@ class BOSMinerGRPCAPI:
|
||||
save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
|
||||
):
|
||||
return await self.send_command(
|
||||
"disable_hashboards", DisableHashboardsRequest(hashboard_ids=hashboard_ids, save_action=save_action)
|
||||
"disable_hashboards",
|
||||
DisableHashboardsRequest(
|
||||
hashboard_ids=hashboard_ids, save_action=save_action
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user