feature: add config sending for bitaxe.
This commit is contained in:
@@ -140,6 +140,14 @@ class MinerConfig:
|
|||||||
**self.pools.as_mara(user_suffix=user_suffix),
|
**self.pools.as_mara(user_suffix=user_suffix),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def as_bitaxe(self, user_suffix: str = None) -> dict:
|
||||||
|
return {
|
||||||
|
**self.fan_mode.as_bitaxe(),
|
||||||
|
**self.temperature.as_bitaxe(),
|
||||||
|
**self.mining_mode.as_bitaxe(),
|
||||||
|
**self.pools.as_bitaxe(user_suffix=user_suffix),
|
||||||
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, dict_conf: dict) -> "MinerConfig":
|
def from_dict(cls, dict_conf: dict) -> "MinerConfig":
|
||||||
"""Constructs a MinerConfig object from a dictionary."""
|
"""Constructs a MinerConfig object from a dictionary."""
|
||||||
@@ -240,6 +248,5 @@ class MinerConfig:
|
|||||||
def from_bitaxe(cls, web_system_info: dict) -> "MinerConfig":
|
def from_bitaxe(cls, web_system_info: dict) -> "MinerConfig":
|
||||||
return cls(
|
return cls(
|
||||||
pools=PoolConfig.from_bitaxe(web_system_info),
|
pools=PoolConfig.from_bitaxe(web_system_info),
|
||||||
fan_mode=FanModeConfig.from_bitaxe(web_system_info)
|
fan_mode=FanModeConfig.from_bitaxe(web_system_info),
|
||||||
|
)
|
||||||
)
|
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ class MinerConfigOption(Enum):
|
|||||||
def as_mara(self) -> dict:
|
def as_mara(self) -> dict:
|
||||||
return self.value.as_mara()
|
return self.value.as_mara()
|
||||||
|
|
||||||
|
def as_bitaxe(self) -> dict:
|
||||||
|
return self.value.as_bitaxe()
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.value(*args, **kwargs)
|
return self.value(*args, **kwargs)
|
||||||
|
|
||||||
@@ -119,6 +122,9 @@ class MinerConfigValue:
|
|||||||
def as_mara(self) -> dict:
|
def as_mara(self) -> dict:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def as_bitaxe(self) -> dict:
|
||||||
|
return {}
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
try:
|
try:
|
||||||
return getattr(self, item)
|
return getattr(self, item)
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ class FanModeNormal(MinerConfigValue):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def as_bitaxe(self) -> dict:
|
||||||
|
return {"autoFanspeed": 1}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FanModeManual(MinerConfigValue):
|
class FanModeManual(MinerConfigValue):
|
||||||
@@ -138,6 +141,9 @@ class FanModeManual(MinerConfigValue):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def as_bitaxe(self) -> dict:
|
||||||
|
return {"autoFanspeed": 0, "fanspeed": self.speed}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FanModeImmersion(MinerConfigValue):
|
class FanModeImmersion(MinerConfigValue):
|
||||||
@@ -297,4 +303,4 @@ class FanModeConfig(MinerConfigOption):
|
|||||||
if web_system_info["autofanspeed"] == 1:
|
if web_system_info["autofanspeed"] == 1:
|
||||||
return cls.normal()
|
return cls.normal()
|
||||||
else:
|
else:
|
||||||
return cls.manual(speed=web_system_info["fanspeed"])
|
return cls.manual(speed=web_system_info["fanspeed"])
|
||||||
|
|||||||
@@ -127,6 +127,13 @@ class Pool(MinerConfigValue):
|
|||||||
}
|
}
|
||||||
return {"url": self.url, "user": self.user, "pass": self.password}
|
return {"url": self.url, "user": self.user, "pass": self.password}
|
||||||
|
|
||||||
|
def as_bitaxe(self, user_suffix: str = None) -> dict:
|
||||||
|
return {
|
||||||
|
"stratumURL": self.url,
|
||||||
|
"stratumUser": f"{self.user}{user_suffix}",
|
||||||
|
"stratumPassword": self.password,
|
||||||
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, dict_conf: dict | None) -> "Pool":
|
def from_dict(cls, dict_conf: dict | None) -> "Pool":
|
||||||
return cls(
|
return cls(
|
||||||
@@ -197,7 +204,11 @@ class Pool(MinerConfigValue):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_bitaxe(cls, web_system_info: dict) -> "Pool":
|
def from_bitaxe(cls, web_system_info: dict) -> "Pool":
|
||||||
url = f"stratum+tcp://{web_system_info['stratumURL']}:{web_system_info['stratumPort']}"
|
url = f"stratum+tcp://{web_system_info['stratumURL']}:{web_system_info['stratumPort']}"
|
||||||
return cls(url=url, user=web_system_info["stratumUser"], password=web_system_info.get("stratumPassword", ""))
|
return cls(
|
||||||
|
url=url,
|
||||||
|
user=web_system_info["stratumUser"],
|
||||||
|
password=web_system_info.get("stratumPassword", ""),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -292,6 +303,9 @@ class PoolGroup(MinerConfigValue):
|
|||||||
def as_mara(self, user_suffix: str = None) -> list:
|
def as_mara(self, user_suffix: str = None) -> list:
|
||||||
return [p.as_mara(user_suffix=user_suffix) for p in self.pools]
|
return [p.as_mara(user_suffix=user_suffix) for p in self.pools]
|
||||||
|
|
||||||
|
def as_bitaxe(self, user_suffix: str = None) -> dict:
|
||||||
|
return self.pools[0].as_bitaxe(user_suffix=user_suffix)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, dict_conf: dict | None) -> "PoolGroup":
|
def from_dict(cls, dict_conf: dict | None) -> "PoolGroup":
|
||||||
cls_conf = {}
|
cls_conf = {}
|
||||||
@@ -465,6 +479,9 @@ class PoolConfig(MinerConfigValue):
|
|||||||
return {"pools": self.groups[0].as_mara(user_suffix=user_suffix)}
|
return {"pools": self.groups[0].as_mara(user_suffix=user_suffix)}
|
||||||
return {"pools": []}
|
return {"pools": []}
|
||||||
|
|
||||||
|
def as_bitaxe(self, user_suffix: str = None) -> dict:
|
||||||
|
return self.groups[0].as_bitaxe(user_suffix=user_suffix)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_api(cls, api_pools: dict) -> "PoolConfig":
|
def from_api(cls, api_pools: dict) -> "PoolConfig":
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ class BitAxe(BaseMiner):
|
|||||||
web_system_info = await self.web.system_info()
|
web_system_info = await self.web.system_info()
|
||||||
return MinerConfig.from_bitaxe(web_system_info)
|
return MinerConfig.from_bitaxe(web_system_info)
|
||||||
|
|
||||||
|
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
|
||||||
|
await self.web.update_settings(**config.as_bitaxe())
|
||||||
|
|
||||||
async def _get_wattage(self, web_system_info: dict = None) -> Optional[int]:
|
async def _get_wattage(self, web_system_info: dict = None) -> Optional[int]:
|
||||||
if web_system_info is None:
|
if web_system_info is None:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -25,11 +25,19 @@ class BitAxeWebAPI(BaseWebAPI):
|
|||||||
transport=settings.transport(),
|
transport=settings.transport(),
|
||||||
) as client:
|
) as client:
|
||||||
if parameters.get("post", False):
|
if parameters.get("post", False):
|
||||||
|
parameters.pop("post")
|
||||||
data = await client.post(
|
data = await client.post(
|
||||||
url,
|
url,
|
||||||
timeout=settings.get("api_function_timeout", 3),
|
timeout=settings.get("api_function_timeout", 3),
|
||||||
json=parameters,
|
json=parameters,
|
||||||
)
|
)
|
||||||
|
elif parameters.get("patch", False):
|
||||||
|
parameters.pop("patch")
|
||||||
|
data = await client.patch(
|
||||||
|
url,
|
||||||
|
timeout=settings.get("api_function_timeout", 3),
|
||||||
|
json=parameters,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
data = await client.get(url)
|
data = await client.get(url)
|
||||||
except httpx.HTTPError:
|
except httpx.HTTPError:
|
||||||
@@ -83,3 +91,6 @@ class BitAxeWebAPI(BaseWebAPI):
|
|||||||
|
|
||||||
async def restart(self):
|
async def restart(self):
|
||||||
return await self.send_command("system/restart", post=True)
|
return await self.send_command("system/restart", post=True)
|
||||||
|
|
||||||
|
async def update_settings(self, **config):
|
||||||
|
return await self.send_command("system", patch=True, **config)
|
||||||
|
|||||||
Reference in New Issue
Block a user