Compare commits

...

2 Commits

Author SHA1 Message Date
UpstreamData
c95c58138e bump version number 2022-09-22 10:07:31 -06:00
UpstreamData
03c93b4de1 added pause_mining and resume_mining to all miners, added get_errors to whatsminers, and improved get_errors type hinting 2022-09-22 10:06:27 -06:00
16 changed files with 165 additions and 29 deletions

View File

@@ -118,6 +118,8 @@ These functions are
[`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).
<br>
@@ -202,6 +204,22 @@ These functions are
<br>
### Stop Mining
::: pyasic.miners.BaseMiner.stop_mining
handler: python
options:
heading_level: 4
<br>
### Resume Mining
::: pyasic.miners.BaseMiner.resume_mining
handler: python
options:
heading_level: 4
<br>
### Send Config
::: pyasic.miners.BaseMiner.send_config
handler: python

View File

@@ -16,3 +16,9 @@ from .whatsminer import WhatsminerError
from .bos import BraiinsOSError
from .X19 import X19Error
from .innosilicon import InnosiliconError
from typing import TypeVar
MinerErrorData = TypeVar(
"MinerErrorData", WhatsminerError, BraiinsOSError, X19Error, InnosiliconError
)

View File

@@ -14,7 +14,7 @@
import ipaddress
import logging
from typing import Union
from typing import Union, List
from pyasic.API.bmminer import BMMinerAPI
@@ -22,6 +22,7 @@ from pyasic.miners.base import BaseMiner
from pyasic.data import MinerData
from pyasic.config import MinerConfig
from pyasic.data.error_codes import MinerErrorData
from pyasic.settings import PyasicSettings
@@ -169,7 +170,7 @@ class BMMiner(BaseMiner):
async def fault_light_on(self) -> bool:
return False
async def get_errors(self) -> list:
async def get_errors(self) -> List[MinerErrorData]:
return []
async def get_mac(self) -> str:
@@ -178,6 +179,12 @@ class BMMiner(BaseMiner):
async def restart_backend(self) -> bool:
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def get_data(self) -> MinerData:
"""Get data from the miner.

View File

@@ -15,7 +15,7 @@
import ipaddress
import logging
import json
from typing import Union
from typing import Union, List
import toml
@@ -24,7 +24,7 @@ from pyasic.miners.base import BaseMiner
from pyasic.API.bosminer import BOSMinerAPI
from pyasic.errors import APIError
from pyasic.data.error_codes import BraiinsOSError
from pyasic.data.error_codes import BraiinsOSError, MinerErrorData
from pyasic.data import MinerData
from pyasic.config import MinerConfig
@@ -103,6 +103,20 @@ class BOSMiner(BaseMiner):
return True
return False
async def stop_mining(self) -> bool:
data = await self.api.pause()
if data.get("PAUSE"):
if data["PAUSE"][0]:
return True
return False
async def resume_mining(self) -> bool:
data = await self.api.resume()
if data.get("RESUME"):
if data["RESUME"][0]:
return True
return False
async def reboot(self) -> bool:
"""Reboots power to the physical miner."""
logging.debug(f"{self}: Sending reboot command.")
@@ -242,7 +256,7 @@ class BOSMiner(BaseMiner):
self.light = True
return self.light
async def get_errors(self) -> list:
async def get_errors(self) -> List[MinerErrorData]:
tunerstatus = None
errors = []

View File

@@ -15,12 +15,13 @@
import logging
import ipaddress
from typing import Union
from typing import Union, List
from pyasic.API.bosminer import BOSMinerAPI
from pyasic.miners.base import BaseMiner
from pyasic.config import MinerConfig
from pyasic.data import MinerData
from pyasic.data.error_codes import MinerErrorData
class BOSMinerOld(BaseMiner):
@@ -77,7 +78,7 @@ class BOSMinerOld(BaseMiner):
async def get_config(self) -> None:
return None
async def get_errors(self) -> list:
async def get_errors(self) -> List[MinerErrorData]:
return []
async def get_hostname(self) -> str:
@@ -95,6 +96,12 @@ class BOSMinerOld(BaseMiner):
async def restart_backend(self) -> bool:
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
return None

View File

@@ -14,7 +14,7 @@
import ipaddress
import logging
from typing import Union
from typing import Union, List
from pyasic.API.btminer import BTMinerAPI
@@ -22,7 +22,7 @@ from pyasic.miners.base import BaseMiner
from pyasic.errors import APIError
from pyasic.data import MinerData
from pyasic.data.error_codes import WhatsminerError
from pyasic.data.error_codes import WhatsminerError, MinerErrorData
from pyasic.config import MinerConfig
from pyasic.settings import PyasicSettings
@@ -156,13 +156,44 @@ class BTMiner(BaseMiner):
return True
return False
async def get_errors(self) -> list:
return []
async def get_errors(self) -> List[MinerErrorData]:
data = []
summary_data = await self.api.summary()
if summary_data[0].get("Error Code Count"):
for i in range(summary_data[0]["Error Code Count"]):
if summary_data[0].get(f"Error Code {i}"):
data.append(
WhatsminerError(error_code=summary_data[0][f"Error Code {i}"])
)
return data
async def reboot(self) -> bool:
data = await self.api.reboot()
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
return False
async def restart_backend(self) -> bool:
data = await self.api.restart()
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
return False
async def stop_mining(self) -> bool:
data = await self.api.power_off(respbefore=True)
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()
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:

View File

@@ -14,7 +14,7 @@
import ipaddress
import logging
from typing import Union
from typing import Union, List
from pyasic.API.cgminer import CGMinerAPI
@@ -23,6 +23,7 @@ from pyasic.errors import APIError
from pyasic.config import MinerConfig
from pyasic.data import MinerData
from pyasic.data.error_codes import MinerErrorData
from pyasic.settings import PyasicSettings
@@ -118,8 +119,7 @@ class CGMiner(BaseMiner):
return True
return False
async def start_cgminer(self) -> None:
"""Start cgminer hashing process."""
async def resume_mining(self) -> bool:
commands = [
"mkdir -p /etc/tmp/",
'echo "*/3 * * * * /usr/bin/cgminer-monitor" > /etc/tmp/root',
@@ -128,9 +128,9 @@ class CGMiner(BaseMiner):
]
commands = ";".join(commands)
await self.send_ssh_command(commands)
return True
async def stop_cgminer(self) -> None:
"""Restart cgminer hashing process."""
async def stop_mining(self) -> bool:
commands = [
"mkdir -p /etc/tmp/",
'echo "" > /etc/tmp/root',
@@ -139,6 +139,7 @@ class CGMiner(BaseMiner):
]
commands = ";".join(commands)
await self.send_ssh_command(commands)
return True
async def get_config(self) -> str:
"""Gets the config for the miner and sets it as `self.config`.
@@ -163,7 +164,7 @@ class CGMiner(BaseMiner):
async def fault_light_on(self) -> bool:
return False
async def get_errors(self) -> list:
async def get_errors(self) -> List[MinerErrorData]:
return []
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:

View File

@@ -15,7 +15,7 @@
from pyasic.miners._backends import BMMiner # noqa - Ignore access to _module
from pyasic.config import MinerConfig
from pyasic.data.error_codes import X19Error
from pyasic.data.error_codes import X19Error, MinerErrorData
from pyasic.settings import PyasicSettings
import httpx
@@ -132,7 +132,7 @@ class BMMinerX19(BMMiner):
return True
return False
async def get_errors(self) -> List[X19Error]:
async def get_errors(self) -> List[MinerErrorData]:
errors = []
url = f"http://{self.ip}/cgi-bin/summary.cgi"
auth = httpx.DigestAuth(self.uname, self.pwd)
@@ -147,12 +147,14 @@ class BMMinerX19(BMMiner):
errors.append(X19Error(item["msg"]))
return errors
async def stop_mining(self) -> None:
async def stop_mining(self) -> bool:
cfg = await self.get_config()
cfg.autotuning_wattage = 0
await self.send_config(cfg)
return True
async def resume_mining(self):
async def resume_mining(self) -> bool:
cfg = await self.get_config()
cfg.autotuning_wattage = 1
await self.send_config(cfg)
return True

View File

@@ -51,6 +51,12 @@ class CGMinerA10X(CGMiner):
return True
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
"""Configures miner with yaml config."""
raise NotImplementedError

View File

@@ -51,6 +51,12 @@ class CGMinerA7X(CGMiner):
return True
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
"""Configures miner with yaml config."""
raise NotImplementedError

View File

@@ -51,6 +51,12 @@ class CGMinerA8X(CGMiner):
return True
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
"""Configures miner with yaml config."""
raise NotImplementedError

View File

@@ -52,6 +52,12 @@ class CGMinerAvalon921(CGMiner, Avalon921):
return True
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
"""Configures miner with yaml config."""
raise NotImplementedError

View File

@@ -25,6 +25,7 @@ from pyasic.data.error_codes import (
BraiinsOSError,
InnosiliconError,
X19Error,
MinerErrorData,
)
@@ -181,9 +182,7 @@ class BaseMiner(ABC):
pass
@abstractmethod
async def get_errors(
self,
) -> List[Union[WhatsminerError, BraiinsOSError, InnosiliconError, X19Error]]:
async def get_errors(self) -> List[MinerErrorData]:
"""Get a list of the errors the miner is experiencing.
Returns:
@@ -200,5 +199,23 @@ class BaseMiner(ABC):
"""
return MinerData(ip=str(self.ip))
@abstractmethod
async def stop_mining(self) -> bool:
"""Stop the mining process of the miner.
Returns:
A boolean value of the success of stopping the mining process.
"""
pass
@abstractmethod
async def resume_mining(self) -> bool:
"""Stop the mining process of the miner.
Returns:
A boolean value of the success of resuming the mining process.
"""
pass
AnyMiner = TypeVar("AnyMiner", bound=BaseMiner)

View File

@@ -15,14 +15,14 @@
from pyasic.miners._backends import CGMiner # noqa - Ignore access to _module
from pyasic.miners._types import InnosiliconT3HPlus # noqa - Ignore access to _module
from pyasic.data import MinerData
from pyasic.data.error_codes import InnosiliconError
from pyasic.data.error_codes import InnosiliconError, MinerErrorData
from pyasic.settings import PyasicSettings
from pyasic.config import MinerConfig
from pyasic.errors import APIError
import httpx
import warnings
from typing import Union
from typing import Union, List
import logging
@@ -142,7 +142,7 @@ class CGMinerInnosiliconT3HPlus(CGMiner, InnosiliconT3HPlus):
"updatePools", data=config.as_inno(user_suffix=user_suffix)
)
async def get_errors(self) -> list:
async def get_errors(self) -> List[MinerErrorData]:
errors = []
try:
data = await self.send_web_command("getErrorDetail")

View File

@@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List
from pyasic.API.unknown import UnknownAPI
from pyasic.miners.base import BaseMiner
from pyasic.config import MinerConfig
from pyasic.data import MinerData
from pyasic.data.error_codes import MinerErrorData
class UnknownMiner(BaseMiner):
@@ -48,7 +51,7 @@ class UnknownMiner(BaseMiner):
async def get_config(self) -> None:
return None
async def get_errors(self) -> list:
async def get_errors(self) -> List[MinerErrorData]:
return []
async def get_mac(self) -> str:
@@ -60,6 +63,12 @@ class UnknownMiner(BaseMiner):
async def restart_backend(self) -> bool:
return False
async def stop_mining(self) -> bool:
return False
async def resume_mining(self) -> bool:
return False
async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
return None

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyasic"
version = "0.17.5"
version = "0.17.6"
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"