Skip to content

Commit e65cb05

Browse files
committed
update miner factory to handle some types of stock fw S9s
1 parent f8590b0 commit e65cb05

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

pyasic/miners/miner_factory.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import TypeVar, Tuple, List, Union
22
from collections.abc import AsyncIterable
33
from pyasic.miners import BaseMiner
4+
import httpx
45

56
from pyasic.miners.antminer import *
67
from pyasic.miners.avalonminer import *
@@ -252,7 +253,6 @@ async def get_miner_generator(
252253
# create a list of tasks
253254
scan_tasks = []
254255
# for each miner IP that was passed in, add a task to get its class
255-
logging.debug(f"Getting miners with generator: [{ips}]")
256256
for miner in ips:
257257
scan_tasks.append(loop.create_task(self.get_miner(miner)))
258258
# asynchronously run the tasks and return them as they complete
@@ -274,7 +274,6 @@ async def get_miner(self, ip: Union[ipaddress.ip_address, str]) -> AnyMiner:
274274
ip = ipaddress.ip_address(ip)
275275
# check if the miner already exists in cache
276276
if ip in self.miners:
277-
logging.debug(f"Miner exists in cache: {self.miners[ip]}")
278277
return self.miners[ip]
279278
# if everything fails, the miner is already set to unknown
280279
miner = UnknownMiner(str(ip))
@@ -298,9 +297,6 @@ async def get_miner(self, ip: Union[ipaddress.ip_address, str]) -> AnyMiner:
298297
ver = new_ver
299298
# if we find the API and model, don't need to loop anymore
300299
if api and model:
301-
logging.debug(
302-
f"Miner api and model found: API - {api}, Model - {model}"
303-
)
304300
break
305301
except asyncio.TimeoutError:
306302
logging.warning(f"{ip}: Get Miner Timed Out")
@@ -344,13 +340,11 @@ async def get_miner(self, ip: Union[ipaddress.ip_address, str]) -> AnyMiner:
344340
self.miners[ip] = miner
345341

346342
# return the miner
347-
logging.debug(f"Found miner: {miner}")
348343
return miner
349344

350345
def clear_cached_miners(self) -> None:
351346
"""Clear the miner factory cache."""
352347
# empty out self.miners
353-
logging.debug("Clearing MinerFactory cache.")
354348
self.miners = {}
355349

356350
async def _get_miner_type(
@@ -376,16 +370,12 @@ async def _get_miner_type(
376370
version = data["version"][0]
377371

378372
except APIError:
379-
logging.debug(f"API Error when getting miner type: {str(ip)}")
380373
try:
381374
# try devdetails and version separately (X19s mainly require this)
382375
# get devdetails and validate
383376
devdetails = await self._send_api_command(str(ip), "devdetails")
384377
validation = await self._validate_command(devdetails)
385378
if not validation[0]:
386-
logging.debug(
387-
f"Splitting commands failed when getting miner type: {str(ip)}"
388-
)
389379
# if devdetails fails try version instead
390380
devdetails = None
391381

@@ -399,15 +389,12 @@ async def _get_miner_type(
399389

400390
# if this fails we raise an error to be caught below
401391
if not validation[0]:
402-
logging.debug(
403-
f"get_version failed when getting miner type: {str(ip)}"
404-
)
405392
raise APIError(validation[1])
406393
except APIError as e:
407394
# catch APIError and let the factory know we cant get data
408-
logging.warning(f"{ip}: API Command Error: {e.__name__} - {e}")
395+
logging.warning(f"{ip}: API Command Error: {e}")
409396
return None, None, None
410-
except OSError:
397+
except OSError as e:
411398
# miner refused connection on API port, we wont be able to get data this way
412399
# try ssh
413400
try:
@@ -432,7 +419,19 @@ async def _get_miner_type(
432419
return model, api, None
433420

434421
except asyncssh.misc.PermissionDenied:
435-
return None, None, None
422+
try:
423+
url = f"http://{self.ip}/cgi-bin/get_system_info.cgi"
424+
auth = httpx.DigestAuth("root", "root")
425+
async with httpx.AsyncClient() as client:
426+
data = await client.get(url, auth=auth)
427+
if data.status_code == 200:
428+
data = data.json()
429+
if "minertype" in data.keys():
430+
model = data["minertype"]
431+
if "bmminer" in "\t".join(data.keys()):
432+
api = "BMMiner"
433+
except:
434+
return None, None, None
436435

437436
# if we have devdetails, we can get model data from there
438437
if devdetails:

0 commit comments

Comments
 (0)