update shields and improve typing and handling of fault light checks

This commit is contained in:
UpstreamData
2022-07-21 08:42:35 -06:00
parent af2f1e9ad5
commit add4b575c2
4 changed files with 21 additions and 11 deletions

View File

@@ -5,8 +5,8 @@
[![pypi](https://img.shields.io/pypi/v/pyasic.svg)](https://pypi.org/project/pyasic/) [![pypi](https://img.shields.io/pypi/v/pyasic.svg)](https://pypi.org/project/pyasic/)
[![python](https://img.shields.io/pypi/pyversions/pyasic.svg)](https://pypi.org/project/pyasic/) [![python](https://img.shields.io/pypi/pyversions/pyasic.svg)](https://pypi.org/project/pyasic/)
[![Read the Docs](https://img.shields.io/readthedocs/pyasic)](https://pyasic.readthedocs.io/en/latest/) [![Read the Docs](https://img.shields.io/readthedocs/pyasic)](https://pyasic.readthedocs.io/en/latest/)
![GitHub](https://img.shields.io/github/license/UpstreamData/pyasic) [![GitHub](https://img.shields.io/github/license/UpstreamData/pyasic)](https://github.com/UpstreamData/pyasic/blob/master/LICENSE.txt)
![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/UpstreamData/pyasic) [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/UpstreamData/pyasic)](https://www.codefactor.io/repository/github/upstreamdata/pyasic)
## Documentation ## Documentation
Documentation is located on Read the Docs as [pyasic](https://pyasic.readthedocs.io/en/latest/) Documentation is located on Read the Docs as [pyasic](https://pyasic.readthedocs.io/en/latest/)

View File

@@ -5,8 +5,8 @@
[![pypi](https://img.shields.io/pypi/v/pyasic.svg)](https://pypi.org/project/pyasic/) [![pypi](https://img.shields.io/pypi/v/pyasic.svg)](https://pypi.org/project/pyasic/)
[![python](https://img.shields.io/pypi/pyversions/pyasic.svg)](https://pypi.org/project/pyasic/) [![python](https://img.shields.io/pypi/pyversions/pyasic.svg)](https://pypi.org/project/pyasic/)
[![Read the Docs](https://img.shields.io/readthedocs/pyasic)](https://pyasic.readthedocs.io/en/latest/) [![Read the Docs](https://img.shields.io/readthedocs/pyasic)](https://pyasic.readthedocs.io/en/latest/)
![GitHub](https://img.shields.io/github/license/UpstreamData/pyasic) [![GitHub](https://img.shields.io/github/license/UpstreamData/pyasic)](https://github.com/UpstreamData/pyasic/blob/master/LICENSE.txt)
![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/UpstreamData/pyasic) [![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/UpstreamData/pyasic)](https://www.codefactor.io/repository/github/upstreamdata/pyasic)
## Intro ## Intro
Welcome to pyasic! Pyasic uses an asynchronous method of communicating with asic miners on your network, which makes it super fast. Welcome to pyasic! Pyasic uses an asynchronous method of communicating with asic miners on your network, which makes it super fast.

View File

@@ -36,7 +36,7 @@ class BMMinerX17(BMMiner):
hostname = data["hostname"] hostname = data["hostname"]
return hostname return hostname
async def get_mac(self): async def get_mac(self) -> Union[str, None]:
mac = None mac = None
url = f"http://{self.ip}/cgi-bin/get_system_info.cgi" url = f"http://{self.ip}/cgi-bin/get_system_info.cgi"
auth = httpx.DigestAuth("root", "root") auth = httpx.DigestAuth("root", "root")
@@ -62,6 +62,7 @@ class BMMinerX17(BMMiner):
if data.status_code == 200: if data.status_code == 200:
data = data.json() data = data.json()
if data["isBlinking"]: if data["isBlinking"]:
self.light = True
return True return True
return False return False
@@ -74,10 +75,13 @@ class BMMinerX17(BMMiner):
if data.status_code == 200: if data.status_code == 200:
data = data.json() data = data.json()
if not data["isBlinking"]: if not data["isBlinking"]:
self.light = False
return True return True
return False return False
async def check_light(self): async def check_light(self) -> Union[bool, None]:
if self.light:
return self.light
url = f"http://{self.ip}/cgi-bin/blink.cgi" url = f"http://{self.ip}/cgi-bin/blink.cgi"
auth = httpx.DigestAuth("root", "root") auth = httpx.DigestAuth("root", "root")
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
@@ -85,8 +89,12 @@ class BMMinerX17(BMMiner):
if data.status_code == 200: if data.status_code == 200:
data = data.json() data = data.json()
if data["isBlinking"]: if data["isBlinking"]:
self.light = True
return True return True
else:
self.light = False
return False return False
return None
async def reboot(self) -> bool: async def reboot(self) -> bool:
url = f"http://{self.ip}/cgi-bin/reboot.cgi" url = f"http://{self.ip}/cgi-bin/reboot.cgi"

View File

@@ -19,6 +19,7 @@ from pyasic.config import MinerConfig
import httpx import httpx
import json import json
import asyncio import asyncio
from typing import Union
class BMMinerX19(BMMiner): class BMMinerX19(BMMiner):
@@ -26,7 +27,7 @@ class BMMinerX19(BMMiner):
super().__init__(ip) super().__init__(ip)
self.ip = ip self.ip = ip
async def check_light(self) -> bool: async def check_light(self) -> Union[bool, None]:
if self.light: if self.light:
return self.light return self.light
url = f"http://{self.ip}/cgi-bin/get_blink_status.cgi" url = f"http://{self.ip}/cgi-bin/get_blink_status.cgi"
@@ -36,8 +37,9 @@ class BMMinerX19(BMMiner):
if data.status_code == 200: if data.status_code == 200:
data = data.json() data = data.json()
light = data["blink"] light = data["blink"]
self.light = light
return light return light
return False return None
async def get_config(self) -> MinerConfig: async def get_config(self) -> MinerConfig:
url = f"http://{self.ip}/cgi-bin/get_miner_conf.cgi" url = f"http://{self.ip}/cgi-bin/get_miner_conf.cgi"
@@ -69,7 +71,7 @@ class BMMinerX19(BMMiner):
break break
await asyncio.sleep(1) await asyncio.sleep(1)
async def get_hostname(self) -> str or None: async def get_hostname(self) -> Union[str, None]:
hostname = None hostname = None
url = f"http://{self.ip}/cgi-bin/get_system_info.cgi" url = f"http://{self.ip}/cgi-bin/get_system_info.cgi"
auth = httpx.DigestAuth("root", "root") auth = httpx.DigestAuth("root", "root")
@@ -82,7 +84,7 @@ class BMMinerX19(BMMiner):
hostname = data["hostname"] hostname = data["hostname"]
return hostname return hostname
async def get_mac(self): async def get_mac(self) -> Union[str, None]:
mac = None mac = None
url = f"http://{self.ip}/cgi-bin/get_system_info.cgi" url = f"http://{self.ip}/cgi-bin/get_system_info.cgi"
auth = httpx.DigestAuth("root", "root") auth = httpx.DigestAuth("root", "root")