improve some type hinting compatibility

This commit is contained in:
UpstreamData
2022-07-20 11:19:13 -06:00
parent 2e3991355b
commit 3d3064d78e
2 changed files with 10 additions and 6 deletions

View File

@@ -15,6 +15,7 @@
from pyasic.miners._backends import BMMiner # noqa - Ignore access to _module
import httpx
from typing import Union
class BMMinerX17(BMMiner):
@@ -22,7 +23,7 @@ class BMMinerX17(BMMiner):
super().__init__(ip)
self.ip = ip
async def get_hostname(self) -> str or None:
async def get_hostname(self) -> Union[str, None]:
hostname = None
url = f"http://{self.ip}/cgi-bin/get_system_info.cgi"
auth = httpx.DigestAuth("root", "root")

View File

@@ -362,8 +362,8 @@ class MinerFactory(metaclass=Singleton):
self.miners = {}
async def _get_miner_type(
self, ip: ipaddress.ip_address or str
) -> Tuple[str or None, str or None, str or None]:
self, ip: Union[ipaddress.ip_address, str]
) -> Tuple[Union[str, None], Union[str, None], Union[str, None]]:
data = None
model = None
@@ -444,7 +444,8 @@ class MinerFactory(metaclass=Singleton):
model = data["minertype"]
if "bmminer" in "\t".join(data.keys()):
api = "BMMiner"
except:
except Exception as e:
logging.debug(f"Unable to get miner - {e}")
return None, None, None
# if we have devdetails, we can get model data from there
@@ -540,7 +541,7 @@ class MinerFactory(metaclass=Singleton):
return model, api, ver
@staticmethod
async def _validate_command(data: dict) -> Tuple[bool, str or None]:
async def _validate_command(data: dict) -> Tuple[bool, Union[str, None]]:
"""Check if the returned command output is correctly formatted."""
# check if the data returned is correct or an error
if not data or data == {}:
@@ -567,7 +568,9 @@ class MinerFactory(metaclass=Singleton):
return True, None
@staticmethod
async def _send_api_command(ip: ipaddress.ip_address or str, command: str) -> dict:
async def _send_api_command(
ip: Union[ipaddress.ip_address, str], command: str
) -> dict:
try:
# get reader and writer streams
reader, writer = await asyncio.open_connection(str(ip), 4028)