Compare commits

..

57 Commits

Author SHA1 Message Date
UpstreamData
b9d5e7b206 version: bump version number. 2022-12-13 10:05:55 -07:00
UpstreamData
2d8c7eb4fd feature: add support for whatsminer M30S+ VG40 2022-12-13 10:05:07 -07:00
UpstreamData
f69e07fe68 version: bump version number. 2022-12-05 09:49:03 -07:00
UpstreamData
84aab38954 bug: properly shorten stratum URLs when gathering data from graphql. 2022-12-05 09:48:40 -07:00
UpstreamData
dcf37481bd version: bump version number. 2022-12-05 09:35:44 -07:00
UpstreamData
1a9cca84d5 bug: fix pool split not being found correctly with braiinsOS. 2022-12-05 09:34:43 -07:00
UpstreamData
c5272d67de version: bump version number 2022-12-03 14:20:57 -07:00
UpstreamData
3bcfb14177 feature: add support for Whatsminer M31SV20, and fix a bug with miner factory not identifying the miners properly by removing a V prefix. 2022-12-03 14:20:37 -07:00
UpstreamData
566280f280 docs: fix some missing data in the docs. 2022-12-02 16:10:30 -07:00
UpstreamData
a814f7eefb Update README.md 2022-12-02 16:06:22 -07:00
UpstreamData
097b8ed534 version: bump version number. 2022-12-02 15:57:52 -07:00
UpstreamData
da47d72749 feature: add wattage limit in get_config when getting config from whatsminers. 2022-12-02 15:57:31 -07:00
UpstreamData
abd4d18a01 feature: add whatsminer M31SV10 and V60. 2022-12-02 15:51:27 -07:00
UpstreamData
2adbce3c21 version: bump version number. 2022-12-02 09:26:53 -07:00
UpstreamData
c41324b324 bug: fix a bug with MinerAPI.commands causing an infinite recursion loop when checking a list of commands with get_commands, and ficx some weirdness where BTMiner doesnt return any data. 2022-12-02 09:26:17 -07:00
UpstreamData
151a4f6c2d version: bump version number. 2022-12-01 16:18:07 -07:00
UpstreamData
d23777a83f feature: Switch to using semaphores in miner network to rate limit as they are much more friendly. 2022-12-01 16:17:46 -07:00
UpstreamData
bb0aee8337 version: bump version number. 2022-12-01 15:54:09 -07:00
UpstreamData
2a23acb73a bug: fix BTMiner not responding to pause_mining and resume_mining causing an exception. 2022-12-01 15:53:47 -07:00
UpstreamData
ad5eb0cef6 bug: fix a bug with updated logging. 2022-12-01 15:40:40 -07:00
UpstreamData
07dd8f55fe format: improve logging. 2022-12-01 15:02:17 -07:00
UpstreamData
bafa91cc47 version: bump version number. 2022-11-30 10:48:20 -07:00
UpstreamData
16399510fa feature: add set_power_limit to all miners that support it. 2022-11-30 10:47:45 -07:00
UpstreamData
e9f54eec0a version: bump version number. 2022-11-30 10:01:27 -07:00
UpstreamData
fbbbc9f215 bug: Add VH60 to miner factory as it was missing. 2022-11-30 10:01:01 -07:00
UpstreamData
69e4f575c0 bug: fix a bug wth bosminer where it will sometimes not get data from graphql 2022-11-30 09:59:12 -07:00
UpstreamData
e95659d2e0 version: bump version number 2022-11-29 09:36:41 -07:00
UpstreamData
35f34310ec bug: fix an issue with incorrect type hinting. 2022-11-29 09:36:24 -07:00
UpstreamData
acc18e20fd Merge remote-tracking branch 'origin/master'
# Conflicts:
#	pyproject.toml
2022-11-24 11:04:19 -07:00
UpstreamData
72460eac08 version: bump version number 2022-11-24 11:03:54 -07:00
UpstreamData
3e5f9d4eca version: bump version number 2022-11-24 11:01:30 -07:00
UpstreamData
e873fa252c feature: add support for setting wattage on whatsminers with the new 2.0.5 API 2022-11-24 09:56:25 -07:00
UpstreamData
ff2c083a19 feature: add new whatsminer commands for version 2.0.5 2022-11-24 09:51:40 -07:00
UpstreamData
a30a84c34b version: bump version number 2022-11-22 18:28:02 -07:00
UpstreamData
97d2023298 feature: add support for whatsminer M31S V70 2022-11-22 18:27:35 -07:00
UpstreamData
1ce8430a14 version: bump version number 2022-11-21 11:28:29 -07:00
UpstreamData
1c0b638818 feature: add S19a Pro 2022-11-21 11:27:52 -07:00
UpstreamData
e852588eeb version: bump version number 2022-11-18 11:15:07 -07:00
UpstreamData
08b9bfd854 bug: fix error with getting miner failing to find a description key. 2022-11-18 11:14:35 -07:00
UpstreamData
7ee2f3a29a version: bump version number 2022-11-17 15:27:24 -07:00
UpstreamData
5ee6a38f39 bug: fix a bug with identifying some older version of BOSMiner. 2022-11-17 15:27:06 -07:00
UpstreamData
8f0bfd5f83 version: bump version number. 2022-11-16 14:30:52 -07:00
UpstreamData
c54f39fc77 bug: fix int and str addition in graphQL. 2022-11-16 14:30:29 -07:00
UpstreamData
eb40769ccf format: improve formatting 2022-11-15 11:28:35 -07:00
UpstreamData
418c62b40d version: bump version number 2022-11-14 13:50:28 -07:00
UpstreamData
198a480c35 bug: fix bug with read timeout not being caught when sending graphql query 2022-11-14 13:49:57 -07:00
UpstreamData
2d4bf4e847 version: bump version number 2022-11-14 11:20:54 -07:00
UpstreamData
774e3d1a62 bug: fix wattage not setting correctly for some BOS+ miners with issues. 2022-11-14 11:20:27 -07:00
UpstreamData
ade3cd6fee version: bump version number 2022-11-14 09:56:18 -07:00
UpstreamData
28dc3ccb84 version: bump version number 2022-11-14 09:51:34 -07:00
UpstreamData
6ca8582ec3 bug: improve robustness of identifying new versions of bosminer running BOSer. 2022-11-14 09:49:19 -07:00
UpstreamData
74b4aeb44a version: bump version number 2022-11-14 09:14:28 -07:00
UpstreamData
9c7ab5ac57 bug: fix support for new miners that return a BOSer string in version data. 2022-11-14 09:10:18 -07:00
Upstream Data
65ecf1fea2 version: bump version number 2022-11-13 19:36:25 -07:00
Upstream Data
44142c658b format: remove print statements 2022-11-13 19:36:07 -07:00
Upstream Data
25a205ce6c version: bump version number 2022-11-13 19:27:55 -07:00
Upstream Data
25094084cf bug: clarify uppercasing data from __get_model_from_graphql() 2022-11-13 19:27:32 -07:00
79 changed files with 777 additions and 330 deletions

View File

