feature: add support for vnish error codes
This commit is contained in:
@@ -18,9 +18,15 @@ from typing import TypeVar
|
|||||||
|
|
||||||
from .bos import BraiinsOSError
|
from .bos import BraiinsOSError
|
||||||
from .innosilicon import InnosiliconError
|
from .innosilicon import InnosiliconError
|
||||||
|
from .vnish import VnishError
|
||||||
from .whatsminer import WhatsminerError
|
from .whatsminer import WhatsminerError
|
||||||
from .X19 import X19Error
|
from .X19 import X19Error
|
||||||
|
|
||||||
MinerErrorData = TypeVar(
|
MinerErrorData = TypeVar(
|
||||||
"MinerErrorData", WhatsminerError, BraiinsOSError, X19Error, InnosiliconError
|
"MinerErrorData",
|
||||||
|
WhatsminerError,
|
||||||
|
BraiinsOSError,
|
||||||
|
X19Error,
|
||||||
|
InnosiliconError,
|
||||||
|
VnishError,
|
||||||
)
|
)
|
||||||
|
|||||||
28
pyasic/data/error_codes/vnish.py
Normal file
28
pyasic/data/error_codes/vnish.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Copyright 2022 Upstream Data Inc -
|
||||||
|
# -
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); -
|
||||||
|
# you may not use this file except in compliance with the License. -
|
||||||
|
# You may obtain a copy of the License at -
|
||||||
|
# -
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0 -
|
||||||
|
# -
|
||||||
|
# Unless required by applicable law or agreed to in writing, software -
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, -
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -
|
||||||
|
# See the License for the specific language governing permissions and -
|
||||||
|
# limitations under the License. -
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
from pyasic.data.error_codes.base import BaseMinerError
|
||||||
|
|
||||||
|
|
||||||
|
class VnishError(BaseMinerError):
|
||||||
|
"""A Dataclass to handle error codes of Vnish miners.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
error_message: The error message as a string.
|
||||||
|
error_code: The error code as an int. 0 if the message is not assigned a code.
|
||||||
|
"""
|
||||||
|
|
||||||
|
error_message: str
|
||||||
|
error_code: int = 0
|
||||||
@@ -15,9 +15,10 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pyasic import MinerConfig
|
from pyasic import MinerConfig
|
||||||
|
from pyasic.data.error_codes import MinerErrorData, VnishError
|
||||||
from pyasic.device.algorithm import AlgoHashRate
|
from pyasic.device.algorithm import AlgoHashRate
|
||||||
from pyasic.errors import APIError
|
from pyasic.errors import APIError
|
||||||
from pyasic.miners.backends.bmminer import BMMiner
|
from pyasic.miners.backends.bmminer import BMMiner
|
||||||
@@ -85,6 +86,10 @@ VNISH_DATA_LOC = DataLocations(
|
|||||||
"_get_pools",
|
"_get_pools",
|
||||||
[RPCAPICommand("rpc_pools", "pools")],
|
[RPCAPICommand("rpc_pools", "pools")],
|
||||||
),
|
),
|
||||||
|
str(DataOptions.ERRORS): DataFunction(
|
||||||
|
"_get_errors",
|
||||||
|
[WebAPICommand("web_summary", "summary")],
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -266,6 +271,24 @@ class VNish(VNishFirmware, BMMiner):
|
|||||||
except LookupError:
|
except LookupError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def _get_errors(self, web_summary: dict = None) -> List[MinerErrorData]:
|
||||||
|
errors = []
|
||||||
|
if web_summary is None:
|
||||||
|
try:
|
||||||
|
web_summary = await self.web.summary()
|
||||||
|
except APIError:
|
||||||
|
return errors
|
||||||
|
|
||||||
|
if web_summary is not None:
|
||||||
|
chains = web_summary.get("miner", {}).get("chains", [])
|
||||||
|
for chain in chains:
|
||||||
|
state = chain.get("status", {}).get("state")
|
||||||
|
description = chain.get("status", {}).get("description", "")
|
||||||
|
if state == "failure":
|
||||||
|
errors.append(VnishError(error_message=description))
|
||||||
|
|
||||||
|
return errors
|
||||||
|
|
||||||
async def get_config(self) -> MinerConfig:
|
async def get_config(self) -> MinerConfig:
|
||||||
try:
|
try:
|
||||||
web_settings = await self.web.settings()
|
web_settings = await self.web.settings()
|
||||||
|
|||||||
Reference in New Issue
Block a user