From 03990941973b9928edcd743d547e57fcda8c16b9 Mon Sep 17 00:00:00 2001 From: Upstream Data Date: Sun, 10 Dec 2023 09:45:34 -0700 Subject: [PATCH] feature: add AM old and goldshell configs. --- pyasic/config/__init__.py | 9 ++++++ pyasic/config/pools.py | 29 ++++++++++++-------- pyasic/miners/backends/antminer.py | 4 +-- pyasic/miners/backends/bfgminer_goldshell.py | 4 +-- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/pyasic/config/__init__.py b/pyasic/config/__init__.py index 7530de8f..24f55916 100644 --- a/pyasic/config/__init__.py +++ b/pyasic/config/__init__.py @@ -108,6 +108,15 @@ class MinerConfig: fan_mode=FanModeConfig.from_am_modern(web_conf) ) + @classmethod + def from_am_old(cls, web_conf: dict): + return cls.from_am_modern(web_conf) + + @classmethod + def from_goldshell(cls, web_conf: dict): + return cls( + pools=PoolConfig.from_am_modern(web_conf), + ) def merge(a: dict, b: dict): diff --git a/pyasic/config/pools.py b/pyasic/config/pools.py index 250f4d89..5cae3c07 100644 --- a/pyasic/config/pools.py +++ b/pyasic/config/pools.py @@ -89,7 +89,6 @@ class Pool(MinerConfigValue): f"Password{idx}": self.password, } - def as_bosminer(self, user_suffix: str = None): if user_suffix is not None: return { @@ -105,7 +104,15 @@ class Pool(MinerConfigValue): @classmethod def from_am_modern(cls, web_pool: dict): - return cls(url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"]) + return cls( + url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"] + ) + + @classmethod + def from_goldshell(cls, web_pool: dict): + return cls( + url=web_pool["url"], user=web_pool["user"], password=web_pool["pass"] + ) @dataclass @@ -158,15 +165,7 @@ class PoolGroup(MinerConfigValue): return pools def as_goldshell(self, user_suffix: str = None) -> list: - pools = [] - idx = 0 - while idx < 3: - if len(self.pools) > idx: - pools.append(self.pools[idx].as_am_modern(user_suffix=user_suffix)) - else: - pools.append(Pool("", "", "").as_am_modern()) - idx += 1 - return pools + return [pool.as_goldshell(user_suffix) for pool in self.pools] def as_avalon(self, user_suffix: str = None) -> dict: if len(self.pools) > 0: @@ -211,6 +210,9 @@ class PoolGroup(MinerConfigValue): pools.append(Pool.from_am_modern(pool)) return cls(pools=pools) + @classmethod + def from_goldshell(cls, web_pools: list): + return cls([Pool.from_goldshell(p) for p in web_pools]) @dataclass @@ -260,7 +262,6 @@ class PoolConfig(MinerConfigValue): return self.groups[0].as_inno(user_suffix=user_suffix) return PoolGroup().as_inno() - def as_bosminer(self, user_suffix: str = None) -> dict: if len(self.groups) > 0: return { @@ -280,3 +281,7 @@ class PoolConfig(MinerConfigValue): pool_data = web_conf["pools"] return cls([PoolGroup.from_am_modern(pool_data)]) + + @classmethod + def from_goldshell(cls, web_pools: list): + return cls([PoolGroup.from_goldshell(web_pools)]) diff --git a/pyasic/miners/backends/antminer.py b/pyasic/miners/backends/antminer.py index abd696b4..bbe967a4 100644 --- a/pyasic/miners/backends/antminer.py +++ b/pyasic/miners/backends/antminer.py @@ -349,11 +349,11 @@ class AntminerOld(CGMiner): async def get_config(self) -> MinerConfig: data = await self.web.get_miner_conf() if data: - self.config = MinerConfig().from_raw(data) + self.config = MinerConfig.from_am_old(data) return self.config async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None: - await self.web.set_miner_conf(config.as_x17(user_suffix=user_suffix)) + await self.web.set_miner_conf(config.as_am_old(user_suffix=user_suffix)) async def get_mac(self) -> Union[str, None]: try: diff --git a/pyasic/miners/backends/bfgminer_goldshell.py b/pyasic/miners/backends/bfgminer_goldshell.py index 5d9e81dc..bf080e3c 100644 --- a/pyasic/miners/backends/bfgminer_goldshell.py +++ b/pyasic/miners/backends/bfgminer_goldshell.py @@ -64,7 +64,7 @@ class BFGMinerGoldshell(BFGMiner): self.data_locations = GOLDSHELL_DATA_LOC async def get_config(self) -> MinerConfig: - return MinerConfig().from_raw(await self.web.pools()) + return MinerConfig.from_goldshell(await self.web.pools()) async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None: pools_data = await self.web.pools() @@ -80,7 +80,7 @@ class BFGMinerGoldshell(BFGMiner): self.config = config # send them back 1 at a time - for pool in config.as_goldshell(user_suffix=user_suffix): + for pool in config.as_goldshell(user_suffix=user_suffix)["pools"]: await self.web.newpool( url=pool["url"], user=pool["user"], password=pool["pass"] )