@@ -38,7 +38,6 @@ There are 2 main ways to get a miner (and the functions attached to it), via sca
#### Scanning for miners
```python
import asyncio
import sys
from pyasic.network import MinerNetwork
@@ -47,7 +46,7 @@ from pyasic.network import MinerNetwork
async def scan_and_get_data():
# Define network range to be used for scanning
# This can take a list of IPs, a constructor string, or an IP and subnet mask
# The standard mask is /24, and you can pass any IP address in the subnet
# The standard mask is /24 (x.x.x.0-255), and you can pass any IP address in the subnet
net = MinerNetwork("192.168.1.69", mask=24)
# Scan the network for miners
# This function returns a list of miners of the correct type as a class
@@ -72,9 +71,8 @@ if __name__ == "__main__":
#### Getting a miner if you know the IP
```python
import asyncio
import sys
from pyasic.miners import get_miner
from pyasic import get_miner
# define asynchronous function to get miner and data
@@ -95,12 +93,15 @@ if __name__ == "__main__":
If needed, this library exposes a wrapper for the miner API that can be used for advanced data gathering.
You can see more information on basic usage of the APIs past this example in the docs [here](https://pyasic.readthedocs.io/en/latest/API/api/).
Please see the appropriate API documentation page (pyasic docs -> Advanced -> Miner APIs -> your API type) for a link to that specific miner's API documentation page and more information.
#### List available API commands
```python
import asyncio
import sys
from pyasic.miners import get_miner
from pyasic import get_miner
async def get_api_commands(miner_ip: str):
@@ -108,7 +109,8 @@ async def get_api_commands(miner_ip: str):
miner = await get_miner(miner_ip)
# List all available commands
print(miner.api.get_commands())
# Can also be called explicitly with the function miner.api.get_commands()
print(miner.api.commands)
if __name__ == "__main__":
@@ -121,9 +123,8 @@ The miner API commands will raise an `APIError` if they fail with a bad status c
```python
import asyncio
import sys
from pyasic.miners import get_miner
from pyasic import get_miner
async def get_api_commands(miner_ip: str):

View File

@@ -117,10 +117,11 @@ These functions are
[`get_hostname`](#get-hostname),
[`get_model`](#get-model),
[`reboot`](#reboot),
[`restart_backend`](#restart-backend), and
[`stop_mining`](#stop-mining), and
[`resume_mining`](#resume-mining), and
[`send_config`](#send-config).
[`restart_backend`](#restart-backend),
[`stop_mining`](#stop-mining),
[`resume_mining`](#resume-mining),
[`send_config`](#send-config), and
[`set_power_limit`](#set-power-limit).
<br>
@@ -228,6 +229,14 @@ These functions are
<br>
### Set Power Limit
::: pyasic.miners.BaseMiner.set_power_limit
handler: python
options:
heading_level: 4
<br>
## [`MinerConfig`][pyasic.config.MinerConfig] and [`MinerData`][pyasic.data.MinerData]
Pyasic implements a few dataclasses as helpers to make data return types consistent across different miners and miner APIs. The different fields of these dataclasses can all be viewed with the classmethod `cls.fields()`.

View File

@@ -77,6 +77,7 @@ details {
<ul>
<li><a href="../whatsminer/M3X/#m30svf20">VF20</a></li>
<li><a href="../whatsminer/M3X/#m30sve40">VE40</a></li>
<li><a href="../whatsminer/M3X/#m30svg40">VG40</a></li>
<li><a href="../whatsminer/M3X/#m30svg60">VG60</a></li>
</ul>
</details>
@@ -90,6 +91,10 @@ details {
</details>
<details>
<summary><a href="../whatsminer/M3X/#m31s">M31S</a></summary>
<summary><a href="../whatsminer/M3X/#m31sv10">M31SV10</a></summary>
<summary><a href="../whatsminer/M3X/#m31sv20">M31SV20</a></summary>
<summary><a href="../whatsminer/M3X/#m31sv60">M31SV60</a></summary>
<summary><a href="../whatsminer/M3X/#m31sv70">M31SV70</a></summary>
</details>
<details>
<summary><a href="../whatsminer/M3X/#m31s_1">M31S+</a></summary>

View File

@@ -65,6 +65,14 @@
show_root_heading: false
heading_level: 4
## M30S+VG40
::: pyasic.miners.whatsminer.btminer.M3X.M30S_Plus.BTMinerM30SPlusVG40
handler: python
options:
show_root_heading: false
heading_level: 4
## M30S+VG60
::: pyasic.miners.whatsminer.btminer.M3X.M30S_Plus.BTMinerM30SPlusVG60
@@ -114,6 +122,38 @@
show_root_heading: false
heading_level: 4
## M31SV10
::: pyasic.miners.whatsminer.btminer.M3X.M31S.BTMinerM31SV10
handler: python
options:
show_root_heading: false
heading_level: 4
## M31SV20
::: pyasic.miners.whatsminer.btminer.M3X.M31S.BTMinerM31SV20
handler: python
options:
show_root_heading: false
heading_level: 4
## M31SV60
::: pyasic.miners.whatsminer.btminer.M3X.M31S.BTMinerM31SV60
handler: python
options:
show_root_heading: false
heading_level: 4
## M31SV70
::: pyasic.miners.whatsminer.btminer.M3X.M31S.BTMinerM31SV70
handler: python
options:
show_root_heading: false
heading_level: 4
## M31S+
::: pyasic.miners.whatsminer.btminer.M3X.M31S_Plus.BTMinerM31SPlus

View File

@@ -35,6 +35,81 @@ class BaseMinerAPI:
raise TypeError(f"Only children of '{cls.__name__}' may be instantiated")
return object.__new__(cls)
def __repr__(self):
return f"{self.__class__.__name__}: {str(self.ip)}"
async def send_command(
self,
command: Union[str, bytes],
parameters: Union[str, int, bool] = None,
ignore_errors: bool = False,
allow_warning: bool = True,
) -> dict:
"""Send an API command to the miner and return the result.
Parameters:
command: The command to sent to the miner.
parameters: Any additional parameters to be sent with the command.
ignore_errors: Whether to raise APIError when the command returns an error.
allow_warning: Whether to warn if the command fails.
Returns:
The return data from the API command parsed from JSON into a dict.
"""
logging.debug(f"{self} - (Send Privileged Command) - {command} " + f'with args {parameters}' if parameters else '')
# create the command
cmd = {"command": command}
if parameters:
cmd["parameter"] = parameters
# send the command
data = await self._send_bytes(json.dumps(cmd).encode("utf-8"))
data = self._load_api_data(data)
# check for if the user wants to allow errors to return
if not ignore_errors:
# validate the command succeeded
validation = self._validate_command_output(data)
if not validation[0]:
if allow_warning:
logging.warning(
f"{self.ip}: API Command Error: {command}: {validation[1]}"
)
raise APIError(validation[1])
logging.debug(f"{self} - (Send Command) - Received data.")
return data
# Privileged command handler, only used by whatsminers, defined here for consistency.
async def send_privileged_command(self, *args, **kwargs) -> dict:
return await self.send_command(*args, **kwargs)
async def multicommand(self, *commands: str, allow_warning: bool = True) -> dict:
"""Creates and sends multiple commands as one command to the miner.
Parameters:
*commands: The commands to send as a multicommand to the miner.
allow_warning: A boolean to supress APIWarnings.
"""
# make sure we can actually run each command, otherwise they will fail
commands = self._check_commands(*commands)
# standard multicommand format is "command1+command2"
# standard format doesn't work for X19
command = "+".join(commands)
try:
data = await self.send_command(command, allow_warning=allow_warning)
except APIError:
return {}
logging.debug(f"{self} - (Multicommand) - Received data")
return data
@property
def commands(self) -> list:
return self.get_commands()
def get_commands(self) -> list:
"""Get a list of command accessible to a specific type of API on the miner.
@@ -46,6 +121,7 @@ class BaseMinerAPI:
for func in
# each function in self
dir(self)
if not func == "commands"
if callable(getattr(self, func)) and
# no __ or _ methods
not func.startswith("__") and not func.startswith("_") and
@@ -72,26 +148,6 @@ If you are sure you want to use this command please use API.send_command("{comma
)
return return_commands
async def multicommand(self, *commands: str, allow_warning: bool = True) -> dict:
"""Creates and sends multiple commands as one command to the miner.
Parameters:
*commands: The commands to send as a multicommand to the miner.
allow_warning: A boolean to supress APIWarnings.
"""
logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}")
# make sure we can actually run each command, otherwise they will fail
commands = self._check_commands(*commands)
# standard multicommand format is "command1+command2"
# doesn't work for S19 which uses the backup _x19_multicommand
command = "+".join(commands)
try:
data = await self.send_command(command, allow_warning=allow_warning)
except APIError:
return {}
logging.debug(f"{self.ip}: Received multicommand data.")
return data
async def _send_bytes(self, data: bytes) -> bytes:
try:
# get reader and writer streams
@@ -99,7 +155,7 @@ If you are sure you want to use this command please use API.send_command("{comma
# handle OSError 121
except OSError as e:
if getattr(e, "winerror") == "121":
logging.warning("Semaphore Timeout has Expired.")
logging.warning(f"{self} - ([Hidden] Send Bytes) - Semaphore timeout expired.")
return b"{}"
# send the command
@@ -117,7 +173,7 @@ If you are sure you want to use this command please use API.send_command("{comma
break
ret_data += d
except Exception as e:
logging.warning(f"{self.ip}: API Command Error: - {e}")
logging.warning(f"{self} - ([Hidden] Send Bytes) - API Command Error {e}")
# close the connection
writer.close()
@@ -125,50 +181,6 @@ If you are sure you want to use this command please use API.send_command("{comma
return ret_data
async def send_command(
self,
command: Union[str, bytes],
parameters: Union[str, int, bool] = None,
ignore_errors: bool = False,
allow_warning: bool = True,
) -> dict:
"""Send an API command to the miner and return the result.
Parameters:
command: The command to sent to the miner.
parameters: Any additional parameters to be sent with the command.
ignore_errors: Whether to raise APIError when the command returns an error.
allow_warning: Whether to warn if the command fails.
Returns:
The return data from the API command parsed from JSON into a dict.
"""
# create the command
cmd = {"command": command}
if parameters:
cmd["parameter"] = parameters
# send the command
data = await self._send_bytes(json.dumps(cmd).encode("utf-8"))
data = self._load_api_data(data)
# check for if the user wants to allow errors to return
if not ignore_errors:
# validate the command succeeded
validation = self._validate_command_output(data)
if not validation[0]:
if allow_warning:
logging.warning(
f"{self.ip}: API Command Error: {command}: {validation[1]}"
)
raise APIError(validation[1])
return data
async def send_privileged_command(self, *args, **kwargs) -> dict:
return await self.send_command(*args, **kwargs)
@staticmethod
def _validate_command_output(data: dict) -> tuple:
# check if the data returned is correct or an error
@@ -198,7 +210,6 @@ If you are sure you want to use this command please use API.send_command("{comma
@staticmethod
def _load_api_data(data: bytes) -> dict:
str_data = None
# some json from the API returns with a null byte (\x00) on the end
if data.endswith(b"\x00"):
# handle the null byte

View File

@@ -40,7 +40,6 @@ class BMMinerAPI(BaseMinerAPI):
async def multicommand(
self, *commands: str, allow_warning: bool = True
) -> dict:
logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}")
# make sure we can actually run each command, otherwise they will fail
commands = self._check_commands(*commands)
# standard multicommand format is "command1+command2"
@@ -49,9 +48,8 @@ class BMMinerAPI(BaseMinerAPI):
try:
data = await self.send_command(command, allow_warning=allow_warning)
except APIError:
logging.debug(f"{self.ip}: Handling X19 multicommand.")
logging.debug(f"{self} - (Multicommand) - Handling X19 multicommand.")
data = await self._x19_multicommand(*command.split("+"))
logging.debug(f"{self.ip}: Received multicommand data.")
return data
async def _x19_multicommand(self, *commands):
@@ -65,7 +63,7 @@ class BMMinerAPI(BaseMinerAPI):
except APIError as e:
raise APIError(e)
except Exception as e:
logging.warning(f"{self.ip}: API Multicommand Error: {e}")
logging.warning(f"{self} - ([Hidden] X19 Multicommand) - API Command Error {e}")
return data
async def version(self) -> dict:

View File

@@ -166,7 +166,7 @@ class BOSMinerAPI(BaseMinerAPI):
return await self.send_command("estats")
async def check(self, command: str) -> dict:
"""Check if the command command exists in BOSMiner.
"""Check if the command `command` exists in BOSMiner.
<details>
<summary>Expand</summary>

View File

@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import asyncio
import base64
import binascii
import hashlib
@@ -33,7 +32,7 @@ from pyasic.settings import PyasicSettings
# tool, then you can set them back to admin with this tool, but they
# must be changed to something else and set back to admin with this
# or the privileged API will not work using admin as the password. If
# you change the password, you can pass that to the this class as pwd,
# you change the password, you can pass that to this class as pwd,
# or add it as the Whatsminer_pwd in the settings.toml file.
@@ -82,7 +81,7 @@ def _add_to_16(string: str) -> bytes:
def parse_btminer_priviledge_data(token_data: dict, data: dict):
"""Parses data returned from the BTMiner privileged API.
Parses data from the BTMiner privileged API using the the token
Parses data from the BTMiner privileged API using the token
from the API in an AES format.
Parameters:
@@ -189,6 +188,7 @@ class BTMinerAPI(BaseMinerAPI):
async def send_privileged_command(
self, command: Union[str, bytes], ignore_errors: bool = False, **kwargs
) -> dict:
logging.debug(f"{self} - (Send Privileged Command) - {command} " + f'with args {kwargs}' if len(kwargs) > 0 else '')
command = {"cmd": command}
for kwarg in kwargs:
if kwargs[kwarg]:
@@ -198,6 +198,8 @@ class BTMinerAPI(BaseMinerAPI):
enc_command = create_privileged_cmd(token_data, command)
data = await self._send_bytes(enc_command)
if not data:
raise APIError("No data was returned from the API.")
data = self._load_api_data(data)
try:
@@ -223,6 +225,7 @@ class BTMinerAPI(BaseMinerAPI):
An encoded token and md5 password, which are used for the privileged API.
</details>
"""
logging.debug(f"{self} - (Get Token) - Getting token")
# get the token
data = await self.send_command("get_token")
@@ -245,6 +248,7 @@ class BTMinerAPI(BaseMinerAPI):
"host_sign": host_sign,
"host_passwd_md5": host_passwd_md5,
}
logging.debug(f"{self} - (Get Token) - Gathered token data: {self.current_token}")
return self.current_token
#### PRIVILEGED COMMANDS ####
@@ -582,7 +586,7 @@ class BTMinerAPI(BaseMinerAPI):
return await self.send_privileged_command("set_hostname", hostname=hostname)
async def set_power_pct(self, percent: int) -> dict:
"""Set the power percentage of the miner.
"""Set the power percentage of the miner based on current power. Used for temporary adjustment.
<details>
<summary>Expand</summary>
@@ -642,6 +646,119 @@ class BTMinerAPI(BaseMinerAPI):
"pre_power_on", complete="false", msg=msg
)
### ADDED IN V2.0.5 Whatsminer API ###
async def set_temp_offset(self, temp_offset: int):
"""Set the offset of miner hash board target temperature.
<details>
<summary>Expand</summary>
Set the offset of miner hash board target temperature, only works after
changing the password of the miner using the Whatsminer tool.
Parameters:
temp_offset: Target temperature offset.
Returns:
A reply informing of the status of setting temp offset.
</details>
"""
if not -30 < temp_offset < 0:
raise APIError(
f"Temp offset is outside of the allowed "
f"range. Please set a number between -30 and "
f"0."
)
return await self.send_privileged_command("set_temp_offset", temp_offset=temp_offset)
async def adjust_power_limit(self, power_limit: int):
"""Set the upper limit of the miner's power. Cannot be higher than the ordinary power of the machine.
<details>
<summary>Expand</summary>
Set the upper limit of the miner's power, only works after
changing the password of the miner using the Whatsminer tool.
The miner will reboot after this is set.
Parameters:
power_limit: New power limit.
Returns:
A reply informing of the status of setting power limit.
</details>
"""
return await self.send_privileged_command("adjust_power_limit", power_limit=power_limit)
async def adjust_upfreq_speed(self, upfreq_speed: int):
"""Set the upfreq speed, 0 is the normal speed, 9 is the fastest speed.
<details>
<summary>Expand</summary>
Set the upfreq speed, 0 is the normal speed, 9 is the fastest speed, only works after
changing the password of the miner using the Whatsminer tool.
The faster the speed, the greater the final hash rate and power deviation, and the stability
may be impacted. Fast boot mode cannot be used at the same time.
Parameters:
upfreq_speed: New upfreq speed.
Returns:
A reply informing of the status of setting upfreq speed.
</details>
"""
if not 0 < upfreq_speed < 9:
raise APIError(
f"Upfreq speed is outside of the allowed "
f"range. Please set a number between 0 (Normal) and "
f"9 (Fastest)."
)
return await self.send_privileged_command("adjust_upfreq_speed", upfreq_speed=upfreq_speed)
async def set_poweroff_cool(self, poweroff_cool: bool):
"""Set whether to cool the machine when mining is stopped.
<details>
<summary>Expand</summary>
Set whether to cool the machine when mining is stopped, only works after
changing the password of the miner using the Whatsminer tool.
Parameters:
poweroff_cool: Whether to cool the miner during power off mode.
Returns:
A reply informing of the status of setting power off cooling mode.
</details>
"""
return await self.send_privileged_command("set_poweroff_cool", poweroff_cool=int(poweroff_cool))
async def set_fan_zero_speed(self, fan_zero_speed: bool):
"""Sets whether the fan speed supports the lowest 0 speed.
<details>
<summary>Expand</summary>
Sets whether the fan speed supports the lowest 0 speed, only works after
changing the password of the miner using the Whatsminer tool.
Parameters:
fan_zero_speed: Whether the fan is allowed to support 0 speed.
Returns:
A reply informing of the status of setting fan minimum speed.
</details>
"""
return await self.send_privileged_command("set_fan_zero_speed", fan_zero_speed=int(fan_zero_speed))
#### END privileged COMMANDS ####
async def summary(self) -> dict:

View File

@@ -41,18 +41,16 @@ class CGMinerAPI(BaseMinerAPI):
async def multicommand(
self, *commands: str, allow_warning: bool = True
) -> dict:
logging.debug(f"{self.ip}: Sending multicommand: {[*commands]}")
# make sure we can actually run each command, otherwise they will fail
commands = self._check_commands(*commands)
# standard multicommand format is "command1+command2"
# doesnt work for S19 which uses the backup _x19_multicommand
# doesn't work for S19 which uses the backup _x19_multicommand
command = "+".join(commands)
try:
data = await self.send_command(command, allow_warning=allow_warning)
except APIError:
logging.debug(f"{self.ip}: Handling X19 multicommand.")
logging.debug(f"{self} - (Multicommand) - Handling X19 multicommand.")
data = await self._x19_multicommand(*command.split("+"))
logging.debug(f"{self.ip}: Received multicommand data.")
return data
async def _x19_multicommand(self, *commands):
@@ -66,7 +64,7 @@ class CGMinerAPI(BaseMinerAPI):
except APIError as e:
raise APIError(e)
except Exception as e:
logging.warning(f"{self.ip}: API Multicommand Error: {e}")
logging.warning(f"{self} - ([Hidden] X19 Multicommand) - API Command Error {e}")
return data
async def version(self) -> dict:

View File

@@ -18,7 +18,7 @@ from pyasic.API import BaseMinerAPI
class UnknownAPI(BaseMinerAPI):
"""An abstraction of an API for a miner which is unknown.
This class is designed to try to be a intersection of as many miner APIs
This class is designed to try to be an intersection of as many miner APIs
and API commands as possible (API ⋂ API), to ensure that it can be used
with as many APIs as possible.
"""

View File

@@ -13,11 +13,12 @@
# limitations under the License.
import json
import logging
import random
import string
import time
from dataclasses import asdict, dataclass, fields
from typing import List, Literal
from typing import Dict, List, Literal
import toml
import yaml
@@ -193,7 +194,7 @@ class _PoolGroup:
return pools
def as_wm(self, user_suffix: str = None) -> List[dict]:
"""Convert the data in this class to a list usable by an Whatsminer device.
"""Convert the data in this class to a list usable by a Whatsminer device.
Parameters:
user_suffix: The suffix to append to username.
@@ -277,6 +278,7 @@ class MinerConfig:
def as_dict(self) -> dict:
"""Convert the data in this class to a dict."""
logging.debug(f"MinerConfig - (To Dict) - Dumping Dict config")
data_dict = asdict(self)
for key in asdict(self).keys():
if data_dict[key] is None:
@@ -285,10 +287,12 @@ class MinerConfig:
def as_toml(self) -> str:
"""Convert the data in this class to toml."""
logging.debug(f"MinerConfig - (To TOML) - Dumping TOML config")
return toml.dumps(self.as_dict())
def as_yaml(self) -> str:
"""Convert the data in this class to yaml."""
logging.debug(f"MinerConfig - (To YAML) - Dumping YAML config")
return yaml.dump(self.as_dict(), sort_keys=False)
def from_raw(self, data: dict):
@@ -298,6 +302,7 @@ class MinerConfig:
Parameters:
data: The raw config data to convert.
"""
logging.debug(f"MinerConfig - (From Raw) - Loading raw config")
pool_groups = []
for key in data.keys():
if key == "pools":
@@ -360,6 +365,12 @@ class MinerConfig:
return self
def from_api(self, pools: list):
"""Convert list output from the `AnyMiner.api.pools()` command into a usable data and save it to this class.
Parameters:
pools: The list of pool data to convert.
"""
logging.debug(f"MinerConfig - (From API) - Loading API config")
_pools = []
for pool in pools:
url = pool.get("URL")
@@ -374,6 +385,7 @@ class MinerConfig:
Parameters:
data: The dict config data to convert.
"""
logging.debug(f"MinerConfig - (From Dict) - Loading Dict config")
pool_groups = []
for group in data["pool_groups"]:
pool_groups.append(_PoolGroup().from_dict(group))
@@ -389,6 +401,7 @@ class MinerConfig:
Parameters:
data: The toml config data to convert.
"""
logging.debug(f"MinerConfig - (From TOML) - Loading TOML config")
return self.from_dict(toml.loads(data))
def from_yaml(self, data: str):
@@ -397,15 +410,17 @@ class MinerConfig:
Parameters:
data: The yaml config data to convert.
"""
logging.debug(f"MinerConfig - (From YAML) - Loading YAML config")
return self.from_dict(yaml.load(data, Loader=yaml.SafeLoader))
def as_wm(self, user_suffix: str = None) -> List[dict]:
"""Convert the data in this class to a config usable by an Whatsminer device.
def as_wm(self, user_suffix: str = None) -> Dict[str, int]:
"""Convert the data in this class to a config usable by a Whatsminer device.
Parameters:
user_suffix: The suffix to append to username.
"""
return self.pool_groups[0].as_wm(user_suffix=user_suffix)
logging.debug(f"MinerConfig - (As Whatsminer) - Generating Whatsminer config")
return {"pools": self.pool_groups[0].as_wm(user_suffix=user_suffix), "wattage": self.autotuning_wattage}
def as_inno(self, user_suffix: str = None) -> dict:
"""Convert the data in this class to a config usable by an Innosilicon device.
@@ -413,6 +428,7 @@ class MinerConfig:
Parameters:
user_suffix: The suffix to append to username.
"""
logging.debug(f"MinerConfig - (As Inno) - Generating Innosilicon config")
return self.pool_groups[0].as_inno(user_suffix=user_suffix)
def as_x19(self, user_suffix: str = None) -> str:
@@ -421,6 +437,7 @@ class MinerConfig:
Parameters:
user_suffix: The suffix to append to username.
"""
logging.debug(f"MinerConfig - (As X19) - Generating X19 config")
cfg = {
"pools": self.pool_groups[0].as_x19(user_suffix=user_suffix),
"bitmain-fan-ctrl": False,
@@ -444,6 +461,7 @@ class MinerConfig:
Parameters:
user_suffix: The suffix to append to username.
"""
logging.debug(f"MinerConfig - (As Avalon) - Generating AvalonMiner config")
cfg = self.pool_groups[0].as_avalon(user_suffix=user_suffix)
return cfg
@@ -454,6 +472,7 @@ class MinerConfig:
model: The model of the miner to be used in the format portion of the config.
user_suffix: The suffix to append to username.
"""
logging.debug(f"MinerConfig - (As BOS) - Generating BOSMiner config")
cfg = {
"format": {
"version": "1.2+",

View File

@@ -14,10 +14,10 @@
import copy
import json
import logging
import time
from dataclasses import asdict, dataclass, field, fields
from datetime import datetime, timezone
from functools import reduce
from typing import List, Union
from .error_codes import BraiinsOSError, InnosiliconError, WhatsminerError, X19Error
@@ -372,6 +372,7 @@ class MinerData:
Returns:
A dictionary version of this class.
"""
logging.debug(f"MinerData - (To Dict) - Dumping Dict data")
return asdict(self)
def as_json(self) -> str:
@@ -380,6 +381,7 @@ class MinerData:
Returns:
A JSON version of this class.
"""
logging.debug(f"MinerData - (To JSON) - Dumping JSON data")
data = self.asdict()
data["datetime"] = str(int(time.mktime(data["datetime"].timetuple())))
return json.dumps(data)
@@ -390,6 +392,7 @@ class MinerData:
Returns:
A CSV version of this class with no headers.
"""
logging.debug(f"MinerData - (To CSV) - Dumping CSV data")
data = self.asdict()
data["datetime"] = str(int(time.mktime(data["datetime"].timetuple())))
errs = []
@@ -408,6 +411,7 @@ class MinerData:
Returns:
A influxdb line protocol version of this class.
"""
logging.debug(f"MinerData - (To InfluxDB) - Dumping InfluxDB data")
tag_data = [measurement_name]
field_data = []

View File

@@ -349,3 +349,7 @@ class BMMiner(BaseMiner):
data.pool_split = str(quota)
return data
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -17,8 +17,8 @@ import json
import logging
from typing import List, Union
import toml
import httpx
import toml
from pyasic.API.bosminer import BOSMinerAPI
from pyasic.config import MinerConfig
@@ -83,7 +83,7 @@ class BOSMiner(BaseMiner):
d = await client.post(url, json={"query": query})
if d.status_code == 200:
return d.json()
except httpx.ReadError:
except (httpx.ReadError, httpx.ReadTimeout):
return None
return None
@@ -327,7 +327,7 @@ class BOSMiner(BaseMiner):
if board["Status"] not in [
"Stable",
"Testing performance profile",
"Tuning individual chips"
"Tuning individual chips",
]:
_error = board["Status"].split(" {")[0]
_error = _error[0].lower() + _error[1:]
@@ -356,9 +356,6 @@ class BOSMiner(BaseMiner):
],
)
board_offset = -1
fan_offset = -1
model = await self.get_model()
hostname = await self.get_hostname()
mac = await self.get_mac()
@@ -474,6 +471,16 @@ class BOSMiner(BaseMiner):
data.pool_2_user = pool_2_user
if quota:
if not quota == "0":
cfg = await self.get_config()
if cfg:
if len(cfg.pool_groups) > 1:
quota = (
str(cfg.pool_groups[0].quota)
+ "/"
+ str(cfg.pool_groups[1].quota)
)
data.pool_split = str(quota)
if tunerstatus:
@@ -484,7 +491,7 @@ class BOSMiner(BaseMiner):
wattage_limit = tuner[0].get("PowerLimit")
if wattage_limit:
data.wattage_limit = wattage_limit
if wattage:
if wattage is not None:
data.wattage = wattage
chain_status = tuner[0].get("TunerChainStatus")
@@ -551,6 +558,8 @@ class BOSMiner(BaseMiner):
if not query_data:
return None
query_data = query_data["data"]
if not query_data:
return None
data.mac = await self.get_mac()
data.model = await self.get_model()
@@ -559,9 +568,13 @@ class BOSMiner(BaseMiner):
data.hostname = query_data["bos"]["hostname"]
try:
if query_data["bosminer"]["info"]["workSolver"]["realHashrate"].get("mhs1M"):
if query_data["bosminer"]["info"]["workSolver"]["realHashrate"].get(
"mhs1M"
):
data.hashrate = round(
query_data["bosminer"]["info"]["workSolver"]["realHashrate"]["mhs1M"]
query_data["bosminer"]["info"]["workSolver"]["realHashrate"][
"mhs1M"
]
/ 1000000,
2,
)
@@ -572,9 +585,13 @@ class BOSMiner(BaseMiner):
if query_data.get("bosminer"):
if query_data["bosminer"].get("info"):
if query_data["bosminer"]["info"].get("workSolver"):
boards = query_data["bosminer"]["info"]["workSolver"].get("childSolvers")
boards = query_data["bosminer"]["info"]["workSolver"].get(
"childSolvers"
)
if boards:
offset = 6 if int(boards[0]["name"]) in [6, 7, 8] else int(boards[0]["name"])
offset = (
6 if int(boards[0]["name"]) in [6, 7, 8] else int(boards[0]["name"])
)
for hb in boards:
_id = int(hb["name"]) - offset
@@ -601,24 +618,33 @@ class BOSMiner(BaseMiner):
if hb["tuner"]["statusMessages"][0] not in [
"Stable",
"Testing performance profile",
"Tuning individual chips"
"Tuning individual chips",
]:
data.errors.append(
BraiinsOSError(f"Slot {_id} {hb['tuner']['statusMessages'][0]}")
BraiinsOSError(
f"Slot {_id} {hb['tuner']['statusMessages'][0]}"
)
)
try:
data.wattage = query_data["bosminer"]["info"]["workSolver"]["power"]["approxConsumptionW"]
data.wattage = query_data["bosminer"]["info"]["workSolver"]["power"][
"approxConsumptionW"
]
except (TypeError, KeyError, ValueError, IndexError):
pass
data.wattage = 0
try:
data.wattage_limit = query_data["bosminer"]["info"]["workSolver"]["power"]["limitW"]
data.wattage_limit = query_data["bosminer"]["info"]["workSolver"]["power"][
"limitW"
]
except (TypeError, KeyError, ValueError, IndexError):
pass
for n in range(self.fan_count):
try:
setattr(data, f"fan_{n + 1}", query_data["bosminer"]["info"]["fans"][n]["rpm"])
setattr(
data,
f"fan_{n + 1}",
query_data["bosminer"]["info"]["fans"][n]["rpm"],
)
except (TypeError, KeyError, ValueError, IndexError):
pass
@@ -633,7 +659,11 @@ class BOSMiner(BaseMiner):
except (TypeError, KeyError, ValueError, IndexError):
pass
try:
data.pool_1_url = groups[0]["pools"][0]["url"]
data.pool_1_url = (
groups[0]["pools"][0]["url"]
.replace("stratum+tcp://", "")
.replace("stratum2+tcp://", "")
)
except (TypeError, KeyError, ValueError, IndexError):
pass
try:
@@ -641,7 +671,11 @@ class BOSMiner(BaseMiner):
except (TypeError, KeyError, ValueError, IndexError):
pass
try:
data.pool_2_url = groups[0]["pools"][1]["url"]
data.pool_2_url = (
groups[0]["pools"][1]["url"]
.replace("stratum+tcp://", "")
.replace("stratum2+tcp://", "")
)
except (TypeError, KeyError, ValueError, IndexError):
pass
data.quota = 0
@@ -651,7 +685,11 @@ class BOSMiner(BaseMiner):
except (TypeError, KeyError, ValueError, IndexError):
pass
try:
data.pool_1_url = groups[0]["pools"][0]["url"]
data.pool_1_url = (
groups[0]["pools"][0]["url"]
.replace("stratum+tcp://", "")
.replace("stratum2+tcp://", "")
)
except (TypeError, KeyError, ValueError, IndexError):
pass
try:
@@ -659,11 +697,19 @@ class BOSMiner(BaseMiner):
except (TypeError, KeyError, ValueError, IndexError):
pass
try:
data.pool_2_url = groups[1]["pools"][0]["url"]
data.pool_2_url = (
groups[1]["pools"][0]["url"]
.replace("stratum+tcp://", "")
.replace("stratum2+tcp://", "")
)
except (TypeError, KeyError, ValueError, IndexError):
pass
if groups[0]["strategy"].get("quota"):
data.quota = groups[0]["strategy"]["quota"] + "/" + groups[1]["strategy"]["quota"]
data.pool_split = (
str(groups[0]["strategy"]["quota"])
+ "/"
+ str(groups[1]["strategy"]["quota"])
)
data.fault_light = await self.check_light()
@@ -672,3 +718,14 @@ class BOSMiner(BaseMiner):
async def get_mac(self):
result = await self.send_ssh_command("cat /sys/class/net/eth0/address")
return result.upper().strip()
async def set_power_limit(self, wattage: int) -> bool:
try:
cfg = await self.get_config()
cfg.autotuning_wattage = wattage
await self.send_config(cfg)
except Exception as e:
logging.warning(f"{self} set_power_limit: {e}")
return False
else:
return True

View File

@@ -104,5 +104,8 @@ class BOSMinerOld(BaseMiner):
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
return None
async def get_data(self) -> MinerData:
async def get_data(self, **kwargs) -> MinerData:
return MinerData(ip=str(self.ip))
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -196,14 +196,20 @@ class BTMiner(BaseMiner):
return False
async def stop_mining(self) -> bool:
data = await self.api.power_off(respbefore=True)
try:
data = await self.api.power_off(respbefore=True)
except APIError:
return False
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
return False
async def resume_mining(self) -> bool:
data = await self.api.power_on()
try:
data = await self.api.power_on()
except APIError:
return False
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
@@ -211,31 +217,45 @@ class BTMiner(BaseMiner):
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
conf = config.as_wm(user_suffix=user_suffix)
pools_conf = conf["pools"]
await self.api.update_pools(
conf[0]["url"],
conf[0]["user"],
conf[0]["pass"],
conf[1]["url"],
conf[1]["user"],
conf[1]["pass"],
conf[2]["url"],
conf[2]["user"],
conf[2]["pass"],
pools_conf[0]["url"],
pools_conf[0]["user"],
pools_conf[0]["pass"],
pools_conf[1]["url"],
pools_conf[1]["user"],
pools_conf[1]["pass"],
pools_conf[2]["url"],
pools_conf[2]["user"],
pools_conf[2]["pass"],
)
try:
await self.api.adjust_power_limit(conf["wattage"])
except APIError:
# cannot set wattage
pass
async def get_config(self) -> MinerConfig:
pools = None
summary = None
cfg = MinerConfig()
try:
pools = await self.api.pools()
data = await self.api.multicommand("pools", "summary")
pools = data["pools"][0]
summary = data["summary"][0]
except APIError as e:
logging.warning(e)
if pools:
if "POOLS" in pools.keys():
if "POOLS" in pools:
cfg = cfg.from_api(pools["POOLS"])
if summary:
if "SUMMARY" in summary:
if wattage := summary["SUMMARY"][0].get("Power Limit"):
cfg.autotuning_wattage = wattage
return cfg
async def get_data(self, allow_warning: bool = True) -> MinerData:
@@ -432,3 +452,13 @@ class BTMiner(BaseMiner):
data.mac = mac
return data
async def set_power_limit(self, wattage: int) -> bool:
try:
await self.api.adjust_power_limit(wattage)
except Exception as e:
logging.warning(f"{self} set_power_limit: {e}")
return False
else:
return True

View File

@@ -335,3 +335,6 @@ class CGMiner(BaseMiner):
data.pool_split = str(quota)
return data
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -61,3 +61,6 @@ class Hiveon(BMMiner):
bad_boards[board] = []
bad_boards[board].append(chain)
return bad_boards
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S17(BaseMiner):
class S17(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S17Plus(BaseMiner):
class S17Plus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S17Pro(BaseMiner):
class S17Pro(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S17e(BaseMiner):
class S17e(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class T17(BaseMiner):
class T17(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class T17Plus(BaseMiner):
class T17Plus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class T17e(BaseMiner):
class T17e(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S19(BaseMiner):
class S19(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S19Pro(BaseMiner):
class S19Pro(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S19XP(BaseMiner):
class S19XP(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S19a(BaseMiner):
class S19a(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -0,0 +1,24 @@
# Copyright 2022 Upstream Data Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pyasic.miners.base import BaseMiner
class S19aPro(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "S19a Pro"
self.nominal_chips = 100
self.fan_count = 4

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S19j(BaseMiner):
class S19j(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S19jPro(BaseMiner):
class S19jPro(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class T19(BaseMiner):
class T19(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -16,6 +16,7 @@ from .S19 import S19
from .S19_Pro import S19Pro
from .S19_XP import S19XP
from .S19a import S19a
from .S19a_Pro import S19aPro
from .S19j import S19j
from .S19j_Pro import S19jPro
from .T19 import T19

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S9(BaseMiner):
class S9(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class S9i(BaseMiner):
class S9i(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class T9(BaseMiner):
class T9(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class Avalon1026(BaseMiner):
class Avalon1026(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class Avalon1047(BaseMiner):
class Avalon1047(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class Avalon1066(BaseMiner):
class Avalon1066(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon721(BaseMiner):
class Avalon721(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 721"
self.chip_count = 18 # This miner has 4 boards totaling 72
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 18
self.fan_count = 1

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon741(BaseMiner):
class Avalon741(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 741"
self.chip_count = 22 # This miner has 4 boards totaling 88
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 22
self.fan_count = 1

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon761(BaseMiner):
class Avalon761(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 761"
self.chip_count = 18 # This miner has 4 boards totaling 72
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 18
self.fan_count = 1

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon821(BaseMiner):
class Avalon821(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 821"
self.chip_count = 26 # This miner has 4 boards totaling 104
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 26
self.fan_count = 1

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon841(BaseMiner):
class Avalon841(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 841"
self.chip_count = 26 # This miner has 4 boards totaling 104
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 26
self.fan_count = 1

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon851(BaseMiner):
class Avalon851(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 851"
self.chip_count = 26 # This miner has 4 boards totaling 104
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 26
self.fan_count = 1

View File

@@ -15,10 +15,11 @@
from pyasic.miners.base import BaseMiner
class Avalon921(BaseMiner):
class Avalon921(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "Avalon 921"
self.chip_count = 26 # This miner has 4 boards totaling 104
self.fan_count = 1 # also only 1 fan
self.ideal_hashboards = 4
self.chip_count = 26
self.fan_count = 1

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class InnosiliconT3HPlus(BaseMiner):
class InnosiliconT3HPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str) -> None:
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M20(BaseMiner):
class M20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M20(BaseMiner):
self.fan_count = 2
class M20V10(BaseMiner):
class M20V10(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M20S(BaseMiner):
class M20S(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M20S(BaseMiner):
self.fan_count = 2
class M20SV10(BaseMiner):
class M20SV10(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -33,7 +33,7 @@ class M20SV10(BaseMiner):
self.fan_count = 2
class M20SV20(BaseMiner):
class M20SV20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M20SPlus(BaseMiner):
class M20SPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M21(BaseMiner):
class M21(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M21S(BaseMiner):
class M21S(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M21S(BaseMiner):
self.fan_count = 2
class M21SV60(BaseMiner):
class M21SV60(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -33,7 +33,7 @@ class M21SV60(BaseMiner):
self.fan_count = 2
class M21SV20(BaseMiner):
class M21SV20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M21SPlus(BaseMiner):
class M21SPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M30S(BaseMiner):
class M30S(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M30S(BaseMiner):
self.fan_count = 2
class M30SV50(BaseMiner):
class M30SV50(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -33,7 +33,7 @@ class M30SV50(BaseMiner):
self.fan_count = 2
class M30SVG20(BaseMiner):
class M30SVG20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -42,7 +42,7 @@ class M30SVG20(BaseMiner):
self.fan_count = 2
class M30SVE20(BaseMiner):
class M30SVE20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -51,7 +51,7 @@ class M30SVE20(BaseMiner):
self.fan_count = 2
class M30SVE10(BaseMiner):
class M30SVE10(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M30SPlus(BaseMiner):
class M30SPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M30SPlus(BaseMiner):
self.fan_count = 2
class M30SPlusVG60(BaseMiner):
class M30SPlusVG60(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -32,8 +32,16 @@ class M30SPlusVG60(BaseMiner):
self.nominal_chips = 86
self.fan_count = 2
class M30SPlusVG40(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "M30S+ VG40"
self.nominal_chips = 105
self.fan_count = 2
class M30SPlusVE40(BaseMiner):
class M30SPlusVE40(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -42,7 +50,7 @@ class M30SPlusVE40(BaseMiner):
self.fan_count = 2
class M30SPlusVF20(BaseMiner):
class M30SPlusVF20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M30SPlusPlus(BaseMiner):
class M30SPlusPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M30SPlusPlus(BaseMiner):
self.fan_count = 2
class M30SPlusPlusVG30(BaseMiner):
class M30SPlusPlusVG30(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -33,7 +33,7 @@ class M30SPlusPlusVG30(BaseMiner):
self.fan_count = 2
class M30SPlusPlusVG40(BaseMiner):
class M30SPlusPlusVG40(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -42,7 +42,7 @@ class M30SPlusPlusVG40(BaseMiner):
self.fan_count = 2
class M30SPlusPlusVH60(BaseMiner):
class M30SPlusPlusVH60(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,10 +15,44 @@
from pyasic.miners.base import BaseMiner
class M31S(BaseMiner):
class M31S(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "M31S"
# TODO: Add chip count for this miner (per board) - self.nominal_chips
self.nominal_chips = 111
self.fan_count = 2
class M31SV10(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "M31S V10"
self.nominal_chips = 105
self.fan_count = 2
class M31SV20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "M31S V20"
self.nominal_chips = 111
self.fan_count = 2
class M31SV60(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "M31S V60"
self.nominal_chips = 105
self.fan_count = 2
class M31SV70(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
self.model = "M31S V70"
self.nominal_chips = 111
self.fan_count = 2

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M31SPlus(BaseMiner):
class M31SPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M31SPlus(BaseMiner):
self.fan_count = 2
class M31SPlusVE20(BaseMiner):
class M31SPlusVE20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -33,7 +33,7 @@ class M31SPlusVE20(BaseMiner):
self.fan_count = 2
class M31SPlusV30(BaseMiner):
class M31SPlusV30(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -42,7 +42,7 @@ class M31SPlusV30(BaseMiner):
self.fan_count = 2
class M31SPlusV40(BaseMiner):
class M31SPlusV40(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -51,7 +51,7 @@ class M31SPlusV40(BaseMiner):
self.fan_count = 2
class M31SPlusV60(BaseMiner):
class M31SPlusV60(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -60,7 +60,7 @@ class M31SPlusV60(BaseMiner):
self.fan_count = 2
class M31SPlusV80(BaseMiner):
class M31SPlusV80(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -69,7 +69,7 @@ class M31SPlusV80(BaseMiner):
self.fan_count = 2
class M31SPlusV90(BaseMiner):
class M31SPlusV90(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M32(BaseMiner):
class M32(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M32(BaseMiner):
self.fan_count = 2
class M32V20(BaseMiner):
class M32V20(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M32S(BaseMiner):
class M32S(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M34SPlus(BaseMiner):
class M34SPlus(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -25,7 +25,7 @@ class M34SPlus(BaseMiner):
self.fan_count = 0
class M34SPlusVE10(BaseMiner):
class M34SPlusVE10(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -13,14 +13,14 @@
# limitations under the License.
from .M30S import M30S, M30SV50, M30SVE10, M30SVE20, M30SVG20
from .M30S_Plus import M30SPlus, M30SPlusVE40, M30SPlusVF20, M30SPlusVG60
from .M30S_Plus import M30SPlus, M30SPlusVE40, M30SPlusVF20, M30SPlusVG60, M30SPlusVG40
from .M30S_Plus_Plus import (
M30SPlusPlus,
M30SPlusPlusVG30,
M30SPlusPlusVG40,
M30SPlusPlusVH60,
)
from .M31S import M31S
from .M31S import M31S, M31SV10, M31SV20, M31SV60, M31SV70
from .M31S_Plus import (
M31SPlus,
M31SPlusV30,

View File

@@ -15,7 +15,7 @@
from pyasic.miners.base import BaseMiner
class M50(BaseMiner):
class M50(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip
@@ -24,7 +24,7 @@ class M50(BaseMiner):
self.fan_count = 2
class M50VH50(BaseMiner):
class M50VH50(BaseMiner): # noqa - ignore ABC method implementation
def __init__(self, ip: str):
super().__init__()
self.ip = ip

View File

@@ -0,0 +1,23 @@
# Copyright 2022 Upstream Data Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pyasic.miners._types import S19aPro # noqa - Ignore access to _module
from .X19 import BMMinerX19
class BMMinerS19aPro(BMMinerX19, S19aPro):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip

View File

@@ -62,7 +62,7 @@ class BMMinerX19(BMMiner):
try:
async with httpx.AsyncClient() as client:
await client.post(url, data=conf, auth=auth)
await client.post(url, data=conf, auth=auth) # noqa - ignore conf being a str
except httpx.ReadTimeout:
pass
for i in range(7):
@@ -102,7 +102,7 @@ class BMMinerX19(BMMiner):
auth = httpx.DigestAuth(self.uname, self.pwd)
data = json.dumps({"blink": "true"})
async with httpx.AsyncClient() as client:
data = await client.post(url, data=data, auth=auth)
data = await client.post(url, data=data, auth=auth) # noqa - ignore conf being a str
if data.status_code == 200:
data = data.json()
if data.get("code") == "B000":
@@ -115,7 +115,7 @@ class BMMinerX19(BMMiner):
auth = httpx.DigestAuth(self.uname, self.pwd)
data = json.dumps({"blink": "false"})
async with httpx.AsyncClient() as client:
data = await client.post(url, data=data, auth=auth)
data = await client.post(url, data=data, auth=auth) # noqa - ignore conf being a str
if data.status_code == 200:
data = data.json()
if data.get("code") == "B100":
@@ -139,7 +139,10 @@ class BMMinerX19(BMMiner):
async with httpx.AsyncClient() as client:
data = await client.get(url, auth=auth)
if data:
data = data.json()
try:
data = data.json()
except json.decoder.JSONDecodeError:
return []
if "SUMMARY" in data.keys():
if "status" in data["SUMMARY"][0].keys():
for item in data["SUMMARY"][0]["status"]:

View File

@@ -16,6 +16,7 @@ from .S19 import BMMinerS19
from .S19_Pro import BMMinerS19Pro
from .S19_XP import BMMinerS19XP
from .S19a import BMMinerS19a
from .S19a_Pro import BMMinerS19aPro
from .S19j import BMMinerS19j
from .S19j_Pro import BMMinerS19jPro
from .T19 import BMMinerT19

View File

@@ -44,7 +44,6 @@ class HiveonT9(Hiveon, T9):
ideal_hashboards=self.ideal_hashboards,
)
board_offset = -1
fan_offset = -1
model = await self.get_model()

View File

@@ -15,19 +15,13 @@
import ipaddress
import logging
from abc import ABC, abstractmethod
from typing import List, TypeVar, Union
from typing import List, TypeVar
import asyncssh
from pyasic.config import MinerConfig
from pyasic.data import MinerData
from pyasic.data.error_codes import (
BraiinsOSError,
InnosiliconError,
MinerErrorData,
WhatsminerError,
X19Error,
)
from pyasic.data.error_codes import MinerErrorData
class BaseMiner(ABC):
@@ -52,7 +46,7 @@ class BaseMiner(ABC):
return object.__new__(cls)
def __repr__(self):
return f"{'' if not self.api_type else self.api_type} {'' if not self.model else self.model}: {str(self.ip)}"
return f"{'' if not self.api_type else self.api_type}{'' if not self.model else ' ' + self.model}: {str(self.ip)}"
def __lt__(self, other):
return ipaddress.ip_address(self.ip) < ipaddress.ip_address(other.ip)
@@ -220,4 +214,15 @@ class BaseMiner(ABC):
pass
@abstractmethod
async def set_power_limit(self, wattage: int) -> bool:
"""Set the power limit to be used by the miner.
Parameters:
wattage: The power limit to set on the miner.
Returns:
A boolean value of the success of setting the power limit.
"""
AnyMiner = TypeVar("AnyMiner", bound=BaseMiner)

View File

@@ -169,9 +169,6 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
],
)
board_offset = -1
fan_offset = -1
model = await self.get_model()
hostname = await self.get_hostname()

View File

@@ -131,6 +131,10 @@ MINER_CLASSES = {
"Default": BMMinerS19a,
"BMMiner": BMMinerS19a,
},
"ANTMINER S19A PRO": {
"Default": BMMinerS19aPro,
"BMMiner": BMMinerS19aPro,
},
"ANTMINER T19": {
"Default": BMMinerT19,
"BOSMiner+": BOSMinerT19,
@@ -179,6 +183,7 @@ MINER_CLASSES = {
"BTMiner": BTMinerM30SPlus,
"F20": BTMinerM30SPlusVF20,
"E40": BTMinerM30SPlusVE40,
"G40": BTMinerM30SPlusVG40,
"G60": BTMinerM30SPlusVG60,
},
"M30S++": {
@@ -186,10 +191,15 @@ MINER_CLASSES = {
"BTMiner": BTMinerM30SPlusPlus,
"G40": BTMinerM30SPlusPlusVG40,
"G30": BTMinerM30SPlusPlusVG30,
"H60": BTMinerM30SPlusPlusVH60,
},
"M31S": {
"Default": BTMinerM31S,
"BTMiner": BTMinerM31S,
"10": BTMinerM31SV10,
"20": BTMinerM31SV20,
"60": BTMinerM31SV60,
"70": BTMinerM31SV70,
},
"M31S+": {
"Default": BTMinerM31SPlus,
@@ -337,7 +347,6 @@ class MinerFactory(metaclass=Singleton):
break
except asyncio.TimeoutError:
logging.warning(f"{ip}: Get Miner Timed Out")
miner = self._select_miner_from_classes(ip, model, api, ver)
# save the miner to the cache at its IP if its not unknown
@@ -412,7 +421,9 @@ class MinerFactory(metaclass=Singleton):
# miner refused connection on API port, we wont be able to get data this way
# try ssh
try:
_model = await self.__get_model_from_ssh(ip)
_model = await self.__get_model_from_graphql(ip)
if not _model:
_model = await self.__get_model_from_ssh(ip)
if _model:
model = _model
api = "BOSMiner+"
@@ -433,12 +444,6 @@ class MinerFactory(metaclass=Singleton):
# if we have devdetails, we can get model data from there
if devdetails:
if devdetails == {"Msg": "Disconnected"}:
model = await self.__get_model_from_graphql(ip)
if model:
api = "BOSMiner+"
return model, api, ver
for _devdetails_key in ["Model", "Driver"]:
try:
model = devdetails["DEVDETAILS"][0][_devdetails_key].upper()
@@ -446,15 +451,47 @@ class MinerFactory(metaclass=Singleton):
break
except KeyError:
continue
if not model:
# braiins OS bug check just in case
if "s9" in devdetails["STATUS"][0]["Description"]:
model = "ANTMINER S9"
if "s17" in version["STATUS"][0]["Description"]:
model = "ANTMINER S17"
try:
if devdetails[0]["STATUS"][0]["Msg"]:
model = await self.__get_model_from_graphql(ip)
if model:
api = "BOSMiner+"
except (KeyError, TypeError, ValueError, IndexError):
pass
try:
if not model:
# braiins OS bug check just in case
if "s9" in devdetails["STATUS"][0]["Description"]:
model = "ANTMINER S9"
if "s17" in version["STATUS"][0]["Description"]:
model = "ANTMINER S17"
except (KeyError, TypeError, ValueError, IndexError):
pass
try:
if not api:
if "boser" in version["STATUS"][0]["Description"]:
api = "BOSMiner+"
except (KeyError, TypeError, ValueError, IndexError):
pass
else:
try:
_model = await self.__get_model_from_graphql(ip)
if _model:
model = _model
api = "BOSMiner+"
except (KeyError, TypeError, ValueError, IndexError):
pass
# if we have version we can get API type from here
if version:
try:
if version[0]["STATUS"][0]["Msg"]:
model = await self.__get_model_from_graphql(ip)
if model:
api = "BOSMiner+"
return model, api, ver
except (KeyError, TypeError, ValueError, IndexError):
pass
if "VERSION" in version:
api_types = ["BMMiner", "CGMiner", "BTMiner"]
# check basic API types, BOSMiner needs a special check
@@ -470,6 +507,8 @@ class MinerFactory(metaclass=Singleton):
api = "BOSMiner+"
if "BOSminer+" in version["VERSION"][0]:
api = "BOSMiner+"
if any("BOSer" in string for string in version["VERSION"][0]):
api = "BOSMiner+"
# check for avalonminers
for _version_key in ["PROD", "MODEL"]:
@@ -533,7 +572,6 @@ class MinerFactory(metaclass=Singleton):
# don't need "Bitmain", just "ANTMINER XX" as model
if "BITMAIN " in model:
model = model.replace("BITMAIN ", "")
return model, api, ver
async def __get_devdetails_and_version(
@@ -548,8 +586,8 @@ class MinerFactory(metaclass=Singleton):
if not validation[0]:
try:
if data["version"][0]["STATUS"][0]["Msg"] == "Disconnected":
return {"Msg": "Disconnected"}, None
except KeyError:
return data["devdetails"], data["version"]
except (KeyError, TypeError):
pass
raise APIError(validation[1])
# copy each part of the main command to devdetails and version
@@ -605,7 +643,7 @@ class MinerFactory(metaclass=Singleton):
async with httpx.AsyncClient() as client:
d = await client.post(url, json={"query": "{bosminer {info{modelName}}}"})
if d.status_code == 200:
model = d.json()["data"]["bosminer"]["info"]["modelName"].upper()
model = (d.json()["data"]["bosminer"]["info"]["modelName"]).upper()
return model
@staticmethod

View File

@@ -74,3 +74,6 @@ class UnknownMiner(BaseMiner):
async def get_data(self, allow_warning: bool = False) -> MinerData:
return MinerData(ip=str(self.ip))
async def set_power_limit(self, wattage: int) -> bool:
return False

View File

@@ -18,6 +18,7 @@ from pyasic.miners._types import ( # noqa - Ignore access to _module
M30SPlusVE40,
M30SPlusVF20,
M30SPlusVG60,
M30SPlusVG40,
)
@@ -39,6 +40,12 @@ class BTMinerM30SPlusVE40(BTMiner, M30SPlusVE40):
self.ip = ip
class BTMinerM30SPlusVG40(BTMiner, M30SPlusVG40):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
class BTMinerM30SPlusVG60(BTMiner, M30SPlusVG60):
def __init__(self, ip: str) -> None:
super().__init__(ip)

View File

@@ -13,10 +13,33 @@
# limitations under the License.
from pyasic.miners._backends import BTMiner # noqa - Ignore access to _module
from pyasic.miners._types import M31S # noqa - Ignore access to _module
from pyasic.miners._types import M31S, M31SV10, M31SV20, M31SV60, M31SV70 # noqa - Ignore access to _module
class BTMinerM31S(BTMiner, M31S):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
class BTMinerM31SV20(BTMiner, M31SV20):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
class BTMinerM31SV10(BTMiner, M31SV10):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
class BTMinerM31SV60(BTMiner, M31SV60):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip
class BTMinerM31SV70(BTMiner, M31SV70):
def __init__(self, ip: str) -> None:
super().__init__(ip)
self.ip = ip

View File

@@ -23,6 +23,7 @@ from .M30S_Plus import (
BTMinerM30SPlus,
BTMinerM30SPlusVE40,
BTMinerM30SPlusVF20,
BTMinerM30SPlusVG40,
BTMinerM30SPlusVG60,
)
from .M30S_Plus_Plus import (
@@ -31,7 +32,7 @@ from .M30S_Plus_Plus import (
BTMinerM30SPlusPlusVG40,
BTMinerM30SPlusPlusVH60,
)
from .M31S import BTMinerM31S
from .M31S import BTMinerM31S, BTMinerM31SV10, BTMinerM31SV20, BTMinerM31SV60, BTMinerM31SV70
from .M31S_Plus import (
BTMinerM31SPlus,
BTMinerM31SPlusV30,

View File

@@ -90,7 +90,7 @@ class MinerNetwork:
f"{self.ip_addr}/{subnet_mask}", strict=False
)
logging.debug(f"Setting MinerNetwork: {self.network}")
logging.debug(f"{self} - (Get Network) - Found network")
return self.network
async def scan_network_for_miners(self) -> List[AnyMiner]:
@@ -101,7 +101,7 @@ class MinerNetwork:
"""
# get the network
local_network = self.get_network()
logging.debug(f"Scanning {local_network} for miners")
logging.debug(f"{self} - (Scan Network For Miners) - Scanning")
# clear cached miners
MinerFactory().clear_cached_miners()
@@ -110,27 +110,13 @@ class MinerNetwork:
scan_tasks = []
miners = []
# for each IP in the network
for host in local_network.hosts():
# make sure we don't exceed the allowed async tasks
if len(scan_tasks) < round(PyasicSettings().network_scan_threads):
# add the task to the list
scan_tasks.append(self.ping_and_get_miner(host))
else:
# run the scan tasks
miners_scan = await asyncio.gather(*scan_tasks)
# add scanned miners to the list of found miners
miners.extend(miners_scan)
# empty the task list
scan_tasks = []
# do a final scan to empty out the list
miners_scan = await asyncio.gather(*scan_tasks)
miners.extend(miners_scan)
limit = asyncio.Semaphore(PyasicSettings().network_scan_threads)
miners = await asyncio.gather(*[self.ping_and_get_miner(host, limit) for host in local_network.hosts()])
# remove all None from the miner list
miners = list(filter(None, miners))
logging.debug(f"Found {len(miners)} connected miners")
logging.debug(f"{self} - (Scan Network For Miners) - Found {len(miners)} miners")
# return the miner objects
return miners
@@ -151,60 +137,47 @@ class MinerNetwork:
# create a list of scan tasks
scan_tasks = []
# for each ip on the network, loop through and scan it
for host in local_network.hosts():
# make sure we don't exceed the allowed async tasks
if len(scan_tasks) >= round(PyasicSettings().network_scan_threads):
# scanned is a loopable list of awaitables
scanned = asyncio.as_completed(scan_tasks)
# when we scan, empty the scan tasks
scan_tasks = []
# yield miners as they are scanned
for miner in scanned:
yield await miner
# add the ping to the list of tasks if we dont scan
scan_tasks.append(loop.create_task(self.ping_and_get_miner(host)))
# do one last scan at the end to close out the list
scanned = asyncio.as_completed(scan_tasks)
for miner in scanned:
limit = asyncio.Semaphore(PyasicSettings().network_scan_threads)
miners = asyncio.as_completed([loop.create_task(self.ping_and_get_miner(host, limit)) for host in local_network.hosts()])
for miner in miners:
yield await miner
@staticmethod
async def ping_miner(ip: ipaddress.ip_address) -> Union[None, ipaddress.ip_address]:
try:
miner = await ping_miner(ip)
if miner:
return miner
except ConnectionRefusedError:
tasks = [ping_miner(ip, port=port) for port in [4029, 8889]]
for miner in asyncio.as_completed(tasks):
try:
miner = await miner
if miner:
return miner
except ConnectionRefusedError:
pass
async def ping_miner(ip: ipaddress.ip_address, semaphore: asyncio.Semaphore) -> Union[None, ipaddress.ip_address]:
async with semaphore:
try:
miner = await ping_miner(ip)
if miner:
return miner
except ConnectionRefusedError:
tasks = [ping_miner(ip, port=port) for port in [4029, 8889]]
for miner in asyncio.as_completed(tasks):
try:
miner = await miner
if miner:
return miner
except ConnectionRefusedError:
pass
@staticmethod
async def ping_and_get_miner(
ip: ipaddress.ip_address,
ip: ipaddress.ip_address, semaphore: asyncio.Semaphore
) -> Union[None, AnyMiner]:
try:
miner = await ping_and_get_miner(ip)
if miner:
return miner
except ConnectionRefusedError:
tasks = [ping_and_get_miner(ip, port=port) for port in [4029, 8889]]
for miner in asyncio.as_completed(tasks):
try:
miner = await miner
if miner:
return miner
except ConnectionRefusedError:
pass
async with semaphore:
try:
miner = await ping_and_get_miner(ip)
if miner:
return miner
except ConnectionRefusedError:
tasks = [ping_and_get_miner(ip, port=port) for port in [4029, 8889]]
for miner in asyncio.as_completed(tasks):
try:
miner = await miner
if miner:
return miner
except ConnectionRefusedError:
pass
async def ping_miner(
@@ -262,6 +235,6 @@ async def ping_and_get_miner(
raise e
# ping failed, likely with an exception
except Exception as e:
logging.warning(f"{str(ip)}: {e}")
logging.warning(f"{str(ip)}: Ping And Get Miner Exception: {e}")
continue
return

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyasic"
version = "0.21.6"
version = "0.24.4"
description = "A set of modules for interfacing with many common types of ASIC bitcoin miners, using both their API and SSH."
authors = ["UpstreamData <brett@upstreamdata.ca>"]
repository = "https://github.com/UpstreamData/pyasic"

View File

@@ -16,10 +16,9 @@ import inspect
import sys
import unittest
from pyasic.miners._backends import CGMiner
from pyasic.miners._backends import CGMiner # noqa
from pyasic.miners.base import BaseMiner
from pyasic.miners.miner_factory import MINER_CLASSES, MinerFactory
from pyasic.miners.miner_listener import MinerListener
class MinersTest(unittest.TestCase):

View File

@@ -16,7 +16,6 @@ import ipaddress
import unittest
from pyasic.network import MinerNetwork
from pyasic.network.net_range import MinerNetworkRange
class NetworkTest(unittest.TestCase):