added more doocstrings and improved the readme

This commit is contained in:
UpstreamData
2022-01-04 09:16:17 -07:00
parent d138778f0a
commit c075f3f66a
4 changed files with 33 additions and 1 deletions

View File

@@ -21,6 +21,21 @@ if __name__ == '__main__':
2. Navigate to this directory, and run ```make_cfg_tool_exe.py build``` on Windows or ```python3 make_cfg_tool_exe.py``` on Mac or UNIX.
### Interfacing with miners programmatically
<br>
##### Note: If you are trying to interface with Whatsminers, there is a bug in the way they are interacted with on Windows, so to fix that you need to change the event loop policy using this code:
```python
# need to import these 2 libraries, you need asyncio anyway so make sure you have sys imported
import sys
import asyncio
# if the computer is windows, set the event loop policy to a WindowsSelector policy
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
```
##### It is likely a good idea to use this code in your program anyway to be preventative.
<br>
To write your own custom programs with this repo, you have many options.

View File

@@ -1,3 +1,7 @@
"""
This file stores the MinerFactory instance used by the ConfigUtility for use in other files.
"""
from miners.miner_factory import MinerFactory
miner_factory = MinerFactory()

View File

@@ -16,6 +16,14 @@ class MinerFactory:
self.miners = {}
async def get_miner_generator(self, ips: list):
"""
Get Miner objects from ip addresses using an async generator.
Returns an asynchronous generator containing Miners.
Parameters:
ips: a list of ip addresses to get miners for.
"""
loop = asyncio.get_event_loop()
scan_tasks = []
for miner in ips:

View File

@@ -31,7 +31,7 @@ class MinerNetwork:
return ipaddress.ip_network(f"{default_gateway}/{subnet_mask}", strict=False)
async def scan_network_for_miners(self) -> None or list:
"""Scan the network for miners, and """
"""Scan the network for miners, and return found miners as a list."""
local_network = self.get_network()
print(f"Scanning {local_network} for miners...")
scan_tasks = []
@@ -55,6 +55,11 @@ class MinerNetwork:
return miners
async def scan_network_generator(self):
"""
Scan the network for miners using an async generator.
Returns an asynchronous generator containing found miners.
"""
loop = asyncio.get_event_loop()
local_network = self.get_network()
scan_tasks = []