refactor: fix some formatting issues and bugs.

This commit is contained in:
UpstreamData
2024-01-15 14:18:41 -07:00
parent ce34dfdde8
commit edaf89c73a
9 changed files with 18 additions and 28 deletions

View File

@@ -20,7 +20,6 @@ from pyasic.config.base import MinerConfigOption, MinerConfigValue
from pyasic.web.braiins_os.proto.braiins.bos.v1 import ( from pyasic.web.braiins_os.proto.braiins.bos.v1 import (
DpsPowerTarget, DpsPowerTarget,
DpsTarget, DpsTarget,
Hours,
Power, Power,
SetDpsRequest, SetDpsRequest,
) )
@@ -210,9 +209,8 @@ class PowerScalingConfig(MinerConfigOption):
except LookupError: except LookupError:
return cls.default() return cls.default()
conf = {} conf = {"shutdown_enabled": PowerScalingShutdown.from_boser(dps_conf)}
conf["shutdown_enabled"] = PowerScalingShutdown.from_boser(dps_conf)
if dps_conf.get("minPowerTarget") is not None: if dps_conf.get("minPowerTarget") is not None:
conf["minimum_power"] = dps_conf["minPowerTarget"]["watt"] conf["minimum_power"] = dps_conf["minPowerTarget"]["watt"]
if dps_conf.get("powerStep") is not None: if dps_conf.get("powerStep") is not None:

View File

@@ -16,8 +16,7 @@
import asyncio import asyncio
import logging import logging
import time import time
from collections import namedtuple from typing import List, Optional, Union
from typing import List, Optional, Tuple, Union
import toml import toml
@@ -32,7 +31,6 @@ from pyasic.miners.base import (
DataFunction, DataFunction,
DataLocations, DataLocations,
DataOptions, DataOptions,
GraphQLCommand,
GRPCCommand, GRPCCommand,
RPCAPICommand, RPCAPICommand,
WebAPICommand, WebAPICommand,
@@ -537,13 +535,13 @@ class BOSMiner(BaseMiner):
if api_fans: if api_fans:
fans = [] fans = []
for n in range(self.fan_count): for n in range(self.expected_fans):
try: try:
fans.append(Fan(api_fans["FANS"][n]["RPM"])) fans.append(Fan(api_fans["FANS"][n]["RPM"]))
except (IndexError, KeyError): except (IndexError, KeyError):
pass pass
return fans return fans
return [Fan() for _ in range(self.fan_count)] return [Fan() for _ in range(self.expected_fans)]
async def _get_fan_psu(self) -> Optional[int]: async def _get_fan_psu(self) -> Optional[int]:
return None return None
@@ -978,13 +976,13 @@ class BOSer(BaseMiner):
if grpc_cooling_state: if grpc_cooling_state:
fans = [] fans = []
for n in range(self.fan_count): for n in range(self.expected_fans):
try: try:
fans.append(Fan(grpc_cooling_state["fans"][n]["rpm"])) fans.append(Fan(grpc_cooling_state["fans"][n]["rpm"]))
except (IndexError, KeyError): except (IndexError, KeyError):
pass pass
return fans return fans
return [Fan() for _ in range(self.fan_count)] return [Fan() for _ in range(self.expected_fans)]
async def _get_fan_psu(self) -> Optional[int]: async def _get_fan_psu(self) -> Optional[int]:
return None return None

View File

@@ -14,7 +14,6 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import logging
import re import re
from typing import List, Optional from typing import List, Optional
@@ -315,7 +314,7 @@ class CGMinerAvalon(CGMiner):
except APIError: except APIError:
pass pass
fans_data = [Fan() for _ in range(self.fan_count)] fans_data = [Fan() for _ in range(self.expected_fans)]
if api_stats: if api_stats:
try: try:
unparsed_stats = api_stats["STATS"][0]["MM ID0"] unparsed_stats = api_stats["STATS"][0]["MM ID0"]
@@ -323,7 +322,7 @@ class CGMinerAvalon(CGMiner):
except LookupError: except LookupError:
return fans_data return fans_data
for fan in range(self.fan_count): for fan in range(self.expected_fans):
try: try:
fans_data[fan].speed = int(parsed_stats[f"Fan{fan + 1}"]) fans_data[fan].speed = int(parsed_stats[f"Fan{fan + 1}"])
except (IndexError, KeyError, ValueError, TypeError): except (IndexError, KeyError, ValueError, TypeError):

View File

@@ -188,7 +188,7 @@ class ePIC(BaseMiner):
if web_summary: if web_summary:
try: try:
hashrate = 0 hashrate = 0
if web_summary["HBs"] != None: if web_summary["HBs"] is not None:
for hb in web_summary["HBs"]: for hb in web_summary["HBs"]:
hashrate += hb["Hashrate"][0] hashrate += hb["Hashrate"][0]
return round(float(float(hashrate / 1000000)), 2) return round(float(float(hashrate / 1000000)), 2)
@@ -207,7 +207,7 @@ class ePIC(BaseMiner):
if web_summary: if web_summary:
try: try:
hashrate = 0 hashrate = 0
if web_summary["HBs"] != None: if web_summary["HBs"] is not None:
for hb in web_summary["HBs"]: for hb in web_summary["HBs"]:
if hb["Hashrate"][1] == 0: if hb["Hashrate"][1] == 0:
ideal = 1.0 ideal = 1.0
@@ -266,7 +266,7 @@ class ePIC(BaseMiner):
HashBoard(slot=i, expected_chips=self.expected_chips) HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards) for i in range(self.expected_hashboards)
] ]
if web_summary["HBs"] != None: if web_summary["HBs"] is not None:
for hb in web_summary["HBs"]: for hb in web_summary["HBs"]:
for hr in web_hashrate: for hr in web_hashrate:
if hr["Index"] == hb["Index"]: if hr["Index"] == hb["Index"]:
@@ -312,7 +312,7 @@ class ePIC(BaseMiner):
if web_summary: if web_summary:
try: try:
error = web_summary["Status"]["Last Error"] error = web_summary["Status"]["Last Error"]
if error != None: if error is not None:
errors.append(X19Error(str(error))) errors.append(X19Error(str(error)))
return errors return errors
except KeyError: except KeyError:
@@ -328,9 +328,6 @@ class ePIC(BaseMiner):
def _get_api_ver(self, *args, **kwargs) -> Optional[str]: def _get_api_ver(self, *args, **kwargs) -> Optional[str]:
pass pass
def get_config(self) -> MinerConfig:
return self.config
def _get_env_temp(self, *args, **kwargs) -> Optional[float]: def _get_env_temp(self, *args, **kwargs) -> Optional[float]:
pass pass

