add support for X19 miner errors codes shown on their dashboard

This commit is contained in:
UpstreamData
2022-08-05 10:23:03 -06:00
parent a53e01df6f
commit b81590bd2e
5 changed files with 51 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
# 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 dataclasses import dataclass, asdict
@dataclass
class X19Error:
"""A Dataclass to handle error codes of X19 miners."""
error_message: str
def asdict(self):
return asdict(self)

View File

@@ -14,3 +14,4 @@
from .whatsminer import WhatsminerError
from .bos import BraiinsOSError
from .X19 import X19Error

View File

@@ -112,5 +112,8 @@ class BaseMiner:
async def get_mac(self):
return None
async def get_errors(self):
return None
async def get_data(self) -> MinerData:
return MinerData(ip=str(self.ip))

View File

@@ -168,6 +168,7 @@ class BMMiner(BaseMiner):
model = await self.get_model()
hostname = await self.get_hostname()
mac = await self.get_mac()
errors = await self.get_errors()
if model:
data.model = model
@@ -178,6 +179,10 @@ class BMMiner(BaseMiner):
if mac:
data.mac = mac
if errors:
for error in errors:
data.errors.append(error)
data.fault_light = await self.check_light()
miner_data = None

View File

@@ -15,11 +15,12 @@
from pyasic.miners._backends import BMMiner # noqa - Ignore access to _module
from pyasic.config import MinerConfig
from pyasic.data.error_codes import X19Error
import httpx
import json
import asyncio
from typing import Union
from typing import Union, List
class BMMinerX19(BMMiner):
@@ -131,3 +132,18 @@ class BMMinerX19(BMMiner):
if data.status_code == 200:
return True
return False
async def get_errors(self) -> List[X19Error]:
errors = []
url = f"http://{self.ip}/cgi-bin/summary.cgi"
auth = httpx.DigestAuth("root", "root")
async with httpx.AsyncClient() as client:
data = await client.get(url, auth=auth)
if data:
data = data.json()
if "SUMMARY" in data.keys():
if "status" in data["SUMMARY"][0].keys():
for item in data["SUMMARY"][0]["status"]:
if not item["status"] == "s":
errors.append(X19Error(item["msg"]))
return errors