Skip to content

Commit

Permalink
feature: add support for Avalon Nano 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rowan committed Sep 1, 2024
1 parent a57f343 commit 477acda
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyasic/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class AvalonminerModels(str, Enum):
Avalon1066 = "Avalon 1066"
Avalon1166Pro = "Avalon 1166 Pro"
Avalon1246 = "Avalon 1246"
AvalonNano3 = "Avalon Nano 3"

def __str__(self):
return self.value
Expand Down
1 change: 1 addition & 0 deletions pyasic/miners/avalonminer/cgminer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from .A10X import *
from .A11X import *
from .A12X import *
from .nano import *
17 changes: 17 additions & 0 deletions pyasic/miners/avalonminer/cgminer/nano/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ------------------------------------------------------------------------------
# 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 .nano3 import CGMinerAvalonNano3
22 changes: 22 additions & 0 deletions pyasic/miners/avalonminer/cgminer/nano/nano3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ------------------------------------------------------------------------------
# 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.backends import AvalonMiner
from pyasic.miners.device.models import AvalonNano3


class CGMinerAvalonNano3(AvalonMiner, AvalonNano3):
pass
5 changes: 3 additions & 2 deletions pyasic/miners/backends/avalonminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ def parse_stats(stats):
stats_items = []
stats_dict = {}
for item in _stats_items:
if ":" in item:
if ": " in item:
data = item.replace("]", "").split("[")
data_list = [i.split(": ") for i in data[1].strip().split(", ")]
data_dict = {}
try:
for key, val in [tuple(item) for item in data_list]:
print(key, val)
data_dict[key] = val
except ValueError:
# --avalon args
Expand Down Expand Up @@ -220,7 +221,7 @@ async def _get_hashboards(self, rpc_stats: dict = None) -> List[HashBoard]:
try:
board_hr = parsed_stats["MGHS"][board]
hashboards[board].hashrate = AlgoHashRate.SHA256(
board_hr, HashUnit.SHA256.GH
float(board_hr), HashUnit.SHA256.GH
).into(self.algo.unit.default)
except LookupError:
pass
Expand Down
1 change: 1 addition & 0 deletions pyasic/miners/device/models/avalonminer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from .A10X import *
from .A11X import *
from .A12X import *
from .nano import *
1 change: 1 addition & 0 deletions pyasic/miners/device/models/avalonminer/nano/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .nano3 import AvalonNano3
10 changes: 10 additions & 0 deletions pyasic/miners/device/models/avalonminer/nano/nano3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pyasic.device import MinerModel
from pyasic.miners.device.makes import AvalonMinerMake


class AvalonNano3(AvalonMinerMake):
raw_model = MinerModel.AVALONMINER.AvalonNano3

expected_hashboards = 1
expected_chips = 10
expected_fans = 1
7 changes: 5 additions & 2 deletions pyasic/miners/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class MinerTypes(enum.Enum):
"AVALONMINER 1066": CGMinerAvalon1066,
"AVALONMINER 1166PRO": CGMinerAvalon1166Pro,
"AVALONMINER 1246": CGMinerAvalon1246,
"AVALONMINER NANO3": CGMinerAvalonNano3,
},
MinerTypes.INNOSILICON: {
None: type("InnosiliconUnknown", (Innosilicon, InnosiliconMake), {}),
Expand Down Expand Up @@ -906,10 +907,12 @@ async def get_miner_model_whatsminer(self, ip: str) -> str | None:
async def get_miner_model_avalonminer(self, ip: str) -> str | None:
sock_json_data = await self.send_api_command(ip, "version")
try:
miner_model = sock_json_data["VERSION"][0]["PROD"]
miner_model = sock_json_data["VERSION"][0]["PROD"].upper()
if "-" in miner_model:
miner_model = miner_model.split("-")[0]

if miner_model == "AVALONNANO":
nano_subtype = sock_json_data["VERSION"][0]["MODEL"].upper()
miner_model = f"AVALONMINER {nano_subtype}"
return miner_model
except (TypeError, LookupError):
pass
Expand Down

0 comments on commit 477acda

Please sign in to comment.