View File

@@ -340,7 +340,7 @@ class Innosilicon(CGMiner):
else: else:
web_get_all = web_get_all["all"] web_get_all = web_get_all["all"]
fans = [Fan() for _ in range(self.fan_count)] fans = [Fan() for _ in range(self.expected_fans)]
if web_get_all: if web_get_all:
try: try:
spd = web_get_all["fansSpeed"] spd = web_get_all["fansSpeed"]
@@ -348,7 +348,7 @@ class Innosilicon(CGMiner):
pass pass
else: else:
round((int(spd) * 6000) / 100) round((int(spd) * 6000) / 100)
for i in range(self.fan_count): for i in range(self.expected_fans):
fans[i].speed = spd fans[i].speed = spd
return fans return fans

View File

@@ -476,6 +476,7 @@ class MinerFactory:
fn = miner_model_fns.get(miner_type) fn = miner_model_fns.get(miner_type)
if fn is not None: if fn is not None:
# noinspection PyArgumentList
task = asyncio.create_task(fn(ip)) task = asyncio.create_task(fn(ip))
try: try:
miner_model = await asyncio.wait_for( miner_model = await asyncio.wait_for(

View File

@@ -33,7 +33,6 @@ class UnknownMiner(BaseMiner):
super().__init__(ip) super().__init__(ip)
self.ip = ip self.ip = ip
self.api = UnknownAPI(ip) self.api = UnknownAPI(ip)
self.model = "Unknown"
def __repr__(self) -> str: def __repr__(self) -> str:
return f"Unknown: {str(self.ip)}" return f"Unknown: {str(self.ip)}"

View File

@@ -89,10 +89,10 @@ class ePICWebAPI(BaseWebAPI):
return data return data
async def restart_epic(self) -> dict: async def restart_epic(self) -> dict:
return await self.send_command("softreboot", post=True, parameters=None) return await self.send_command("softreboot", post=True)
async def reboot(self) -> dict: async def reboot(self) -> dict:
return await self.send_command("reboot", post=True, parameters=None) return await self.send_command("reboot", post=True)
async def pause_mining(self) -> dict: async def pause_mining(self) -> dict:
return await self.send_command("miner", post=True, parameters="Stop") return await self.send_command("miner", post=True, parameters="Stop")

View File

@@ -14,8 +14,6 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import unittest
from tests.api_tests import * from tests.api_tests import *
from tests.config_tests import TestConfig from tests.config_tests import TestConfig
from tests.miners_tests import MinersTest from tests.miners_tests import MinersTest