added unknown miner type

This commit is contained in:
UpstreamData
2021-10-07 16:49:36 -06:00
parent a0e88490c6
commit e0dd2ee1f3
5 changed files with 16 additions and 4 deletions

View File

@@ -6,7 +6,9 @@ import asyncio
async def main(): async def main():
miner_network = MinerNetwork("192.168.1.1") miner_network = MinerNetwork("192.168.1.1")
await miner_network.scan_network_for_miners() miner_list = await miner_network.scan_network_for_miners()
print(miner_list)
if __name__ == '__main__': if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main()) asyncio.get_event_loop().run_until_complete(main())

View File

@@ -7,4 +7,4 @@ import ipaddress
class BaseMiner: class BaseMiner:
def __init__(self, ip: str, api: BOSMinerAPI or CGMinerAPI or BMMinerAPI): def __init__(self, ip: str, api: BOSMinerAPI or CGMinerAPI or BMMinerAPI):
self.ip = ipaddress.ip_address(ip) self.ip = ipaddress.ip_address(ip)
self.api = api self.api = api

View File

@@ -1,6 +1,7 @@
from miners.bosminer import BOSminer from miners.bosminer import BOSminer
from miners.bmminer import BMMiner from miners.bmminer import BMMiner
from miners.cgminer import CGMiner from miners.cgminer import CGMiner
from miners.unknown_miner import UnknownMiner
from API import APIError from API import APIError
import asyncio import asyncio
import ipaddress import ipaddress
@@ -19,7 +20,7 @@ class MinerFactory:
return CGMiner(str(ip)) return CGMiner(str(ip))
elif version == "BMMiner": elif version == "BMMiner":
return BMMiner(str(ip)) return BMMiner(str(ip))
return f"Unknown: {str(ip)}" return UnknownMiner(str(ip))
async def _get_version_data(self, ip: ipaddress.ip_address): async def _get_version_data(self, ip: ipaddress.ip_address):
try: try:

9
miners/unknown_miner.py Normal file
View File

@@ -0,0 +1,9 @@
import ipaddress
class UnknownMiner():
def __init__(self, ip: str):
self.ip = ipaddress.ip_address(ip)
def __repr__(self):
return f"Unknown: {str(self.ip)}"

View File

@@ -38,7 +38,7 @@ class MinerNetwork:
for miner_ip in miner_ips: for miner_ip in miner_ips:
create_miners_tasks.append(self.miner_factory.get_miner(miner_ip)) create_miners_tasks.append(self.miner_factory.get_miner(miner_ip))
miners = await asyncio.gather(*create_miners_tasks) miners = await asyncio.gather(*create_miners_tasks)
print(miners) return miners
async def ping_miner(self, ip: ipaddress.ip_address): async def ping_miner(self, ip: ipaddress.ip_address):