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

@@ -14,14 +14,14 @@
# limitations under the License. -
# ------------------------------------------------------------------------------
from dataclasses import dataclass
from typing import Any
from .hashrate import AlgoHashRate
from pydantic import BaseModel, field_serializer
from .hashrate import AlgoHashRateType
@dataclass
class HashBoard:
class HashBoard(BaseModel):
"""A Dataclass to standardize hashboard data.
Attributes:
@@ -39,16 +39,21 @@ class HashBoard:
"""
slot: int = 0
hashrate: AlgoHashRate = None
temp: int = None
chip_temp: int = None
chips: int = None
expected_chips: int = None
serial_number: str = None
hashrate: AlgoHashRateType | None = None
temp: int | None = None
chip_temp: int | None = None
chips: int | None = None
expected_chips: int | None = None
serial_number: str | None = None
missing: bool = True
tuned: bool = None
active: bool = None
voltage: float = None
tuned: bool | None = None
active: bool | None = None
voltage: float | None = None
@field_serializer("hashrate")
def serialize_hashrate(self, hashrate: AlgoHashRateType | None) -> float:
if hashrate is not None:
return float(hashrate)
def get(self, __key: str, default: Any = None):
try: