feature: swap from @dataclass to pydantic BaseModel (#238)

* feature: switch almost everything to pydantic BaseModel

* feature: swap more dataclasses over to pydantic models

* feature: use more model serializers to make data handle better

* bug: fix some serialization issues with `None` values

* bug: fix some initialization problems with miner mode config

* bug: fix new BOS+ pool parsing

* bug: fix new BOS+ board temperature parsing serialization error

* bug: more misc fixes with serialization, extra methods, and hashrate types

* bug: add explicit type conversions to hashrate types

* bug: fix epic pool URL parsing

* bug: fix positional args in hashboards

* bug: fix epic missing url scheme

* convert board temp to int

---------

Co-authored-by: Upstream Data <brett@upstreamdata.ca>
Co-authored-by: John-Paul Compagnone <jpcompagnone@epicblockchain.io>
This commit is contained in:
Brett Rowan
2024-11-20 13:42:41 -07:00
committed by GitHub
parent 65ed565220
commit d66739e2c9
46 changed files with 597 additions and 485 deletions

View File

@@ -179,14 +179,15 @@ class LUXMiner(LuxOSFirmware):
if rpc_summary is not None:
try:
return AlgoHashRate.SHA256(
rpc_summary["SUMMARY"][0]["GHS 5s"], HashUnit.SHA256.GH
rate=float(rpc_summary["SUMMARY"][0]["GHS 5s"]),
unit=HashUnit.SHA256.GH,
).into(self.algo.unit.default)
except (LookupError, ValueError, TypeError):
pass
async def _get_hashboards(self, rpc_stats: dict = None) -> List[HashBoard]:
hashboards = [
HashBoard(idx, expected_chips=self.expected_chips)
HashBoard(slot=idx, expected_chips=self.expected_chips)
for idx in range(self.expected_hashboards)
]
@@ -202,7 +203,8 @@ class LUXMiner(LuxOSFirmware):
for idx in range(3):
board_n = idx + 1
hashboards[idx].hashrate = AlgoHashRate.SHA256(
float(board_stats[f"chain_rate{board_n}"]), HashUnit.SHA256.GH
rate=float(board_stats[f"chain_rate{board_n}"]),
unit=HashUnit.SHA256.GH,
).into(self.algo.unit.default)
hashboards[idx].chips = int(board_stats[f"chain_acn{board_n}"])
chip_temp_data = list(
@@ -253,7 +255,7 @@ class LUXMiner(LuxOSFirmware):
if rpc_fans is not None:
for fan in range(self.expected_fans):
try:
fans.append(Fan(rpc_fans["FANS"][fan]["RPM"]))
fans.append(Fan(speed=rpc_fans["FANS"][fan]["RPM"]))
except (LookupError, ValueError, TypeError):
fans.append(Fan())
return fans
@@ -275,7 +277,7 @@ class LUXMiner(LuxOSFirmware):
except KeyError:
rate_unit = "GH"
return AlgoHashRate.SHA256(
expected_rate, HashUnit.SHA256.from_str(rate_unit)
rate=float(expected_rate), unit=HashUnit.SHA256.from_str(rate_unit)
).into(self.algo.unit.default)
except LookupError:
pass