repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M62S_Plus.py | pyasic/miners/whatsminer/btminer/M6X/M62S_Plus.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M62SPlusVK30
class BTMinerM62SPlusVK30(M6X, M62SPlusVK30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M61.py | pyasic/miners/whatsminer/btminer/M6X/M61.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M61VK10
class BTMinerM61VK10(M6X, M61VK10):
pass
from pyasic.miners.device.models import M61VK20
class BTMinerM61VK20(M6X, M61VK20):
pass
from pyasic.miners.device.models import M61VK30
class BTMinerM61VK30(M6X, M61VK30):
pass
from pyasic.miners.device.models import M61VK40
class BTMinerM61VK40(M6X, M61VK40):
pass
from pyasic.miners.device.models import M61VL10
class BTMinerM61VL10(M6X, M61VL10):
pass
from pyasic.miners.device.models import M61VL30
class BTMinerM61VL30(M6X, M61VL30):
pass
from pyasic.miners.device.models import M61VL40
class BTMinerM61VL40(M6X, M61VL40):
pass
from pyasic.miners.device.models import M61VL50
class BTMinerM61VL50(M6X, M61VL50):
pass
from pyasic.miners.device.models import M61VL60
class BTMinerM61VL60(M6X, M61VL60):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M63S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M6X/M63S_Plus_Plus.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M63SPlusPlusVL20
class BTMinerM63SPlusPlusVL20(M6X, M63SPlusPlusVL20):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M66S_Plus.py | pyasic/miners/whatsminer/btminer/M6X/M66S_Plus.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M66SPlusVK30
class BTMinerM66SPlusVK30(M6X, M66SPlusVK30):
pass
from pyasic.miners.device.models import M66SPlusVL10
class BTMinerM66SPlusVL10(M6X, M66SPlusVL10):
pass
from pyasic.miners.device.models import M66SPlusVL20
class BTMinerM66SPlusVL20(M6X, M66SPlusVL20):
pass
from pyasic.miners.device.models import M66SPlusVL30
class BTMinerM66SPlusVL30(M6X, M66SPlusVL30):
pass
from pyasic.miners.device.models import M66SPlusVL40
class BTMinerM66SPlusVL40(M6X, M66SPlusVL40):
pass
from pyasic.miners.device.models import M66SPlusVL60
class BTMinerM66SPlusVL60(M6X, M66SPlusVL60):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M67S.py | pyasic/miners/whatsminer/btminer/M6X/M67S.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M67SVK30
class BTMinerM67SVK30(M6X, M67SVK30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M60S.py | pyasic/miners/whatsminer/btminer/M6X/M60S.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M60SVK10
class BTMinerM60SVK10(M6X, M60SVK10):
pass
from pyasic.miners.device.models import M60SVK20
class BTMinerM60SVK20(M6X, M60SVK20):
pass
from pyasic.miners.device.models import M60SVK30
class BTMinerM60SVK30(M6X, M60SVK30):
pass
from pyasic.miners.device.models import M60SVK40
class BTMinerM60SVK40(M6X, M60SVK40):
pass
from pyasic.miners.device.models import M60SVL10
class BTMinerM60SVL10(M6X, M60SVL10):
pass
from pyasic.miners.device.models import M60SVL20
class BTMinerM60SVL20(M6X, M60SVL20):
pass
from pyasic.miners.device.models import M60SVL30
class BTMinerM60SVL30(M6X, M60SVL30):
pass
from pyasic.miners.device.models import M60SVL40
class BTMinerM60SVL40(M6X, M60SVL40):
pass
from pyasic.miners.device.models import M60SVL50
class BTMinerM60SVL50(M6X, M60SVL50):
pass
from pyasic.miners.device.models import M60SVL60
class BTMinerM60SVL60(M6X, M60SVL60):
pass
from pyasic.miners.device.models import M60SVL70
class BTMinerM60SVL70(M6X, M60SVL70):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M66.py | pyasic/miners/whatsminer/btminer/M6X/M66.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M66VK20
class BTMinerM66VK20(M6X, M66VK20):
pass
from pyasic.miners.device.models import M66VK30
class BTMinerM66VK30(M6X, M66VK30):
pass
from pyasic.miners.device.models import M66VL20
class BTMinerM66VL20(M6X, M66VL20):
pass
from pyasic.miners.device.models import M66VL30
class BTMinerM66VL30(M6X, M66VL30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M63.py | pyasic/miners/whatsminer/btminer/M6X/M63.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M63VK10
class BTMinerM63VK10(M6X, M63VK10):
pass
from pyasic.miners.device.models import M63VK20
class BTMinerM63VK20(M6X, M63VK20):
pass
from pyasic.miners.device.models import M63VK30
class BTMinerM63VK30(M6X, M63VK30):
pass
from pyasic.miners.device.models import M63VL10
class BTMinerM63VL10(M6X, M63VL10):
pass
from pyasic.miners.device.models import M63VL30
class BTMinerM63VL30(M6X, M63VL30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M65S.py | pyasic/miners/whatsminer/btminer/M6X/M65S.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M65SVK20
class BTMinerM65SVK20(M6X, M65SVK20):
pass
from pyasic.miners.device.models import M65SVL60
class BTMinerM65SVL60(M6X, M65SVL60):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M65S_Plus.py | pyasic/miners/whatsminer/btminer/M6X/M65S_Plus.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M65SPlusVK30
class BTMinerM65SPlusVK30(M6X, M65SPlusVK30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M63S_Plus.py | pyasic/miners/whatsminer/btminer/M6X/M63S_Plus.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M63SPlusVK30
class BTMinerM63SPlusVK30(M6X, M63SPlusVK30):
pass
from pyasic.miners.device.models import M63SPlusVL10
class BTMinerM63SPlusVL10(M6X, M63SPlusVL10):
pass
from pyasic.miners.device.models import M63SPlusVL20
class BTMinerM63SPlusVL20(M6X, M63SPlusVL20):
pass
from pyasic.miners.device.models import M63SPlusVL30
class BTMinerM63SPlusVL30(M6X, M63SPlusVL30):
pass
from pyasic.miners.device.models import M63SPlusVL50
class BTMinerM63SPlusVL50(M6X, M63SPlusVL50):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/__init__.py | pyasic/miners/whatsminer/btminer/M6X/__init__.py | from .M60 import (
BTMinerM60VK6A,
BTMinerM60VK10,
BTMinerM60VK20,
BTMinerM60VK30,
BTMinerM60VK40,
BTMinerM60VL10,
BTMinerM60VL20,
BTMinerM60VL30,
BTMinerM60VL40,
BTMinerM60VL50,
)
from .M60S import (
BTMinerM60SVK10,
BTMinerM60SVK20,
BTMinerM60SVK30,
BTMinerM60SVK40,
BTMinerM60SVL10,
BTMinerM60SVL20,
BTMinerM60SVL30,
BTMinerM60SVL40,
BTMinerM60SVL50,
BTMinerM60SVL60,
BTMinerM60SVL70,
)
from .M60S_Plus import (
BTMinerM60SPlusVK30,
BTMinerM60SPlusVK40,
BTMinerM60SPlusVK50,
BTMinerM60SPlusVK60,
BTMinerM60SPlusVK70,
BTMinerM60SPlusVL10,
BTMinerM60SPlusVL30,
BTMinerM60SPlusVL40,
BTMinerM60SPlusVL50,
BTMinerM60SPlusVL60,
)
from .M60S_Plus_Plus import BTMinerM60SPlusPlusVL30, BTMinerM60SPlusPlusVL40
from .M61 import (
BTMinerM61VK10,
BTMinerM61VK20,
BTMinerM61VK30,
BTMinerM61VK40,
BTMinerM61VL10,
BTMinerM61VL30,
BTMinerM61VL40,
BTMinerM61VL50,
BTMinerM61VL60,
)
from .M61S import BTMinerM61SVL10, BTMinerM61SVL20, BTMinerM61SVL30
from .M61S_Plus import BTMinerM61SPlusVL30
from .M62S_Plus import BTMinerM62SPlusVK30
from .M63 import (
BTMinerM63VK10,
BTMinerM63VK20,
BTMinerM63VK30,
BTMinerM63VL10,
BTMinerM63VL30,
)
from .M63S import (
BTMinerM63SVK10,
BTMinerM63SVK20,
BTMinerM63SVK30,
BTMinerM63SVK60,
BTMinerM63SVL10,
BTMinerM63SVL50,
BTMinerM63SVL60,
)
from .M63S_Plus import (
BTMinerM63SPlusVK30,
BTMinerM63SPlusVL10,
BTMinerM63SPlusVL20,
BTMinerM63SPlusVL30,
BTMinerM63SPlusVL50,
)
from .M63S_Plus_Plus import BTMinerM63SPlusPlusVL20
from .M64 import BTMinerM64VL30, BTMinerM64VL40
from .M64S import BTMinerM64SVL30
from .M65S import BTMinerM65SVK20, BTMinerM65SVL60
from .M65S_Plus import BTMinerM65SPlusVK30
from .M66 import BTMinerM66VK20, BTMinerM66VK30, BTMinerM66VL20, BTMinerM66VL30
from .M66S import (
BTMinerM66SVK20,
BTMinerM66SVK30,
BTMinerM66SVK40,
BTMinerM66SVK50,
BTMinerM66SVK60,
BTMinerM66SVL10,
BTMinerM66SVL20,
BTMinerM66SVL30,
BTMinerM66SVL40,
BTMinerM66SVL50,
)
from .M66S_Plus import (
BTMinerM66SPlusVK30,
BTMinerM66SPlusVL10,
BTMinerM66SPlusVL20,
BTMinerM66SPlusVL30,
BTMinerM66SPlusVL40,
BTMinerM66SPlusVL60,
)
from .M66S_Plus_Plus import BTMinerM66SPlusPlusVL20
from .M67S import BTMinerM67SVK30
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M63S.py | pyasic/miners/whatsminer/btminer/M6X/M63S.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M63SVK10
class BTMinerM63SVK10(M6X, M63SVK10):
pass
from pyasic.miners.device.models import M63SVK20
class BTMinerM63SVK20(M6X, M63SVK20):
pass
from pyasic.miners.device.models import M63SVK30
class BTMinerM63SVK30(M6X, M63SVK30):
pass
from pyasic.miners.device.models import M63SVK60
class BTMinerM63SVK60(M6X, M63SVK60):
pass
from pyasic.miners.device.models import M63SVL10
class BTMinerM63SVL10(M6X, M63SVL10):
pass
from pyasic.miners.device.models import M63SVL50
class BTMinerM63SVL50(M6X, M63SVL50):
pass
from pyasic.miners.device.models import M63SVL60
class BTMinerM63SVL60(M6X, M63SVL60):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M66S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M6X/M66S_Plus_Plus.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M66SPlusPlusVL20
class BTMinerM66SPlusPlusVL20(M6X, M66SPlusPlusVL20):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M6X/M61S.py | pyasic/miners/whatsminer/btminer/M6X/M61S.py | from pyasic.miners.backends import M6X
from pyasic.miners.device.models import M61SVL10
class BTMinerM61SVL10(M6X, M61SVL10):
pass
from pyasic.miners.device.models import M61SVL20
class BTMinerM61SVL20(M6X, M61SVL20):
pass
from pyasic.miners.device.models import M61SVL30
class BTMinerM61SVL30(M6X, M61SVL30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M7X/M70.py | pyasic/miners/whatsminer/btminer/M7X/M70.py | from pyasic.miners.backends import M7X
from pyasic.miners.device.models import M70VM30
class BTMinerM70VM30(M7X, M70VM30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M7X/__init__.py | pyasic/miners/whatsminer/btminer/M7X/__init__.py | from .M70 import BTMinerM70VM30
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M29.py | pyasic/miners/whatsminer/btminer/M2X/M29.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M29V10
class BTMinerM29V10(M2X, M29V10):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M20S_Plus.py | pyasic/miners/whatsminer/btminer/M2X/M20S_Plus.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M20SPlusV30
class BTMinerM20SPlusV30(M2X, M20SPlusV30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M21.py | pyasic/miners/whatsminer/btminer/M2X/M21.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M21V10
class BTMinerM21V10(M2X, M21V10):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M21S_Plus.py | pyasic/miners/whatsminer/btminer/M2X/M21S_Plus.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M21SPlusV20
class BTMinerM21SPlusV20(M2X, M21SPlusV20):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M20S.py | pyasic/miners/whatsminer/btminer/M2X/M20S.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M20SV10
class BTMinerM20SV10(M2X, M20SV10):
pass
from pyasic.miners.device.models import M20SV20
class BTMinerM20SV20(M2X, M20SV20):
pass
from pyasic.miners.device.models import M20SV30
class BTMinerM20SV30(M2X, M20SV30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M21S.py | pyasic/miners/whatsminer/btminer/M2X/M21S.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M21SV20
class BTMinerM21SV20(M2X, M21SV20):
pass
from pyasic.miners.device.models import M21SV60
class BTMinerM21SV60(M2X, M21SV60):
pass
from pyasic.miners.device.models import M21SV70
class BTMinerM21SV70(M2X, M21SV70):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M20.py | pyasic/miners/whatsminer/btminer/M2X/M20.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M20V10
class BTMinerM20V10(M2X, M20V10):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/__init__.py | pyasic/miners/whatsminer/btminer/M2X/__init__.py | from .M20 import BTMinerM20V10
from .M20P import BTMinerM20PV10, BTMinerM20PV30
from .M20S import BTMinerM20SV10, BTMinerM20SV20, BTMinerM20SV30
from .M20S_Plus import BTMinerM20SPlusV30
from .M21 import BTMinerM21V10
from .M21S import BTMinerM21SV20, BTMinerM21SV60, BTMinerM21SV70
from .M21S_Plus import BTMinerM21SPlusV20
from .M29 import BTMinerM29V10
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M2X/M20P.py | pyasic/miners/whatsminer/btminer/M2X/M20P.py | from pyasic.miners.backends import M2X
from pyasic.miners.device.models import M20PV10
class BTMinerM20PV10(M2X, M20PV10):
pass
from pyasic.miners.device.models import M20PV30
class BTMinerM20PV30(M2X, M20PV30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M52S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M52S_Plus_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M52SPlusPlusVL10
class BTMinerM52SPlusPlusVL10(M5X, M52SPlusPlusVL10):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M56.py | pyasic/miners/whatsminer/btminer/M5X/M56.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M56VH30
class BTMinerM56VH30(M5X, M56VH30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M56S.py | pyasic/miners/whatsminer/btminer/M5X/M56S.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M56SVH30
class BTMinerM56SVH30(M5X, M56SVH30):
pass
from pyasic.miners.device.models import M56SVJ30
class BTMinerM56SVJ30(M5X, M56SVJ30):
pass
from pyasic.miners.device.models import M56SVJ40
class BTMinerM56SVJ40(M5X, M56SVJ40):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M59.py | pyasic/miners/whatsminer/btminer/M5X/M59.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M59VH30
class BTMinerM59VH30(M5X, M59VH30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M50S_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M50S_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M50SPlusVH30
class BTMinerM50SPlusVH30(M5X, M50SPlusVH30):
pass
from pyasic.miners.device.models import M50SPlusVH40
class BTMinerM50SPlusVH40(M5X, M50SPlusVH40):
pass
from pyasic.miners.device.models import M50SPlusVJ30
class BTMinerM50SPlusVJ30(M5X, M50SPlusVJ30):
pass
from pyasic.miners.device.models import M50SPlusVJ40
class BTMinerM50SPlusVJ40(M5X, M50SPlusVJ40):
pass
from pyasic.miners.device.models import M50SPlusVJ60
class BTMinerM50SPlusVJ60(M5X, M50SPlusVJ60):
pass
from pyasic.miners.device.models import M50SPlusVK10
class BTMinerM50SPlusVK10(M5X, M50SPlusVK10):
pass
from pyasic.miners.device.models import M50SPlusVK20
class BTMinerM50SPlusVK20(M5X, M50SPlusVK20):
pass
from pyasic.miners.device.models import M50SPlusVK30
class BTMinerM50SPlusVK30(M5X, M50SPlusVK30):
pass
from pyasic.miners.device.models import M50SPlusVL10
class BTMinerM50SPlusVL10(M5X, M50SPlusVL10):
pass
from pyasic.miners.device.models import M50SPlusVL20
class BTMinerM50SPlusVL20(M5X, M50SPlusVL20):
pass
from pyasic.miners.device.models import M50SPlusVL30
class BTMinerM50SPlusVL30(M5X, M50SPlusVL30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M53S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M53S_Plus_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M53SPlusPlusVK10
class BTMinerM53SPlusPlusVK10(M5X, M53SPlusPlusVK10):
pass
from pyasic.miners.device.models import M53SPlusPlusVK20
class BTMinerM53SPlusPlusVK20(M5X, M53SPlusPlusVK20):
pass
from pyasic.miners.device.models import M53SPlusPlusVK30
class BTMinerM53SPlusPlusVK30(M5X, M53SPlusPlusVK30):
pass
from pyasic.miners.device.models import M53SPlusPlusVK50
class BTMinerM53SPlusPlusVK50(M5X, M53SPlusPlusVK50):
pass
from pyasic.miners.device.models import M53SPlusPlusVL10
class BTMinerM53SPlusPlusVL10(M5X, M53SPlusPlusVL10):
pass
from pyasic.miners.device.models import M53SPlusPlusVL30
class BTMinerM53SPlusPlusVL30(M5X, M53SPlusPlusVL30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M50S.py | pyasic/miners/whatsminer/btminer/M5X/M50S.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M50SVH10
class BTMinerM50SVH10(M5X, M50SVH10):
pass
from pyasic.miners.device.models import M50SVH20
class BTMinerM50SVH20(M5X, M50SVH20):
pass
from pyasic.miners.device.models import M50SVH30
class BTMinerM50SVH30(M5X, M50SVH30):
pass
from pyasic.miners.device.models import M50SVH40
class BTMinerM50SVH40(M5X, M50SVH40):
pass
from pyasic.miners.device.models import M50SVH50
class BTMinerM50SVH50(M5X, M50SVH50):
pass
from pyasic.miners.device.models import M50SVJ10
class BTMinerM50SVJ10(M5X, M50SVJ10):
pass
from pyasic.miners.device.models import M50SVJ20
class BTMinerM50SVJ20(M5X, M50SVJ20):
pass
from pyasic.miners.device.models import M50SVJ30
class BTMinerM50SVJ30(M5X, M50SVJ30):
pass
from pyasic.miners.device.models import M50SVJ40
class BTMinerM50SVJ40(M5X, M50SVJ40):
pass
from pyasic.miners.device.models import M50SVJ50
class BTMinerM50SVJ50(M5X, M50SVJ50):
pass
from pyasic.miners.device.models import M50SVK10
class BTMinerM50SVK10(M5X, M50SVK10):
pass
from pyasic.miners.device.models import M50SVK20
class BTMinerM50SVK20(M5X, M50SVK20):
pass
from pyasic.miners.device.models import M50SVK30
class BTMinerM50SVK30(M5X, M50SVK30):
pass
from pyasic.miners.device.models import M50SVK50
class BTMinerM50SVK50(M5X, M50SVK50):
pass
from pyasic.miners.device.models import M50SVK60
class BTMinerM50SVK60(M5X, M50SVK60):
pass
from pyasic.miners.device.models import M50SVK70
class BTMinerM50SVK70(M5X, M50SVK70):
pass
from pyasic.miners.device.models import M50SVK80
class BTMinerM50SVK80(M5X, M50SVK80):
pass
from pyasic.miners.device.models import M50SVL20
class BTMinerM50SVL20(M5X, M50SVL20):
pass
from pyasic.miners.device.models import M50SVL30
class BTMinerM50SVL30(M5X, M50SVL30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M54S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M54S_Plus_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M54SPlusPlusVK30
class BTMinerM54SPlusPlusVK30(M5X, M54SPlusPlusVK30):
pass
from pyasic.miners.device.models import M54SPlusPlusVL30
class BTMinerM54SPlusPlusVL30(M5X, M54SPlusPlusVL30):
pass
from pyasic.miners.device.models import M54SPlusPlusVL40
class BTMinerM54SPlusPlusVL40(M5X, M54SPlusPlusVL40):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M50S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M50S_Plus_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M50SPlusPlusVK10
class BTMinerM50SPlusPlusVK10(M5X, M50SPlusPlusVK10):
pass
from pyasic.miners.device.models import M50SPlusPlusVK20
class BTMinerM50SPlusPlusVK20(M5X, M50SPlusPlusVK20):
pass
from pyasic.miners.device.models import M50SPlusPlusVK30
class BTMinerM50SPlusPlusVK30(M5X, M50SPlusPlusVK30):
pass
from pyasic.miners.device.models import M50SPlusPlusVK40
class BTMinerM50SPlusPlusVK40(M5X, M50SPlusPlusVK40):
pass
from pyasic.miners.device.models import M50SPlusPlusVK50
class BTMinerM50SPlusPlusVK50(M5X, M50SPlusPlusVK50):
pass
from pyasic.miners.device.models import M50SPlusPlusVK60
class BTMinerM50SPlusPlusVK60(M5X, M50SPlusPlusVK60):
pass
from pyasic.miners.device.models import M50SPlusPlusVL20
class BTMinerM50SPlusPlusVL20(M5X, M50SPlusPlusVL20):
pass
from pyasic.miners.device.models import M50SPlusPlusVL30
class BTMinerM50SPlusPlusVL30(M5X, M50SPlusPlusVL30):
pass
from pyasic.miners.device.models import M50SPlusPlusVL40
class BTMinerM50SPlusPlusVL40(M5X, M50SPlusPlusVL40):
pass
from pyasic.miners.device.models import M50SPlusPlusVL50
class BTMinerM50SPlusPlusVL50(M5X, M50SPlusPlusVL50):
pass
from pyasic.miners.device.models import M50SPlusPlusVL60
class BTMinerM50SPlusPlusVL60(M5X, M50SPlusPlusVL60):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/__init__.py | pyasic/miners/whatsminer/btminer/M5X/__init__.py | from .M50 import (
BTMinerM50VE30,
BTMinerM50VG30,
BTMinerM50VH10,
BTMinerM50VH20,
BTMinerM50VH30,
BTMinerM50VH40,
BTMinerM50VH50,
BTMinerM50VH60,
BTMinerM50VH70,
BTMinerM50VH80,
BTMinerM50VH90,
BTMinerM50VJ10,
BTMinerM50VJ20,
BTMinerM50VJ30,
BTMinerM50VJ40,
BTMinerM50VJ60,
BTMinerM50VK40,
BTMinerM50VK50,
)
from .M50S import (
BTMinerM50SVH10,
BTMinerM50SVH20,
BTMinerM50SVH30,
BTMinerM50SVH40,
BTMinerM50SVH50,
BTMinerM50SVJ10,
BTMinerM50SVJ20,
BTMinerM50SVJ30,
BTMinerM50SVJ40,
BTMinerM50SVJ50,
BTMinerM50SVK10,
BTMinerM50SVK20,
BTMinerM50SVK30,
BTMinerM50SVK50,
BTMinerM50SVK60,
BTMinerM50SVK70,
BTMinerM50SVK80,
BTMinerM50SVL20,
BTMinerM50SVL30,
)
from .M50S_Plus import (
BTMinerM50SPlusVH30,
BTMinerM50SPlusVH40,
BTMinerM50SPlusVJ30,
BTMinerM50SPlusVJ40,
BTMinerM50SPlusVJ60,
BTMinerM50SPlusVK10,
BTMinerM50SPlusVK20,
BTMinerM50SPlusVK30,
BTMinerM50SPlusVL10,
BTMinerM50SPlusVL20,
BTMinerM50SPlusVL30,
)
from .M50S_Plus_Plus import (
BTMinerM50SPlusPlusVK10,
BTMinerM50SPlusPlusVK20,
BTMinerM50SPlusPlusVK30,
BTMinerM50SPlusPlusVK40,
BTMinerM50SPlusPlusVK50,
BTMinerM50SPlusPlusVK60,
BTMinerM50SPlusPlusVL20,
BTMinerM50SPlusPlusVL30,
BTMinerM50SPlusPlusVL40,
BTMinerM50SPlusPlusVL50,
BTMinerM50SPlusPlusVL60,
)
from .M52S import BTMinerM52SVK30
from .M52S_Plus_Plus import BTMinerM52SPlusPlusVL10
from .M53 import (
BTMinerM53VH30,
BTMinerM53VH40,
BTMinerM53VH50,
BTMinerM53VK30,
BTMinerM53VK60,
)
from .M53H import BTMinerM53HVH10
from .M53S import (
BTMinerM53SVH20,
BTMinerM53SVH30,
BTMinerM53SVJ30,
BTMinerM53SVJ40,
BTMinerM53SVK30,
)
from .M53S_Plus import (
BTMinerM53SPlusVJ30,
BTMinerM53SPlusVJ40,
BTMinerM53SPlusVJ50,
BTMinerM53SPlusVK30,
)
from .M53S_Plus_Plus import (
BTMinerM53SPlusPlusVK10,
BTMinerM53SPlusPlusVK20,
BTMinerM53SPlusPlusVK30,
BTMinerM53SPlusPlusVK50,
BTMinerM53SPlusPlusVL10,
BTMinerM53SPlusPlusVL30,
)
from .M54S_Plus_Plus import (
BTMinerM54SPlusPlusVK30,
BTMinerM54SPlusPlusVL30,
BTMinerM54SPlusPlusVL40,
)
from .M56 import BTMinerM56VH30
from .M56S import BTMinerM56SVH30, BTMinerM56SVJ30, BTMinerM56SVJ40
from .M56S_Plus import (
BTMinerM56SPlusVJ30,
BTMinerM56SPlusVK30,
BTMinerM56SPlusVK40,
BTMinerM56SPlusVK50,
)
from .M56S_Plus_Plus import (
BTMinerM56SPlusPlusVK10,
BTMinerM56SPlusPlusVK30,
BTMinerM56SPlusPlusVK40,
BTMinerM56SPlusPlusVK50,
)
from .M59 import BTMinerM59VH30
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M56S_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M56S_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M56SPlusVJ30
class BTMinerM56SPlusVJ30(M5X, M56SPlusVJ30):
pass
from pyasic.miners.device.models import M56SPlusVK30
class BTMinerM56SPlusVK30(M5X, M56SPlusVK30):
pass
from pyasic.miners.device.models import M56SPlusVK40
class BTMinerM56SPlusVK40(M5X, M56SPlusVK40):
pass
from pyasic.miners.device.models import M56SPlusVK50
class BTMinerM56SPlusVK50(M5X, M56SPlusVK50):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M53S.py | pyasic/miners/whatsminer/btminer/M5X/M53S.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M53SVH20
class BTMinerM53SVH20(M5X, M53SVH20):
pass
from pyasic.miners.device.models import M53SVH30
class BTMinerM53SVH30(M5X, M53SVH30):
pass
from pyasic.miners.device.models import M53SVJ30
class BTMinerM53SVJ30(M5X, M53SVJ30):
pass
from pyasic.miners.device.models import M53SVJ40
class BTMinerM53SVJ40(M5X, M53SVJ40):
pass
from pyasic.miners.device.models import M53SVK30
class BTMinerM53SVK30(M5X, M53SVK30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M53S_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M53S_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M53SPlusVJ30
class BTMinerM53SPlusVJ30(M5X, M53SPlusVJ30):
pass
from pyasic.miners.device.models import M53SPlusVJ40
class BTMinerM53SPlusVJ40(M5X, M53SPlusVJ40):
pass
from pyasic.miners.device.models import M53SPlusVJ50
class BTMinerM53SPlusVJ50(M5X, M53SPlusVJ50):
pass
from pyasic.miners.device.models import M53SPlusVK30
class BTMinerM53SPlusVK30(M5X, M53SPlusVK30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M50.py | pyasic/miners/whatsminer/btminer/M5X/M50.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M50VE30
class BTMinerM50VE30(M5X, M50VE30):
pass
from pyasic.miners.device.models import M50VG30
class BTMinerM50VG30(M5X, M50VG30):
pass
from pyasic.miners.device.models import M50VH10
class BTMinerM50VH10(M5X, M50VH10):
pass
from pyasic.miners.device.models import M50VH20
class BTMinerM50VH20(M5X, M50VH20):
pass
from pyasic.miners.device.models import M50VH30
class BTMinerM50VH30(M5X, M50VH30):
pass
from pyasic.miners.device.models import M50VH40
class BTMinerM50VH40(M5X, M50VH40):
pass
from pyasic.miners.device.models import M50VH50
class BTMinerM50VH50(M5X, M50VH50):
pass
from pyasic.miners.device.models import M50VH60
class BTMinerM50VH60(M5X, M50VH60):
pass
from pyasic.miners.device.models import M50VH70
class BTMinerM50VH70(M5X, M50VH70):
pass
from pyasic.miners.device.models import M50VH80
class BTMinerM50VH80(M5X, M50VH80):
pass
from pyasic.miners.device.models import M50VH90
class BTMinerM50VH90(M5X, M50VH90):
pass
from pyasic.miners.device.models import M50VJ10
class BTMinerM50VJ10(M5X, M50VJ10):
pass
from pyasic.miners.device.models import M50VJ20
class BTMinerM50VJ20(M5X, M50VJ20):
pass
from pyasic.miners.device.models import M50VJ30
class BTMinerM50VJ30(M5X, M50VJ30):
pass
from pyasic.miners.device.models import M50VJ40
class BTMinerM50VJ40(M5X, M50VJ40):
pass
from pyasic.miners.device.models import M50VJ60
class BTMinerM50VJ60(M5X, M50VJ60):
pass
from pyasic.miners.device.models import M50VK40
class BTMinerM50VK40(M5X, M50VK40):
pass
from pyasic.miners.device.models import M50VK50
class BTMinerM50VK50(M5X, M50VK50):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M53.py | pyasic/miners/whatsminer/btminer/M5X/M53.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M53VH30
class BTMinerM53VH30(M5X, M53VH30):
pass
from pyasic.miners.device.models import M53VH40
class BTMinerM53VH40(M5X, M53VH40):
pass
from pyasic.miners.device.models import M53VH50
class BTMinerM53VH50(M5X, M53VH50):
pass
from pyasic.miners.device.models import M53VK30
class BTMinerM53VK30(M5X, M53VK30):
pass
from pyasic.miners.device.models import M53VK60
class BTMinerM53VK60(M5X, M53VK60):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M56S_Plus_Plus.py | pyasic/miners/whatsminer/btminer/M5X/M56S_Plus_Plus.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M56SPlusPlusVK10
class BTMinerM56SPlusPlusVK10(M5X, M56SPlusPlusVK10):
pass
from pyasic.miners.device.models import M56SPlusPlusVK30
class BTMinerM56SPlusPlusVK30(M5X, M56SPlusPlusVK30):
pass
from pyasic.miners.device.models import M56SPlusPlusVK40
class BTMinerM56SPlusPlusVK40(M5X, M56SPlusPlusVK40):
pass
from pyasic.miners.device.models import M56SPlusPlusVK50
class BTMinerM56SPlusPlusVK50(M5X, M56SPlusPlusVK50):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M52S.py | pyasic/miners/whatsminer/btminer/M5X/M52S.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M52SVK30
class BTMinerM52SVK30(M5X, M52SVK30):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/whatsminer/btminer/M5X/M53H.py | pyasic/miners/whatsminer/btminer/M5X/M53H.py | from pyasic.miners.backends import M5X
from pyasic.miners.device.models import M53HVH10
class BTMinerM53HVH10(M5X, M53HVH10):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/elphapex/__init__.py | pyasic/miners/elphapex/__init__.py | from .daoge import *
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/elphapex/daoge/__init__.py | pyasic/miners/elphapex/daoge/__init__.py | from .DGX import *
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/elphapex/daoge/DGX/DG1.py | pyasic/miners/elphapex/daoge/DGX/DG1.py | from pyasic.miners.backends.elphapex import ElphapexMiner
from pyasic.miners.device.models import DG1, DG1Home, DG1Plus
class ElphapexDG1Plus(ElphapexMiner, DG1Plus):
pass
class ElphapexDG1(ElphapexMiner, DG1):
pass
class ElphapexDG1Home(ElphapexMiner, DG1Home):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/elphapex/daoge/DGX/__init__.py | pyasic/miners/elphapex/daoge/DGX/__init__.py | from .DG1 import ElphapexDG1, ElphapexDG1Home, ElphapexDG1Plus
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/luckyminer.py | pyasic/miners/backends/luckyminer.py | from pyasic.miners.backends.espminer import ESPMiner
class LuckyMiner(ESPMiner):
"""Handler for LuckyMiner"""
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/braiins_os.py | pyasic/miners/backends/braiins_os.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import base64
import logging
import time
import aiofiles
import tomli_w
try:
import tomllib
except ImportError:
import tomli as tomllib # type: ignore
from pyasic.config import MinerConfig
from pyasic.config.mining import MiningModePowerTune
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import BraiinsOSError, MinerErrorData
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.firmware import BraiinsOSFirmware
from pyasic.rpc.bosminer import BOSMinerRPCAPI
from pyasic.ssh.braiins_os import BOSMinerSSH
from pyasic.web.braiins_os import BOSerWebAPI, BOSMinerWebAPI
from pyasic.web.braiins_os.proto.braiins.bos.v1 import SaveAction
BOSMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_net_conf", "admin/network/iface_status/lan")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_bos_info", "bos/info")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_temps", "temps"),
RPCAPICommand("rpc_devdetails", "devdetails"),
RPCAPICommand("rpc_devs", "devs"),
],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_tunerstatus", "tunerstatus")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[RPCAPICommand("rpc_tunerstatus", "tunerstatus")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_fans", "fans")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[RPCAPICommand("rpc_tunerstatus", "tunerstatus")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class BOSMiner(BraiinsOSFirmware):
"""Handler for old versions of BraiinsOS+ (pre-gRPC)"""
_rpc_cls = BOSMinerRPCAPI
rpc: BOSMinerRPCAPI
_web_cls = BOSMinerWebAPI
web: BOSMinerWebAPI
_ssh_cls = BOSMinerSSH
ssh: BOSMinerSSH
data_locations = BOSMINER_DATA_LOC
supports_shutdown = True
supports_autotuning = True
async def fault_light_on(self) -> bool:
ret = await self.ssh.fault_light_on()
if isinstance(ret, str):
self.light = True
return self.light
return False
async def fault_light_off(self) -> bool:
ret = await self.ssh.fault_light_off()
if isinstance(ret, str):
self.light = False
return True
return False
async def restart_backend(self) -> bool:
return await self.restart_bosminer()
async def restart_bosminer(self) -> bool:
ret = await self.ssh.restart_bosminer()
if isinstance(ret, str):
return True
return False
async def stop_mining(self) -> bool:
try:
data = await self.rpc.pause()
except APIError:
return False
if data.get("PAUSE"):
if data["PAUSE"][0]:
return True
return False
async def resume_mining(self) -> bool:
try:
data = await self.rpc.resume()
except APIError:
return False
if data.get("RESUME"):
if data["RESUME"][0]:
return True
return False
async def reboot(self) -> bool:
ret = await self.ssh.reboot()
if isinstance(ret, str):
return True
return False
async def get_config(self) -> MinerConfig:
raw_data = await self.ssh.get_config_file()
try:
toml_data = tomllib.loads(raw_data)
cfg = MinerConfig.from_bosminer(toml_data)
self.config = cfg
except tomllib.TOMLDecodeError as e:
raise APIError("Failed to decode toml when getting config.") from e
except TypeError as e:
raise APIError("Failed to decode toml when getting config.") from e
return self.config
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
parsed_cfg = config.as_bosminer(user_suffix=user_suffix)
toml_conf = tomli_w.dumps(
{
"format": {
"version": "2.0",
"generator": "pyasic",
"model": f"{self.make.replace('Miner', 'miner') if self.make else ''} {self.raw_model.replace('j', 'J') if self.raw_model else ''}",
"timestamp": int(time.time()),
},
**parsed_cfg,
}
)
try:
await self.ssh.send_command("/etc/init.d/bosminer stop")
await self.ssh.send_command("echo '" + toml_conf + "' > /etc/bosminer.toml")
await self.ssh.send_command("/etc/init.d/bosminer start")
except Exception as e:
raise APIError("SSH command failed when sending config.") from e
async def set_power_limit(self, wattage: int) -> bool:
try:
cfg = await self.get_config()
if cfg is None:
return False
cfg.mining_mode = MiningModePowerTune(power=wattage)
await self.send_config(cfg)
except APIError:
raise
except Exception as e:
logging.warning(f"{self} - Failed to set power limit: {e}")
return False
else:
return True
async def set_static_ip(
self,
ip: str,
dns: str,
gateway: str,
subnet_mask: str = "255.255.255.0",
):
cfg_data_lan = "\n\t".join(
[
"config interface 'lan'",
"option type 'bridge'",
"option ifname 'eth0'",
"option proto 'static'",
f"option ipaddr '{ip}'",
f"option netmask '{subnet_mask}'",
f"option gateway '{gateway}'",
f"option dns '{dns}'",
]
)
data = await self.ssh.get_network_config()
split_data = data.split("\n\n")
for idx, val in enumerate(split_data):
if "config interface 'lan'" in val:
split_data[idx] = cfg_data_lan
config = "\n\n".join(split_data)
await self.ssh.send_command("echo '" + config + "' > /etc/config/network")
async def set_dhcp(self):
cfg_data_lan = "\n\t".join(
[
"config interface 'lan'",
"option type 'bridge'",
"option ifname 'eth0'",
"option proto 'dhcp'",
]
)
data = await self.ssh.get_network_config()
split_data = data.split("\n\n")
for idx, val in enumerate(split_data):
if "config interface 'lan'" in val:
split_data[idx] = cfg_data_lan
config = "\n\n".join(split_data)
await self.ssh.send_command("echo '" + config + "' > /etc/config/network")
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(self, web_net_conf: dict | list | None = None) -> str | None:
if web_net_conf is None:
try:
web_net_conf = await self.web.get_net_conf()
except APIError:
return None
if isinstance(web_net_conf, dict):
if "admin/network/iface_status/lan" in web_net_conf.keys():
web_net_conf = web_net_conf["admin/network/iface_status/lan"]
if web_net_conf is not None:
try:
return web_net_conf[0]["macaddr"]
except LookupError:
pass
return None
# could use ssh, but its slow and buggy
# result = await self.send_ssh_command("cat /sys/class/net/eth0/address")
# if result:
# return result.upper().strip()
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
return None
# Now get the API version
if rpc_version is not None:
try:
rpc_ver = rpc_version["VERSION"][0]["API"]
except LookupError:
rpc_ver = None
self.api_ver = rpc_ver
self.rpc.rpc_ver = self.api_ver # type: ignore
return self.api_ver
async def _get_fw_ver(self, web_bos_info: dict | None = None) -> str | None:
if web_bos_info is None:
try:
web_bos_info = await self.web.get_bos_info()
except APIError:
return None
if web_bos_info is None:
return None
if isinstance(web_bos_info, dict):
if "bos/info" in web_bos_info.keys():
web_bos_info = web_bos_info["bos/info"]
try:
ver = web_bos_info["version"].split("-")[5]
if "." in ver:
self.fw_ver = ver
except (LookupError, AttributeError):
return None
return self.fw_ver
async def _get_hostname(self) -> str | None:
try:
hostname = (await self.ssh.get_hostname()).strip()
except AttributeError:
return None
except Exception as e:
logging.error(f"{self} - Getting hostname failed: {e}")
return None
return hostname
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
return None
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (KeyError, IndexError, ValueError, TypeError):
pass
return None
async def _get_hashboards(
self,
rpc_temps: dict | None = None,
rpc_devdetails: dict | None = None,
rpc_devs: dict | None = None,
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
cmds = []
if rpc_temps is None:
cmds.append("temps")
if rpc_devdetails is None:
cmds.append("devdetails")
if rpc_devs is None:
cmds.append("devs")
if len(cmds) > 0:
try:
d = await self.rpc.multicommand(*cmds)
except APIError:
d = {}
try:
rpc_temps = d["temps"][0]
except LookupError:
rpc_temps = None
try:
rpc_devdetails = d["devdetails"][0]
except (KeyError, IndexError):
rpc_devdetails = None
try:
rpc_devs = d["devs"][0]
except LookupError:
rpc_devs = None
if rpc_temps is not None:
try:
offset = 6 if rpc_temps["TEMPS"][0]["ID"] in [6, 7, 8] else 1
for board in rpc_temps["TEMPS"]:
_id = board["ID"] - offset
chip_temp = round(board["Chip"])
board_temp = round(board["Board"])
hashboards[_id].chip_temp = chip_temp
hashboards[_id].temp = board_temp
except (IndexError, KeyError, ValueError, TypeError):
pass
if rpc_devdetails is not None:
try:
offset = 6 if rpc_devdetails["DEVDETAILS"][0]["ID"] in [6, 7, 8] else 1
for board in rpc_devdetails["DEVDETAILS"]:
_id = board["ID"] - offset
chips = board["Chips"]
hashboards[_id].chips = chips
hashboards[_id].missing = False
except (IndexError, KeyError):
pass
if rpc_devs is not None:
try:
offset = 6 if rpc_devs["DEVS"][0]["ID"] in [6, 7, 8] else 1
for board in rpc_devs["DEVS"]:
_id = board["ID"] - offset
hashboards[_id].hashrate = self.algo.hashrate(
rate=float(board["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except (IndexError, KeyError):
pass
return hashboards
async def _get_wattage(self, rpc_tunerstatus: dict | None = None) -> int | None:
if rpc_tunerstatus is None:
try:
rpc_tunerstatus = await self.rpc.tunerstatus()
except APIError:
return None
if rpc_tunerstatus is not None:
try:
return rpc_tunerstatus["TUNERSTATUS"][0][
"ApproximateMinerPowerConsumption"
]
except LookupError:
pass
return None
async def _get_wattage_limit(
self, rpc_tunerstatus: dict | None = None
) -> int | None:
if rpc_tunerstatus is None:
try:
rpc_tunerstatus = await self.rpc.tunerstatus()
except APIError:
return None
if rpc_tunerstatus is not None:
try:
return rpc_tunerstatus["TUNERSTATUS"][0]["PowerLimit"]
except LookupError:
pass
return None
async def _get_fans(self, rpc_fans: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_fans is None:
try:
rpc_fans = await self.rpc.fans()
except APIError:
return [Fan() for _ in range(self.expected_fans)]
if rpc_fans is not None:
fans = []
for n in range(self.expected_fans):
try:
fans.append(Fan(speed=rpc_fans["FANS"][n]["RPM"]))
except (IndexError, KeyError):
pass
return fans
return [Fan() for _ in range(self.expected_fans)]
async def _get_errors(
self, rpc_tunerstatus: dict | None = None
) -> list[MinerErrorData]:
if rpc_tunerstatus is None:
try:
rpc_tunerstatus = await self.rpc.tunerstatus()
except APIError:
return []
if rpc_tunerstatus is not None:
errors = []
try:
chain_status = rpc_tunerstatus["TUNERSTATUS"][0]["TunerChainStatus"]
if chain_status and len(chain_status) > 0:
offset = (
6 if int(chain_status[0]["HashchainIndex"]) in [6, 7, 8] else 0
)
for board in chain_status:
_id = board["HashchainIndex"] - offset
if board["Status"] not in [
"Stable",
"Testing performance profile",
"Tuning individual chips",
]:
_error = board["Status"].split(" {")[0]
_error = _error[0].lower() + _error[1:]
errors.append(
BraiinsOSError(error_message=f"Slot {_id} {_error}")
)
return errors # type: ignore
except (KeyError, IndexError):
pass
return []
async def _get_fault_light(self) -> bool:
if self.light:
return self.light
try:
data = (await self.ssh.get_led_status()).strip()
self.light = False
if data == "50":
self.light = True
return self.light
except (TypeError, AttributeError):
return self.light or False
async def _get_expected_hashrate(
self, rpc_devs: dict | None = None
) -> AlgoHashRateType | None:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
return None
if rpc_devs is not None:
try:
hr_list = []
for board in rpc_devs["DEVS"]:
expected_hashrate = float(board["Nominal MHS"])
if expected_hashrate:
hr_list.append(expected_hashrate)
if len(hr_list) == 0:
return self.algo.hashrate(
rate=float(0),
unit=self.algo.unit.default, # type: ignore
)
else:
return self.algo.hashrate(
rate=float(
(sum(hr_list) / len(hr_list))
* (self.expected_hashboards or 1)
),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (IndexError, KeyError):
pass
return None
async def _is_mining(self, rpc_devs: dict | None = None) -> bool | None:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.send_command(
"devs", ignore_errors=True, allow_warning=False
)
except APIError:
return None
if rpc_devs is not None:
try:
return any(dev["MHS 5s"] > 0 for dev in rpc_devs["DEVS"])
except LookupError:
pass
return None
async def _get_uptime(self, rpc_summary: dict | None = None) -> int | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
return None
if rpc_summary is not None:
try:
return int(rpc_summary["SUMMARY"][0]["Elapsed"])
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
return []
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
async def upgrade_firmware(
self,
*,
file: str | None = None,
url: str | None = None,
version: str | None = None,
keep_settings: bool = True,
) -> bool:
"""
Upgrade the firmware of the BOSMiner device.
Args:
file: The local file path of the firmware to be uploaded.
url: URL of firmware to download (not used in this implementation).
version: Specific version to upgrade to (not used in this implementation).
keep_settings: Whether to keep current settings (not used in this implementation).
Returns:
True if upgrade was successful, False otherwise.
"""
try:
logging.info("Starting firmware upgrade process.")
if not file:
raise ValueError("File location must be provided for firmware upgrade.")
# Read the firmware file contents
async with aiofiles.open(file, "rb") as f:
upgrade_contents = await f.read()
# Encode the firmware contents in base64
encoded_contents = base64.b64encode(upgrade_contents).decode("utf-8")
# Upload the firmware file to the BOSMiner device
logging.info(f"Uploading firmware file from {file} to the device.")
await self.ssh.send_command(
f"echo {encoded_contents} | base64 -d > /tmp/firmware.tar && sysupgrade /tmp/firmware.tar"
)
logging.info("Firmware upgrade process completed successfully.")
return True
except FileNotFoundError as e:
logging.error(f"File not found during the firmware upgrade process: {e}")
return False
except ValueError as e:
logging.error(
f"Validation error occurred during the firmware upgrade process: {e}"
)
return False
except OSError as e:
logging.error(f"OS error occurred during the firmware upgrade process: {e}")
return False
except Exception as e:
logging.error(
f"An unexpected error occurred during the firmware upgrade process: {e}",
exc_info=True,
)
return False
BOSER_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("grpc_miner_details", "get_miner_details")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("grpc_miner_details", "get_miner_details")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("grpc_miner_details", "get_miner_details")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[WebAPICommand("grpc_miner_details", "get_miner_details")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[WebAPICommand("grpc_hashboards", "get_hashboards")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("grpc_miner_stats", "get_miner_stats")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[
WebAPICommand(
"grpc_active_performance_mode", "get_active_performance_mode"
)
],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("grpc_cooling_state", "get_cooling_state")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[RPCAPICommand("rpc_tunerstatus", "tunerstatus")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("grpc_locate_device_status", "get_locate_device_status")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools", [WebAPICommand("grpc_pool_groups", "get_pool_groups")]
),
}
)
class BOSer(BraiinsOSFirmware):
"""Handler for new versions of BraiinsOS+ (post-gRPC)"""
_rpc_cls = BOSMinerRPCAPI
rpc: BOSMinerRPCAPI
_web_cls = BOSerWebAPI
web: BOSerWebAPI
data_locations = BOSER_DATA_LOC
supports_autotuning = True
supports_shutdown = True
async def fault_light_on(self) -> bool:
resp = await self.web.set_locate_device_status(True)
if resp.get("enabled", False):
return True
return False
async def fault_light_off(self) -> bool:
resp = await self.web.set_locate_device_status(False)
if resp == {}:
return True
return False
async def restart_backend(self) -> bool:
return await self.restart_boser()
async def restart_boser(self) -> bool:
await self.web.restart()
return True
async def stop_mining(self) -> bool:
try:
await self.web.pause_mining()
except APIError:
return False
return True
async def resume_mining(self) -> bool:
try:
await self.web.resume_mining()
except APIError:
return False
return True
async def reboot(self) -> bool:
ret = await self.web.reboot()
if ret == {}:
return True
return False
async def get_config(self) -> MinerConfig:
grpc_conf = await self.web.get_miner_configuration()
return MinerConfig.from_boser(grpc_conf)
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
boser_cfg = config.as_boser(user_suffix=user_suffix)
for key in boser_cfg:
await self.web.send_command(key, message=boser_cfg[key])
async def set_power_limit(self, wattage: int) -> bool:
try:
result = await self.web.set_power_target(
wattage,
save_action=SaveAction(SaveAction.SAVE_AND_FORCE_APPLY),
)
except APIError:
return False
try:
if result["powerTarget"]["watt"] == wattage:
return True
except KeyError:
pass
return False
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(self, grpc_miner_details: dict | None = None) -> str | None:
if grpc_miner_details is None:
try:
grpc_miner_details = await self.web.get_miner_details()
except APIError:
return None
if grpc_miner_details is not None:
try:
return grpc_miner_details["macAddress"].upper()
except (LookupError, TypeError):
pass
return None
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
return None
if rpc_version is not None:
try:
rpc_ver = rpc_version["VERSION"][0]["API"]
except LookupError:
rpc_ver = None
self.api_ver = rpc_ver
self.rpc.rpc_ver = self.api_ver # type: ignore
return self.api_ver
async def _get_fw_ver(self, grpc_miner_details: dict | None = None) -> str | None:
if grpc_miner_details is None:
try:
grpc_miner_details = await self.web.get_miner_details()
except APIError:
return None
fw_ver = None
if grpc_miner_details is not None:
try:
fw_ver = grpc_miner_details["bosVersion"]["current"]
except (KeyError, TypeError):
pass
# if we get the version data, parse it
if fw_ver is not None:
ver = fw_ver.split("-")[5]
if "." in ver:
self.fw_ver = ver
return self.fw_ver
async def _get_hostname(self, grpc_miner_details: dict | None = None) -> str | None:
if grpc_miner_details is None:
try:
grpc_miner_details = await self.web.get_miner_details()
except APIError:
return None
if grpc_miner_details is not None:
try:
return grpc_miner_details["hostname"]
except LookupError:
pass
return None
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
return None
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (KeyError, IndexError, ValueError, TypeError):
pass
return None
async def _get_expected_hashrate(
self, grpc_miner_details: dict | None = None
) -> AlgoHashRateType | None:
if grpc_miner_details is None:
try:
grpc_miner_details = await self.web.get_miner_details()
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | true |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/btminer.py | pyasic/miners/backends/btminer.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import asyncio
import logging
from typing import Optional
import aiofiles
import semver
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, WhatsminerError
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.miners.device.firmware import StockFirmware
from pyasic.rpc.btminer import BTMinerRPCAPI, BTMinerV3RPCAPI
class BTMiner(StockFirmware):
def __new__(cls, ip: str, version: str | None = None):
bases = cls.__bases__
bases = bases[1:]
def get_new(v: str | None):
if v is None:
return BTMinerV2
try:
semantic = semver.Version(
major=int(v[0:4]),
minor=int(v[4:6]),
patch=int(v[6:8]),
)
except ValueError:
return BTMinerV2
if semantic > semver.Version(major=2024, minor=11, patch=0):
return BTMinerV3
return BTMinerV2
inject = get_new(version)
bases = (inject,) + bases
cls = type(cls.__name__, bases, {})(ip=ip, version=version)
return cls
BTMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[
RPCAPICommand("rpc_summary", "summary"),
RPCAPICommand("rpc_get_miner_info", "get_miner_info"),
],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_get_version", "get_version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[
RPCAPICommand("rpc_get_version", "get_version"),
RPCAPICommand("rpc_summary", "summary"),
],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[RPCAPICommand("rpc_get_miner_info", "get_miner_info")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.ENVIRONMENT_TEMP): DataFunction(
"_get_env_temp",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.SERIAL_NUMBER): DataFunction(
"_get_serial_number",
[RPCAPICommand("rpc_get_miner_info", "get_miner_info")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[
RPCAPICommand("rpc_summary", "summary"),
RPCAPICommand("rpc_get_psu", "get_psu"),
],
),
str(DataOptions.FAN_PSU): DataFunction(
"_get_fan_psu",
[
RPCAPICommand("rpc_summary", "summary"),
RPCAPICommand("rpc_get_psu", "get_psu"),
],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[
RPCAPICommand("rpc_get_error_code", "get_error_code"),
RPCAPICommand("rpc_summary", "summary"),
],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[RPCAPICommand("rpc_get_miner_info", "get_miner_info")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[RPCAPICommand("rpc_status", "status")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class BTMinerV2(StockFirmware):
"""Base handler for BTMiner based miners."""
_rpc_cls = BTMinerRPCAPI
rpc: BTMinerRPCAPI
data_locations = BTMINER_DATA_LOC
supports_shutdown = True
supports_power_modes = True
async def _reset_rpc_pwd_to_admin(self, pwd: str):
try:
data = await self.rpc.update_pwd(pwd, "admin")
except APIError:
return False
if data:
if "Code" in data.keys():
if data["Code"] == 131:
return True
return False
async def fault_light_off(self) -> bool:
try:
data = await self.rpc.set_led(auto=True)
except APIError:
return False
if data:
if "Code" in data.keys():
if data["Code"] == 131:
self.light = False
return True
return False
async def fault_light_on(self) -> bool:
try:
data = await self.rpc.set_led(auto=False)
await self.rpc.set_led(
auto=False, color="green", start=0, period=1, duration=0
)
except APIError:
return False
if data:
if "Code" in data.keys():
if data["Code"] == 131:
self.light = True
return True
return False
async def reboot(self) -> bool:
try:
data = await self.rpc.reboot()
except APIError:
return False
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
return False
async def restart_backend(self) -> bool:
try:
data = await self.rpc.restart()
except APIError:
return False
if data.get("Msg"):
if data["Msg"] == "API command OK":
return True
return False
async def stop_mining(self) -> bool:
try:
data = await self.rpc.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:
try:
data = await self.rpc.power_on()
except APIError:
return False
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
) -> None:
self.config = config
conf = config.as_wm(user_suffix=user_suffix)
pools_conf = conf["pools"]
try:
await self.rpc.update_pools(**pools_conf)
if conf["mode"] == "normal":
await self.rpc.set_normal_power()
elif conf["mode"] == "high":
await self.rpc.set_high_power()
elif conf["mode"] == "low":
await self.rpc.set_low_power()
elif conf["mode"] == "power_tuning":
await self.rpc.adjust_power_limit(conf["power_tuning"]["wattage"])
except APIError:
# cannot update, no API access usually
pass
async def get_config(self) -> MinerConfig:
pools = None
summary = None
status = None
try:
data = await self.rpc.multicommand("pools", "summary", "status")
pools = data["pools"][0]
summary = data["summary"][0]
status = data["status"][0]
except APIError as e:
logging.warning(e)
except LookupError:
pass
if pools is not None:
cfg = MinerConfig.from_api(pools)
else:
cfg = MinerConfig()
is_mining = await self._is_mining(status)
if not is_mining:
cfg.mining_mode = MiningModeConfig.sleep()
return cfg
if summary is not None:
mining_mode = None
try:
mining_mode = summary["SUMMARY"][0]["Power Mode"]
except LookupError:
pass
if mining_mode == "High":
cfg.mining_mode = MiningModeConfig.high()
return cfg
elif mining_mode == "Low":
cfg.mining_mode = MiningModeConfig.low()
return cfg
try:
power_lim = summary["SUMMARY"][0]["Power Limit"]
except LookupError:
power_lim = None
if power_lim is None:
cfg.mining_mode = MiningModeConfig.normal()
return cfg
cfg.mining_mode = MiningModeConfig.power_tuning(power=power_lim)
self.config = cfg
return self.config
cfg.mining_mode = MiningModeConfig.normal()
return cfg
async def set_power_limit(self, wattage: int) -> bool:
try:
await self.rpc.adjust_power_limit(wattage)
except Exception as e:
logging.warning(f"{self} set_power_limit: {e}")
return False
else:
return True
return False
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(
self, rpc_summary: dict | None = None, rpc_get_miner_info: dict | None = None
) -> str | None:
if rpc_get_miner_info is None:
try:
rpc_get_miner_info = await self.rpc.get_miner_info()
except APIError:
pass
if rpc_get_miner_info is not None:
try:
mac = rpc_get_miner_info["Msg"]["mac"]
return str(mac).upper()
except KeyError:
pass
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
mac = rpc_summary["SUMMARY"][0]["MAC"]
return str(mac).upper()
except LookupError:
pass
return None
async def _get_api_ver(self, rpc_get_version: dict | None = None) -> str | None:
if rpc_get_version is None:
try:
rpc_get_version = await self.rpc.get_version()
except APIError:
pass
if rpc_get_version is not None:
if "Code" in rpc_get_version.keys():
if rpc_get_version["Code"] == 131:
try:
rpc_ver = rpc_get_version["Msg"]
if not isinstance(rpc_ver, str):
rpc_ver = rpc_ver["rpc_ver"]
self.api_ver = rpc_ver.replace("whatsminer v", "")
except (KeyError, TypeError):
pass
else:
return self.api_ver
return self.api_ver
async def _get_fw_ver(
self, rpc_get_version: dict | None = None, rpc_summary: dict | None = None
) -> str | None:
if rpc_get_version is None:
try:
rpc_get_version = await self.rpc.get_version()
except APIError:
pass
if rpc_get_version is not None:
if "Code" in rpc_get_version.keys():
if rpc_get_version["Code"] == 131:
try:
self.fw_ver = rpc_get_version["Msg"]["fw_ver"]
except (KeyError, TypeError):
pass
else:
return self.fw_ver
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary:
try:
self.fw_ver = rpc_summary["SUMMARY"][0]["Firmware Version"].replace(
"'", ""
)
except LookupError:
pass
return self.fw_ver
async def _get_hostname(self, rpc_get_miner_info: dict | None = None) -> str | None:
hostname = None
if rpc_get_miner_info is None:
try:
rpc_get_miner_info = await self.rpc.get_miner_info()
except APIError:
return None # only one way to get this
if rpc_get_miner_info is not None:
try:
hostname = rpc_get_miner_info["Msg"]["hostname"]
except KeyError:
return None
return hostname
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _get_hashboards(self, rpc_devs: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
if rpc_devs is not None:
try:
for board in rpc_devs["DEVS"]:
asc = board.get("ASC")
if asc is None:
asc = board["Slot"]
if len(hashboards) < asc + 1:
hashboards.append(
HashBoard(slot=asc, expected_chips=self.expected_chips)
)
self.expected_hashboards += 1
hashboards[asc].chip_temp = round(board["Chip Temp Avg"])
hashboards[asc].temp = round(board["Temperature"])
hashboards[asc].hashrate = self.algo.hashrate(
rate=float(board["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[asc].chips = board["Effective Chips"]
hashboards[asc].serial_number = board["PCB SN"]
hashboards[asc].missing = False
except LookupError:
pass
return hashboards
async def _get_env_temp(self, rpc_summary: dict | None = None) -> float | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return rpc_summary["SUMMARY"][0]["Env Temp"]
except LookupError:
pass
return None
async def _get_wattage(self, rpc_summary: dict | None = None) -> int | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
wattage = rpc_summary["SUMMARY"][0]["Power"]
return wattage if not wattage == -1 else None
except LookupError:
pass
return None
async def _get_wattage_limit(self, rpc_summary: dict | None = None) -> int | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return rpc_summary["SUMMARY"][0]["Power Limit"]
except LookupError:
pass
return None
async def _get_fans(
self, rpc_summary: dict | None = None, rpc_get_psu: dict | None = None
) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
fans = [Fan() for _ in range(self.expected_fans)]
if rpc_summary is not None:
try:
if self.expected_fans > 0:
fans = [
Fan(speed=rpc_summary["SUMMARY"][0].get("Fan Speed In", 0)),
Fan(speed=rpc_summary["SUMMARY"][0].get("Fan Speed Out", 0)),
]
except LookupError:
pass
return fans
async def _get_fan_psu(
self, rpc_summary: dict | None = None, rpc_get_psu: dict | None = None
) -> int | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return int(rpc_summary["SUMMARY"][0]["Power Fanspeed"])
except LookupError:
pass
if rpc_get_psu is None:
try:
rpc_get_psu = await self.rpc.get_psu()
except APIError:
pass
if rpc_get_psu is not None:
try:
return int(rpc_get_psu["Msg"]["fan_speed"])
except (KeyError, TypeError):
pass
return None
async def _get_errors(
self, rpc_summary: dict | None = None, rpc_get_error_code: dict | None = None
) -> list[MinerErrorData]:
errors = []
if rpc_get_error_code is None and rpc_summary is None:
try:
rpc_get_error_code = await self.rpc.get_error_code()
except APIError:
pass
if rpc_get_error_code is not None:
try:
for err in rpc_get_error_code["Msg"]["error_code"]:
if isinstance(err, dict):
for code in err:
errors.append(WhatsminerError(error_code=int(code)))
else:
errors.append(WhatsminerError(error_code=int(err)))
except KeyError:
pass
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
for i in range(rpc_summary["SUMMARY"][0]["Error Code Count"]):
err = rpc_summary["SUMMARY"][0].get(f"Error Code {i}")
if err:
errors.append(WhatsminerError(error_code=err))
except (LookupError, ValueError, TypeError):
pass
return errors # type: ignore[return-value]
async def _get_serial_number(
self, rpc_get_miner_info: dict | None = None
) -> str | None:
if rpc_get_miner_info is None:
try:
rpc_get_miner_info = await self.rpc.get_miner_info()
except APIError:
pass
if rpc_get_miner_info is not None:
try:
return rpc_get_miner_info["Msg"]["minersn"]
except LookupError:
pass
return None
async def _get_expected_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
expected_hashrate = rpc_summary["SUMMARY"][0]["Factory GHS"]
if expected_hashrate:
return self.algo.hashrate(
rate=float(expected_hashrate),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _get_fault_light(
self, rpc_get_miner_info: dict | None = None
) -> bool | None:
if rpc_get_miner_info is None:
try:
rpc_get_miner_info = await self.rpc.get_miner_info()
except APIError:
if not self.light:
self.light = False
if rpc_get_miner_info is not None:
try:
self.light = not (rpc_get_miner_info["Msg"]["ledstat"] == "auto")
except KeyError:
pass
return self.light if self.light else False
async def set_static_ip(
self,
ip: str,
dns: str,
gateway: str,
subnet_mask: str = "255.255.255.0",
hostname: str | None = None,
):
if not hostname:
hostname = await self.get_hostname()
if hostname is None:
hostname = str(self.ip)
await self.rpc.net_config(
ip=ip, mask=subnet_mask, dns=dns, gate=gateway, host=hostname, dhcp=False
)
async def set_dhcp(self, hostname: str | None = None):
if hostname:
await self.set_hostname(hostname)
await self.rpc.net_config()
async def set_hostname(self, hostname: str):
await self.rpc.set_hostname(hostname)
async def _is_mining(self, rpc_status: dict | None = None) -> bool | None:
if rpc_status is None:
try:
rpc_status = await self.rpc.status()
except APIError:
pass
if rpc_status is not None:
try:
if rpc_status["Msg"].get("btmineroff"):
try:
await self.rpc.devdetails()
except APIError:
return False
return True
return True if rpc_status["Msg"]["mineroff"] == "false" else False
except LookupError:
pass
return False
async def _get_uptime(self, rpc_summary: dict | None = None) -> int | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return int(rpc_summary["SUMMARY"][0]["Elapsed"])
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
async def upgrade_firmware(
self,
*,
file: str | None = None,
url: str | None = None,
version: str | None = None,
keep_settings: bool = True,
) -> bool:
"""
Upgrade the firmware of the Whatsminer device.
Args:
file: The local file path of the firmware to be uploaded.
url: URL to download firmware from (not supported).
version: Specific version to upgrade to (not supported).
keep_settings: Whether to keep settings after upgrade.
Returns:
bool: True if firmware upgrade was successful.
"""
try:
logging.info("Starting firmware upgrade process for Whatsminer.")
if not file:
raise ValueError("File location must be provided for firmware upgrade.")
# Read the firmware file contents
async with aiofiles.open(file, "rb") as f:
upgrade_contents = await f.read()
await self.rpc.update_firmware(upgrade_contents)
logging.info(
"Firmware upgrade process completed successfully for Whatsminer."
)
return True
except FileNotFoundError as e:
logging.error(f"File not found during the firmware upgrade process: {e}")
raise
except ValueError as e:
logging.error(
f"Validation error occurred during the firmware upgrade process: {e}"
)
raise
except OSError as e:
logging.error(f"OS error occurred during the firmware upgrade process: {e}")
raise
except Exception as e:
logging.error(
f"An unexpected error occurred during the firmware upgrade process: {e}",
exc_info=True,
)
raise
BTMINERV3_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac", [RPCAPICommand("rpc_get_device_info", "get.device.info")]
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_version",
[RPCAPICommand("rpc_get_device_info", "get.device.info")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_firmware_version",
[RPCAPICommand("rpc_get_device_info", "get.device.info")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname", [RPCAPICommand("rpc_get_device_info", "get.device.info")]
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_light_flashing",
[RPCAPICommand("rpc_get_device_info", "get.device.info")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[RPCAPICommand("rpc_get_device_info", "get.device.info")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
str(DataOptions.FAN_PSU): DataFunction(
"_get_psu_fans", [RPCAPICommand("rpc_get_device_info", "get.device.info")]
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_get_device_info", "get.device.info"),
RPCAPICommand(
"rpc_get_miner_status_edevs",
"get.miner.status:edevs",
),
],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
str(DataOptions.SERIAL_NUMBER): DataFunction(
"_get_serial_number",
[RPCAPICommand("rpc_get_device_info", "get.device.info")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
str(DataOptions.ENVIRONMENT_TEMP): DataFunction(
"_get_env_temp",
[RPCAPICommand("rpc_get_miner_status_summary", "get.miner.status:summary")],
),
}
)
class BTMinerV3(StockFirmware):
_rpc_cls = BTMinerV3RPCAPI
rpc: BTMinerV3RPCAPI
data_locations = BTMINERV3_DATA_LOC
supports_shutdown = True
supports_autotuning = True
supports_power_modes = True
async def get_config(self) -> MinerConfig:
pools = None
settings = None
device_info = None
try:
pools = await self.rpc.get_miner_status_pools()
settings = await self.rpc.get_miner_setting()
device_info = await self.rpc.get_device_info()
except APIError as e:
logging.warning(e)
except LookupError:
pass
if pools is not None and settings is not None and device_info is not None:
self.config = MinerConfig.from_btminer_v3(
rpc_pools=pools, rpc_settings=settings, rpc_device_info=device_info
)
else:
self.config = MinerConfig()
return self.config
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
conf = config.as_btminer_v3(user_suffix=user_suffix)
await asyncio.gather(
*[self.rpc.send_command(k, parameters=v) for k, v in conf.values()]
)
async def fault_light_off(self) -> bool:
try:
data = await self.rpc.set_system_led()
except APIError:
return False
if data:
if "code" in data.keys():
if data["code"] == 0:
self.light = False
return True
return False
async def fault_light_on(self) -> bool:
try:
data = await self.rpc.set_system_led(
leds=[{"color": "red", "period": 60, "duration": 20, "start": 0}]
)
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | true |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/goldshell.py | pyasic/miners/backends/goldshell.py | # ------------------------------------------------------------------------------
# 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.config import MinerConfig, MiningModeConfig
from pyasic.data import HashBoard
from pyasic.errors import APIError
from pyasic.logger import logger
from pyasic.miners.backends import BFGMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.web.goldshell import GoldshellWebAPI
GOLDSHELL_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_setting", "setting")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_status", "status")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_devs", "devs"),
RPCAPICommand("rpc_devdetails", "devdetails"),
],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class GoldshellMiner(BFGMiner):
"""Handler for goldshell miners"""
_web_cls = GoldshellWebAPI
web: GoldshellWebAPI
data_locations = GOLDSHELL_DATA_LOC
supports_shutdown = True
supports_power_modes = True
async def get_config(self) -> MinerConfig:
# get pool data
try:
pools = await self.web.pools()
except APIError:
if self.config is not None:
return self.config
self.config = MinerConfig.from_goldshell(pools)
return self.config
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
pools_data = await self.web.pools()
# have to delete all the pools one at a time first
for pool in pools_data:
await self.web.delpool(
url=pool["url"],
user=pool["user"],
password=pool["pass"],
dragid=pool["dragid"],
)
self.config = config
cfg = config.as_goldshell(user_suffix=user_suffix)
# send them back 1 at a time
for pool in cfg["pools"]:
await self.web.newpool(
url=pool["url"], user=pool["user"], password=pool["pass"]
)
settings = await self.web.setting()
for idx, plan in enumerate(settings["powerplans"]):
if plan["level"] == cfg["settings"]["level"]:
settings["select"] = idx
await self.web.set_setting(settings)
async def _get_mac(self, web_setting: dict | None = None) -> str | None:
if web_setting is None:
try:
web_setting = await self.web.setting()
except APIError:
return None
if web_setting is not None:
try:
return web_setting["name"]
except KeyError:
pass
return None
async def _get_fw_ver(self, web_status: dict | None = None) -> str | None:
if web_status is None:
try:
web_status = await self.web.setting()
except APIError:
return None
if web_status is not None:
try:
return web_status["firmware"]
except KeyError:
pass
return None
async def _get_hashboards(
self, rpc_devs: dict | None = None, rpc_devdetails: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_devs is not None:
if rpc_devs.get("DEVS"):
for board in rpc_devs["DEVS"]:
if board.get("ID") is not None:
try:
b_id = board["ID"]
hashboards[b_id].hashrate = self.algo.hashrate(
rate=float(board["MHS 20s"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[b_id].temp = board["tstemp-2"]
hashboards[b_id].missing = False
except KeyError:
pass
else:
logger.error(self, rpc_devs)
if rpc_devdetails is None:
try:
rpc_devdetails = await self.rpc.devdetails()
except APIError:
pass
if rpc_devdetails is not None:
if rpc_devdetails.get("DEVS"):
for board in rpc_devdetails["DEVS"]:
if board.get("ID") is not None:
try:
b_id = board["ID"]
hashboards[b_id].chips = board["chips-nr"]
except KeyError:
pass
else:
logger.error(self, rpc_devdetails)
return hashboards
async def stop_mining(self) -> bool:
settings = await self.web.setting()
mode = MiningModeConfig.sleep()
cfg = mode.as_goldshell()
level = cfg["settings"]["level"]
for idx, plan in enumerate(settings["powerplans"]):
if plan["level"] == level:
settings["select"] = idx
await self.web.set_setting(settings)
return True
async def resume_mining(self) -> bool:
settings = await self.web.setting()
mode = MiningModeConfig.normal()
cfg = mode.as_goldshell()
level = cfg["settings"]["level"]
for idx, plan in enumerate(settings["powerplans"]):
if plan["level"] == level:
settings["select"] = idx
await self.web.set_setting(settings)
return True
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/whatsminer.py | pyasic/miners/backends/whatsminer.py | # ------------------------------------------------------------------------------
# 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.btminer import BTMiner, BTMinerV2
class M7X(BTMiner):
supports_autotuning = True
supports_presets = True
class M6X(BTMiner):
supports_autotuning = True
supports_presets = True
class M5X(BTMiner):
supports_autotuning = True
supports_presets = True
class M3X(BTMiner):
supports_autotuning = True
supports_presets = True
class M2X(BTMinerV2):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/bmminer.py | pyasic/miners/backends/bmminer.py | # ------------------------------------------------------------------------------
# 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.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.miners.device.firmware import StockFirmware
from pyasic.rpc.bmminer import BMMinerRPCAPI
BMMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class BMMiner(StockFirmware):
"""Base handler for BMMiner based miners."""
_rpc_cls = BMMinerRPCAPI
rpc: BMMinerRPCAPI
data_locations = BMMINER_DATA_LOC
async def get_config(self) -> MinerConfig:
# get pool data
try:
pools = await self.rpc.pools()
except APIError:
if self.config is not None:
return self.config
self.config = MinerConfig.from_api(pools)
return self.config
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.api_ver = rpc_version["VERSION"][0]["API"]
except LookupError:
pass
return self.api_ver
async def _get_fw_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.fw_ver = rpc_version["VERSION"][0]["CompileTime"]
except LookupError:
pass
return self.fw_ver
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
# get hr from API
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["GHS 5s"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_hashboards(self, rpc_stats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
board_offset = -1
boards = rpc_stats["STATS"]
if len(boards) > 1:
for board_num in range(1, 16, 5):
for _b_num in range(5):
b = boards[1].get(f"chain_acn{board_num + _b_num}")
if b and not b == 0 and board_offset == -1:
board_offset = board_num
if board_offset == -1:
board_offset = 1
real_slots = []
for i in range(board_offset, board_offset + 4):
try:
key = f"chain_acs{i}"
if boards[1].get(key, "") != "":
real_slots.append(i)
except LookupError:
pass
if len(real_slots) < 3:
real_slots = list(
range(board_offset, board_offset + self.expected_hashboards)
)
for i in real_slots:
hashboard = HashBoard(
slot=i - board_offset, expected_chips=self.expected_chips
)
chip_temp = boards[1].get(f"temp{i}")
if chip_temp:
hashboard.chip_temp = round(chip_temp)
temp = boards[1].get(f"temp2_{i}")
if temp:
hashboard.temp = round(temp)
hashrate = boards[1].get(f"chain_rate{i}")
if hashrate:
hashboard.hashrate = self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
chips = boards[1].get(f"chain_acn{i}")
if chips:
hashboard.chips = chips
hashboard.missing = False
if (not chips) or (not chips > 0):
hashboard.missing = True
hashboards.append(hashboard)
except (LookupError, ValueError, TypeError):
pass
return hashboards
async def _get_fans(self, rpc_stats: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
fans = [Fan() for _ in range(self.expected_fans)]
if rpc_stats is not None:
try:
fan_offset = -1
for fan_num in range(1, 8, 4):
for _f_num in range(4):
f = rpc_stats["STATS"][1].get(f"fan{fan_num + _f_num}", 0)
if f and not f == 0 and fan_offset == -1:
fan_offset = fan_num
if fan_offset == -1:
fan_offset = 1
for fan in range(self.expected_fans):
fans[fan].speed = rpc_stats["STATS"][1].get(
f"fan{fan_offset + fan}", 0
)
except LookupError:
pass
return fans
async def _get_expected_hashrate(
self, rpc_stats: dict | None = None
) -> AlgoHashRateType | None:
# X19 method, not sure compatibility
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
expected_rate = rpc_stats["STATS"][1]["total_rateideal"]
try:
rate_unit = rpc_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "GH"
return self.algo.hashrate(
rate=float(expected_rate), unit=self.algo.unit.from_str(rate_unit)
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except LookupError:
pass
return None
async def _get_uptime(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return int(rpc_stats["STATS"][1]["Elapsed"])
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/bfgminer.py | pyasic/miners/backends/bfgminer.py | # ------------------------------------------------------------------------------
# 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.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.miners.device.firmware import StockFirmware
from pyasic.rpc.bfgminer import BFGMinerRPCAPI
BFGMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class BFGMiner(StockFirmware):
"""Base handler for BFGMiner based miners."""
_rpc_cls = BFGMinerRPCAPI
rpc: BFGMinerRPCAPI
data_locations = BFGMINER_DATA_LOC
async def get_config(self) -> MinerConfig:
# get pool data
try:
pools = await self.rpc.pools()
except APIError:
if self.config is not None:
return self.config
self.config = MinerConfig.from_api(pools)
return self.config
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.api_ver = rpc_version["VERSION"][0]["API"]
except LookupError:
pass
return self.api_ver
async def _get_fw_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.fw_ver = rpc_version["VERSION"][0]["CompileTime"]
except LookupError:
pass
return self.fw_ver
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
# get hr from API
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 20s"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_hashboards(self, rpc_stats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
board_offset = -1
boards = rpc_stats["STATS"]
if len(boards) > 1:
for board_num in range(1, 16, 5):
for _b_num in range(5):
b = boards[1].get(f"chain_acn{board_num + _b_num}")
if b and not b == 0 and board_offset == -1:
board_offset = board_num
if board_offset == -1:
board_offset = 1
for i in range(
board_offset, board_offset + self.expected_hashboards
):
hashboard = HashBoard(
slot=i - board_offset, expected_chips=self.expected_chips
)
chip_temp = boards[1].get(f"temp{i}")
if chip_temp:
hashboard.chip_temp = round(chip_temp)
temp = boards[1].get(f"temp2_{i}")
if temp:
hashboard.temp = round(temp)
hashrate = boards[1].get(f"chain_rate{i}")
if hashrate:
hashboard.hashrate = self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
chips = boards[1].get(f"chain_acn{i}")
if chips:
hashboard.chips = chips
hashboard.missing = False
if (not chips) or (not chips > 0):
hashboard.missing = True
hashboards.append(hashboard)
except (LookupError, ValueError, TypeError):
pass
return hashboards
async def _get_fans(self, rpc_stats: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
fans_data = [None, None, None, None]
if rpc_stats is not None:
try:
fan_offset = -1
for fan_num in range(0, 8, 4):
for _f_num in range(4):
f = rpc_stats["STATS"][1].get(f"fan{fan_num + _f_num}", 0)
if not f == 0 and fan_offset == -1:
fan_offset = fan_num
if fan_offset == -1:
fan_offset = 1
for fan in range(self.expected_fans):
fans_data[fan] = rpc_stats["STATS"][1].get(
f"fan{fan_offset + fan}", 0
)
except LookupError:
pass
fans = [Fan(speed=d) for d in fans_data if d is not None]
return fans
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
async def _get_expected_hashrate(
self, rpc_stats: dict | None = None
) -> AlgoHashRateType | None:
# X19 method, not sure compatibility
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
expected_rate = rpc_stats["STATS"][1]["total_rateideal"]
try:
rate_unit = rpc_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "GH"
return self.algo.hashrate(
rate=float(expected_rate), unit=self.algo.unit.from_str(rate_unit)
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/innosilicon.py | pyasic/miners/backends/innosilicon.py | # ------------------------------------------------------------------------------
# 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.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes.innosilicon import InnosiliconError
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.backends import CGMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.web.innosilicon import InnosiliconWebAPI
INNOSILICON_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[
WebAPICommand("web_get_all", "getAll"),
WebAPICommand("web_overview", "overview"),
],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[
RPCAPICommand("rpc_summary", "summary"),
WebAPICommand("web_get_all", "getAll"),
],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_stats", "stats"),
WebAPICommand("web_get_all", "getAll"),
],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[
WebAPICommand("web_get_all", "getAll"),
RPCAPICommand("rpc_stats", "stats"),
],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[
WebAPICommand("web_get_all", "getAll"),
],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[
WebAPICommand("web_get_all", "getAll"),
],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[
WebAPICommand("web_get_error_detail", "getErrorDetail"),
],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools", [RPCAPICommand("rpc_pools", "pools")]
),
}
)
class Innosilicon(CGMiner):
"""Base handler for Innosilicon miners"""
_web_cls = InnosiliconWebAPI
web: InnosiliconWebAPI
data_locations = INNOSILICON_DATA_LOC
supports_shutdown = True
async def get_config(self) -> MinerConfig:
# get pool data
try:
pools = await self.web.pools()
if pools and "pools" in pools:
self.config = MinerConfig.from_inno(pools["pools"])
except APIError:
pass
return self.config or MinerConfig()
async def reboot(self) -> bool:
try:
data = await self.web.reboot()
except APIError:
return False
else:
return data["success"]
async def restart_cgminer(self) -> bool:
try:
data = await self.web.restart_cgminer()
except APIError:
return False
else:
return data["success"]
async def restart_backend(self) -> bool:
return await self.restart_cgminer()
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
await self.web.update_pools(config.as_inno(user_suffix=user_suffix))
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(
self, web_get_all: dict | None = None, web_overview: dict | None = None
) -> str | None:
if web_get_all:
web_get_all = web_get_all["all"]
if web_get_all is None and web_overview is None:
try:
web_overview = await self.web.overview()
except APIError:
pass
if web_get_all is not None:
try:
mac = web_get_all["mac"]
return mac.upper()
except KeyError:
pass
if web_overview is not None:
try:
mac = web_overview["version"]["ethaddr"]
return mac.upper()
except KeyError:
pass
return None
async def _get_hashrate(
self, rpc_summary: dict | None = None, web_get_all: dict | None = None
) -> AlgoHashRateType | None:
if web_get_all:
web_get_all = web_get_all["all"]
if rpc_summary is None and web_get_all is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if web_get_all is not None:
try:
if "Hash Rate H" in web_get_all["total_hash"].keys():
return self.algo.hashrate(
rate=float(web_get_all["total_hash"]["Hash Rate H"]),
unit=self.algo.unit.H, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
elif "Hash Rate" in web_get_all["total_hash"].keys():
return self.algo.hashrate(
rate=float(web_get_all["total_hash"]["Hash Rate"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except KeyError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except (KeyError, IndexError):
pass
return None
async def _get_hashboards(
self, rpc_stats: dict | None = None, web_get_all: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
if web_get_all:
web_get_all = web_get_all["all"]
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if web_get_all is None:
try:
web_get_all = await self.web.get_all()
except APIError:
pass
else:
web_get_all = web_get_all["all"]
if rpc_stats is not None:
if rpc_stats.get("STATS"):
for board in rpc_stats["STATS"]:
try:
idx = board["Chain ID"]
chips = board["Num active chips"]
except KeyError:
pass
else:
hashboards[idx].chips = chips
hashboards[idx].missing = False
if web_get_all is not None:
if web_get_all.get("chain"):
for board in web_get_all["chain"]:
idx = board.get("ASC")
if idx is not None:
temp = board.get("Temp min")
if temp:
hashboards[idx].temp = round(temp)
hashrate = board.get("Hash Rate H")
if hashrate:
hashboards[idx].hashrate = self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.H, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
chip_temp = board.get("Temp max")
if chip_temp:
hashboards[idx].chip_temp = round(chip_temp)
return hashboards
async def _get_wattage(
self, web_get_all: dict | None = None, rpc_stats: dict | None = None
) -> int | None:
if web_get_all:
web_get_all = web_get_all["all"]
if web_get_all is None:
try:
web_get_all = await self.web.get_all()
except APIError:
pass
else:
web_get_all = web_get_all["all"]
if web_get_all is not None:
try:
return web_get_all["power"]
except KeyError:
pass
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
if rpc_stats.get("STATS"):
for board in rpc_stats["STATS"]:
try:
wattage = board["power"]
except KeyError:
pass
else:
wattage = int(wattage)
return wattage
return None
async def _get_fans(self, web_get_all: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_get_all:
web_get_all = web_get_all["all"]
if web_get_all is None:
try:
web_get_all = await self.web.get_all()
except APIError:
pass
else:
web_get_all = web_get_all["all"]
fans = [Fan() for _ in range(self.expected_fans)]
if web_get_all is not None:
try:
spd = web_get_all["fansSpeed"]
except KeyError:
pass
else:
spd_converted = round((int(spd) * 6000) / 100)
for i in range(self.expected_fans):
fans[i].speed = spd_converted
return fans
async def _get_errors( # type: ignore[override]
self, web_get_error_detail: dict | None = None
) -> list[InnosiliconError]:
errors = []
if web_get_error_detail is None:
try:
web_get_error_detail = await self.web.get_error_detail()
except APIError:
pass
if web_get_error_detail is not None:
try:
# only 1 error?
# TODO: check if this should be a loop, can't remember.
err = web_get_error_detail["code"]
except KeyError:
pass
else:
err = int(err)
if not err == 0:
errors.append(InnosiliconError(error_code=err))
return errors
async def _get_wattage_limit(self, web_get_all: dict | None = None) -> int | None:
if web_get_all:
web_get_all = web_get_all["all"]
if web_get_all is None:
try:
web_get_all = await self.web.get_all()
except APIError:
pass
else:
web_get_all = web_get_all["all"]
if web_get_all is not None:
try:
level = web_get_all["running_mode"]["level"]
except KeyError:
pass
else:
# this is very possibly not correct.
level = int(level)
limit = 1250 + (250 * level)
return limit
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/hammer.py | pyasic/miners/backends/hammer.py | # ------------------------------------------------------------------------------
# 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 typing import cast
from pyasic import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, X19Error
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.firmware import StockFirmware
from pyasic.rpc.ccminer import CCMinerRPCAPI
from pyasic.web.hammer import HammerWebAPI
HAMMER_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_get_blink_status", "get_blink_status")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_get_conf", "get_miner_conf")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class BlackMiner(StockFirmware):
"""Handler for Hammer miners."""
_rpc_cls = CCMinerRPCAPI
rpc: CCMinerRPCAPI
_web_cls = HammerWebAPI
web: HammerWebAPI
data_locations = HAMMER_DATA_LOC
async def get_config(self) -> MinerConfig:
data = await self.web.get_miner_conf()
if data:
self.config = MinerConfig.from_hammer(data)
return self.config or MinerConfig()
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
await self.web.set_miner_conf(config.as_hammer(user_suffix=user_suffix))
async def fault_light_on(self) -> bool:
data = await self.web.blink(blink=True)
if data:
if data.get("code") == "B000":
self.light = True
return self.light or False
async def fault_light_off(self) -> bool:
data = await self.web.blink(blink=False)
if data:
if data.get("code") == "B100":
self.light = False
return self.light or False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
return True
return False
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.api_ver = rpc_version["VERSION"][0]["API"]
except LookupError:
pass
return self.api_ver
async def _get_fw_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.fw_ver = rpc_version["VERSION"][0]["CompileTime"]
except LookupError:
pass
return self.fw_ver
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
# get hr from API
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 5s"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_hashboards(self, rpc_stats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
board_offset = -1
boards = rpc_stats["STATS"]
if len(boards) > 1:
for board_num in range(1, 16, 5):
for _b_num in range(5):
b = boards[1].get(f"chain_acn{board_num + _b_num}")
if b and not b == 0 and board_offset == -1:
board_offset = board_num
if board_offset == -1:
board_offset = 1
real_slots = []
for i in range(board_offset, board_offset + 4):
try:
key = f"chain_acs{i}"
if boards[1].get(key, "") != "":
real_slots.append(i)
except LookupError:
pass
if len(real_slots) < 3:
real_slots = list(
range(board_offset, board_offset + self.expected_hashboards)
)
for i in real_slots:
hashboard = HashBoard(
slot=i - board_offset, expected_chips=self.expected_chips
)
temp = boards[1].get(f"temp{i}")
if temp:
hashboard.chip_temp = round(temp)
hashboard.temp = round(temp)
hashrate = boards[1].get(f"chain_rate{i}")
if hashrate:
hashboard.hashrate = self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
chips = boards[1].get(f"chain_acn{i}")
if chips:
hashboard.chips = chips
hashboard.missing = False
if (not chips) or (not chips > 0):
hashboard.missing = True
hashboards.append(hashboard)
except (LookupError, ValueError, TypeError):
pass
return hashboards
async def _get_fans(self, rpc_stats: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
fans = [Fan() for _ in range(self.expected_fans)]
if rpc_stats is not None:
try:
fan_offset = -1
for fan_num in range(1, 8, 4):
for _f_num in range(4):
f = rpc_stats["STATS"][1].get(f"fan{fan_num + _f_num}", 0)
if f and not f == 0 and fan_offset == -1:
fan_offset = fan_num
if fan_offset == -1:
fan_offset = 1
for fan in range(self.expected_fans):
fans[fan].speed = rpc_stats["STATS"][1].get(
f"fan{fan_offset + fan}", 0
)
except LookupError:
pass
return fans
async def _get_hostname(
self, web_get_system_info: dict | None = None
) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["hostname"]
except KeyError:
pass
return None
async def _get_mac(self, web_get_system_info: dict | None = None) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["macaddr"]
except KeyError:
pass
try:
data = await self.web.get_network_info()
if data:
return data["macaddr"]
except KeyError:
pass
return None
async def _get_errors(
self, web_summary: dict | None = None
) -> list[MinerErrorData]:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
errors = []
if web_summary is not None:
try:
for item in web_summary["SUMMARY"][0]["status"]:
try:
if not item["status"] == "s":
errors.append(X19Error(error_message=item["msg"]))
except KeyError:
continue
except LookupError:
pass
return cast(list[MinerErrorData], errors)
async def _get_fault_light(
self, web_get_blink_status: dict | None = None
) -> bool | None:
if self.light:
return self.light
if web_get_blink_status is None:
try:
web_get_blink_status = await self.web.get_blink_status()
except APIError:
pass
if web_get_blink_status is not None:
try:
self.light = web_get_blink_status["blink"]
except KeyError:
pass
return self.light
async def _get_expected_hashrate(
self, rpc_stats: dict | None = None
) -> AlgoHashRateType | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
expected_rate = rpc_stats["STATS"][1].get("total_rateideal")
if expected_rate is None:
if (
hasattr(self, "sticker_hashrate")
and self.sticker_hashrate is not None
):
return self.sticker_hashrate.into(self.algo.unit.default) # type: ignore[attr-defined]
return None
try:
rate_unit = rpc_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "MH"
return self.algo.hashrate(
rate=float(expected_rate), unit=self.algo.unit.from_str(rate_unit)
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def set_static_ip(
self,
ip: str,
dns: str,
gateway: str,
subnet_mask: str = "255.255.255.0",
hostname: str | None = None,
):
if not hostname:
hostname = await self.get_hostname() or ""
await self.web.set_network_conf(
ip=ip,
dns=dns,
gateway=gateway,
subnet_mask=subnet_mask,
hostname=hostname,
protocol=2,
)
async def set_dhcp(self, hostname: str | None = None):
if not hostname:
hostname = await self.get_hostname() or ""
await self.web.set_network_conf(
ip="", dns="", gateway="", subnet_mask="", hostname=hostname, protocol=1
)
async def set_hostname(self, hostname: str):
cfg = await self.web.get_network_info()
dns = cfg["conf_dnsservers"]
gateway = cfg["conf_gateway"]
ip = cfg["conf_ipaddress"]
subnet_mask = cfg["conf_netmask"]
protocol = 1 if cfg["conf_nettype"] == "DHCP" else 2
await self.web.set_network_conf(
ip=ip,
dns=dns,
gateway=gateway,
subnet_mask=subnet_mask,
hostname=hostname,
protocol=protocol,
)
async def _is_mining(self, web_get_conf: dict | None = None) -> bool | None:
if web_get_conf is None:
try:
web_get_conf = await self.web.get_miner_conf()
except APIError:
pass
if web_get_conf is not None:
try:
if str(web_get_conf["bitmain-work-mode"]).isdigit():
return (
False if int(web_get_conf["bitmain-work-mode"]) == 1 else True
)
return False
except LookupError:
pass
return None
async def _get_uptime(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return int(rpc_stats["STATS"][1]["Elapsed"])
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/bitaxe.py | pyasic/miners/backends/bitaxe.py | from pyasic.miners.backends.espminer import ESPMiner
class BitAxe(ESPMiner):
"""Handler for BitAxe"""
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/cgminer.py | pyasic/miners/backends/cgminer.py | # ------------------------------------------------------------------------------
# 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.config import MinerConfig
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.miners.device.firmware import StockFirmware
from pyasic.rpc.cgminer import CGMinerRPCAPI
CGMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class CGMiner(StockFirmware):
"""Base handler for CGMiner based miners"""
_rpc_cls = CGMinerRPCAPI
rpc: CGMinerRPCAPI
data_locations = CGMINER_DATA_LOC
async def get_config(self) -> MinerConfig:
# get pool data
try:
pools = await self.rpc.pools()
except APIError:
return self.config or MinerConfig()
self.config = MinerConfig.from_api(pools)
return self.config
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.api_ver = rpc_version["VERSION"][0]["API"]
except LookupError:
pass
return self.api_ver
async def _get_fw_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
self.fw_ver = rpc_version["VERSION"][0]["CGMiner"]
except LookupError:
pass
return self.fw_ver
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["GHS 5s"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_uptime(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return int(rpc_stats["STATS"][1]["Elapsed"])
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/elphapex.py | pyasic/miners/backends/elphapex.py | # ------------------------------------------------------------------------------
# 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 import APIError, MinerConfig
from pyasic.data import Fan, HashBoard, X19Error
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
WebAPICommand,
)
from pyasic.miners.device.firmware import StockFirmware
from pyasic.web.elphapex import ElphapexWebAPI
ELPHAPEX_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[WebAPICommand("web_stats", "stats")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[WebAPICommand("web_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("web_stats", "stats")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_get_blink_status", "get_blink_status")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_get_miner_conf", "get_miner_conf")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[WebAPICommand("web_pools", "pools")],
),
}
)
class ElphapexMiner(StockFirmware):
"""Handler for Elphapex miners."""
_web_cls = ElphapexWebAPI
web: ElphapexWebAPI
data_locations = ELPHAPEX_DATA_LOC
async def get_config(self) -> MinerConfig:
data = await self.web.get_miner_conf()
if data:
self.config = MinerConfig.from_elphapex(data)
if self.config is None:
self.config = MinerConfig()
return self.config
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
await self.web.set_miner_conf(config.as_elphapex(user_suffix=user_suffix))
async def fault_light_on(self) -> bool:
data = await self.web.blink(blink=True)
if data:
if data.get("code") == "B000":
self.light = True
return self.light if self.light is not None else False
async def fault_light_off(self) -> bool:
data = await self.web.blink(blink=False)
if data:
if data.get("code") == "B100":
self.light = False
return self.light if self.light is not None else False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
return True
return False
async def _get_api_ver(self, web_summary: dict | None = None) -> str | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
self.api_ver = web_summary["STATUS"]["api_version"]
except LookupError:
pass
return self.api_ver
async def _get_fw_ver(self, web_get_system_info: dict | None = None) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
self.fw_ver = (
web_get_system_info["system_filesystem_version"]
.upper()
.split("V")[-1]
)
except LookupError:
pass
return self.fw_ver
async def _get_hostname(
self, web_get_system_info: dict | None = None
) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["hostname"]
except KeyError:
pass
return None
async def _get_mac(self, web_get_system_info: dict | None = None) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["macaddr"]
except KeyError:
pass
try:
data = await self.web.get_network_info()
if data:
return data["macaddr"]
except KeyError:
pass
return None
async def _get_errors( # type: ignore[override]
self, web_summary: dict | None = None
) -> list[X19Error]:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
errors = []
if web_summary is not None:
try:
for item in web_summary["SUMMARY"][0]["status"]:
try:
if not item["status"] == "s":
errors.append(X19Error(error_message=item["msg"]))
except KeyError:
continue
except LookupError:
pass
return errors
async def _get_hashboards(self, web_stats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=idx, expected_chips=self.expected_chips)
for idx in range(self.expected_hashboards)
]
if web_stats is None:
try:
web_stats = await self.web.stats()
except APIError:
return hashboards
if web_stats is not None:
try:
for board in web_stats["STATS"][0]["chain"]:
hashboards[board["index"]].hashrate = self.algo.hashrate(
rate=board["rate_real"],
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[board["index"]].chips = board["asic_num"]
board_temp_data = list(
filter(lambda x: not x == 0, board["temp_pcb"])
)
if not len(board_temp_data) == 0:
hashboards[board["index"]].temp = sum(board_temp_data) / len(
board_temp_data
)
chip_temp_data = list(
filter(lambda x: not x == "", board["temp_chip"])
)
hashboards[board["index"]].chip_temp = sum(
[int(i) / 1000 for i in chip_temp_data]
) / len(chip_temp_data)
hashboards[board["index"]].serial_number = board["sn"]
hashboards[board["index"]].missing = False
except LookupError:
pass
return hashboards
async def _get_fault_light(
self, web_get_blink_status: dict | None = None
) -> bool | None:
if self.light:
return self.light
if web_get_blink_status is None:
try:
web_get_blink_status = await self.web.get_blink_status()
except APIError:
pass
if web_get_blink_status is not None:
try:
self.light = web_get_blink_status["blink"]
except KeyError:
pass
return self.light
async def _get_expected_hashrate(
self, web_stats: dict | None = None
) -> AlgoHashRateType | None:
if web_stats is None:
try:
web_stats = await self.web.stats()
except APIError:
pass
if web_stats is not None:
try:
expected_rate = web_stats["STATS"][1]["total_rateideal"]
try:
rate_unit = web_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "MH"
return self.algo.hashrate(
rate=float(expected_rate), unit=self.algo.unit.from_str(rate_unit)
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _is_mining(self, web_get_miner_conf: dict | None = None) -> bool | None:
if web_get_miner_conf is None:
try:
web_get_miner_conf = await self.web.get_miner_conf()
except APIError:
pass
if web_get_miner_conf is not None:
try:
if str(web_get_miner_conf["fc-work-mode"]).isdigit():
return (
False if int(web_get_miner_conf["fc-work-mode"]) == 1 else True
)
return False
except LookupError:
pass
return None
async def _get_uptime(self, web_summary: dict | None = None) -> int | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
return int(web_summary["SUMMARY"][1]["elapsed"])
except LookupError:
pass
return None
async def _get_fans(self, web_stats: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_stats is None:
try:
web_stats = await self.web.stats()
except APIError:
pass
fans = [Fan() for _ in range(self.expected_fans)]
if web_stats is not None:
for fan_n in range(self.expected_fans):
try:
fans[fan_n].speed = int(web_stats["STATS"][0]["fan"][fan_n])
except LookupError:
pass
return fans
async def _get_pools(self, web_pools: dict | None = None) -> list[PoolMetrics]:
if web_pools is None:
try:
web_pools = await self.web.pools()
except APIError:
return []
if web_pools is None:
return []
active_pool_index = None
highest_priority = float("inf")
for pool_info in web_pools["POOLS"]:
if (
pool_info.get("status") == "Alive"
and pool_info.get("priority", float("inf")) < highest_priority
):
highest_priority = pool_info["priority"]
active_pool_index = pool_info["index"]
pools_data = []
try:
for pool_info in web_pools["POOLS"]:
url = pool_info.get("url")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("accepted"),
rejected=pool_info.get("rejected"),
get_failures=pool_info.get("stale"),
remote_failures=pool_info.get("discarded"),
active=pool_info.get("index") == active_pool_index,
alive=pool_info.get("status") == "Alive",
url=pool_url,
user=pool_info.get("user"),
index=pool_info.get("index"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/avalonminer.py | pyasic/miners/backends/avalonminer.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import copy
import re
import time
from pyasic.data import Fan, HashBoard
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.backends.cgminer import CGMiner
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.rpc.avalonminer import AvalonMinerRPCAPI
AVALON_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.ENVIRONMENT_TEMP): DataFunction(
"_get_env_temp",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[RPCAPICommand("rpc_estats", "estats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class AvalonMiner(CGMiner):
"""Handler for Avalon Miners"""
_rpc_cls = AvalonMinerRPCAPI
rpc: AvalonMinerRPCAPI
data_locations = AVALON_DATA_LOC
async def fault_light_on(self) -> bool:
try:
data = await self.rpc.ascset(0, "led", "1-1")
except APIError:
return False
if data["STATUS"][0]["Msg"] == "ASC 0 set OK":
return True
return False
async def fault_light_off(self) -> bool:
try:
data = await self.rpc.ascset(0, "led", "1-0")
except APIError:
return False
if data["STATUS"][0]["Msg"] == "ASC 0 set OK":
return True
return False
async def set_power_limit(self, wattage: int) -> bool:
try:
if wattage < 3:
limit = wattage
elif wattage > 100:
limit = 2
elif wattage > 80:
limit = 1
else:
limit = 0
data = await self.rpc.ascset(0, "worklevel,set", limit)
except APIError:
return False
if data["STATUS"][0]["Msg"] == "ASC 0 set OK":
return True
return False
async def reboot(self) -> bool:
try:
data = await self.rpc.restart()
except APIError:
return False
try:
if data["STATUS"] == "RESTART":
return True
except KeyError:
return False
return False
async def stop_mining(self) -> bool:
try:
# Shut off 5 seconds from now
timestamp = int(time.time()) + 5
data = await self.rpc.ascset(0, "softoff", f"1:{timestamp}")
except APIError:
return False
if "success" in data["STATUS"][0]["Msg"]:
return True
return False
async def resume_mining(self) -> bool:
try:
# Shut off 5 seconds from now
timestamp = int(time.time()) + 5
data = await self.rpc.ascset(0, "softon", f"1:{timestamp}")
except APIError:
return False
if "success" in data["STATUS"][0]["Msg"]:
return True
return False
@staticmethod
def parse_estats(data):
# Deep copy to preserve original structure
new_data = copy.deepcopy(data)
def convert_value(val, key):
val = val.strip()
if key == "SYSTEMSTATU":
return val
if " " in val:
parts = val.split()
result = []
for part in parts:
if part.isdigit():
result.append(int(part))
else:
try:
result.append(float(part))
except ValueError:
result.append(part)
return result
else:
if val.isdigit():
return int(val)
try:
return float(val)
except ValueError:
return val
def parse_info_block(info_str):
pattern = re.compile(r"(\w+)\[([^\]]*)\]")
return {
key: convert_value(val, key) for key, val in pattern.findall(info_str)
}
for stat in new_data.get("STATS", []):
keys_to_replace = {}
for key, value in stat.items():
if "MM" in key:
# Normalize key by removing suffix after colon
norm_key = key.split(":")[0]
mm_data = value
if not isinstance(mm_data, str):
continue
if mm_data.startswith("'STATS':"):
mm_data = mm_data[len("'STATS':") :]
keys_to_replace[norm_key] = parse_info_block(mm_data)
elif key == "HBinfo":
match = re.search(r"'(\w+)':\{(.+)\}", value)
if match:
hb_key = match.group(1)
hb_data = match.group(2)
keys_to_replace[key] = {hb_key: parse_info_block(hb_data)}
# Remove old keys and insert parsed versions
for k in list(stat.keys()):
if "MM" in k or k == "HBinfo":
del stat[k]
stat.update(keys_to_replace)
return new_data
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
base_mac = rpc_version["VERSION"][0]["MAC"]
base_mac = base_mac.upper()
mac = ":".join(
[base_mac[i : (i + 2)] for i in range(0, len(base_mac), 2)]
)
return mac
except (KeyError, ValueError):
pass
return None
async def _get_hashrate(
self, rpc_devs: dict | None = None
) -> AlgoHashRateType | None:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
return None
if rpc_devs is not None:
try:
return self.algo.hashrate(
rate=float(rpc_devs["DEVS"][0]["MHS 1m"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (KeyError, IndexError, ValueError, TypeError):
pass
return None
async def _get_hashboards(self, rpc_estats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
pass
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)
except (IndexError, KeyError, ValueError, TypeError):
return hashboards
for board in range(self.expected_hashboards):
try:
board_hr = parsed_estats["STATS"][0]["MM ID0"]["MGHS"]
if isinstance(board_hr, list):
hashboards[board].hashrate = self.algo.hashrate(
rate=float(board_hr[board]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
else:
hashboards[board].hashrate = self.algo.hashrate(
rate=float(board_hr),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except LookupError:
pass
try:
hashboards[board].chip_temp = int(
parsed_estats["STATS"][0]["MM ID0"]["MTmax"][board]
)
except (LookupError, TypeError):
try:
hashboards[board].chip_temp = int(
parsed_estats["STATS"][0]["MM ID0"].get(
"Tmax", parsed_estats["STATS"][0]["MM ID0"]["TMax"]
)
)
except LookupError:
pass
try:
hashboards[board].temp = int(
parsed_estats["STATS"][0]["MM ID0"]["MTmax"][board]
)
except (LookupError, TypeError):
try:
hashboards[board].temp = int(
parsed_estats["STATS"][0]["MM ID0"].get(
"Tavg", parsed_estats["STATS"][0]["MM ID0"]["TAvg"]
)
)
except LookupError:
pass
try:
hashboards[board].inlet_temp = int(
parsed_estats["STATS"][0]["MM ID0"]["MTavg"][board]
)
except (LookupError, TypeError):
try:
hashboards[board].inlet_temp = int(
parsed_estats["STATS"][0]["MM ID0"]["HBITemp"]
)
except LookupError:
pass
try:
hashboards[board].outlet_temp = int(
parsed_estats["STATS"][0]["MM ID0"]["MTmax"][board]
)
except (LookupError, TypeError):
try:
hashboards[board].outlet_temp = int(
parsed_estats["STATS"][0]["MM ID0"]["HBOTemp"]
)
except LookupError:
pass
try:
chip_data = parsed_estats["STATS"][0]["MM ID0"][f"PVT_T{board}"]
hashboards[board].missing = False
if chip_data:
hashboards[board].chips = len(
[item for item in chip_data if not item == "0"]
)
except (LookupError, TypeError):
try:
chip_data = parsed_estats["STATS"][0]["HBinfo"][f"HB{board}"][
f"PVT_T{board}"
]
hashboards[board].missing = False
if chip_data:
hashboards[board].chips = len(
[item for item in chip_data if not item == "0"]
)
except LookupError:
pass
return hashboards
async def _get_expected_hashrate(
self, rpc_estats: dict | None = None
) -> AlgoHashRateType | None:
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
return None
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)["STATS"][0]["MM ID0"]
return self.algo.hashrate(
rate=float(parsed_estats["GHSmm"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (IndexError, KeyError, ValueError, TypeError):
pass
return None
async def _get_env_temp(self, rpc_estats: dict | None = None) -> float | None:
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
pass
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)["STATS"][0]["MM ID0"]
return float(parsed_estats["Temp"])
except (IndexError, KeyError, ValueError, TypeError):
pass
return None
async def _get_wattage_limit(self, rpc_estats: dict | None = None) -> int | None:
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
return None
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)["STATS"][0]["MM ID0"]
return int(parsed_estats["MPO"])
except (IndexError, KeyError, ValueError, TypeError):
pass
return None
async def _get_wattage(self, rpc_estats: dict | None = None) -> int | None:
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
pass
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)["STATS"][0]["MM ID0"]
return int(parsed_estats["WALLPOWER"])
except (IndexError, KeyError, ValueError, TypeError):
pass
return None
async def _get_fans(self, rpc_estats: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
pass
fans_data = [Fan() for _ in range(self.expected_fans)]
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)["STATS"][0]["MM ID0"]
except LookupError:
return fans_data
for fan in range(self.expected_fans):
try:
fans_data[fan].speed = int(parsed_estats[f"Fan{fan + 1}"])
except (IndexError, KeyError, ValueError, TypeError):
pass
return fans_data
async def _get_fault_light(self, rpc_estats: dict | None = None) -> bool | None:
if self.light:
return self.light
if rpc_estats is None:
try:
rpc_estats = await self.rpc.estats()
except APIError:
pass
if rpc_estats is not None:
try:
parsed_estats = self.parse_estats(rpc_estats)["STATS"][0]["MM ID0"]
led = int(parsed_estats["Led"])
return True if led == 1 else False
except (IndexError, KeyError, ValueError, TypeError):
pass
return False
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/mskminer.py | pyasic/miners/backends/mskminer.py | from pyasic import APIError
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.miners.backends import BMMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.web.mskminer import MSKMinerWebAPI
MSKMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_info_v1", "info_v1")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class MSKMiner(BMMiner):
"""Handler for MSKMiner"""
data_locations = MSKMINER_DATA_LOC
web: MSKMinerWebAPI
_web_cls = MSKMinerWebAPI
async def _get_hashrate(
self, rpc_stats: dict | None = None
) -> AlgoHashRateType | None:
# get hr from API
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return self.algo.hashrate(
rate=float(rpc_stats["STATS"][0]["total_rate"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_wattage(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return rpc_stats["STATS"][0]["total_power"]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_mac(self, web_info_v1: dict | None = None) -> str | None:
if web_info_v1 is None:
try:
web_info_v1 = await self.web.info_v1()
except APIError:
pass
if web_info_v1 is not None:
try:
return web_info_v1["network_info"]["result"]["macaddr"].upper()
except (LookupError, ValueError, TypeError):
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/iceriver.py | pyasic/miners/backends/iceriver.py | from pyasic import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType, MinerAlgo
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, WebAPICommand
from pyasic.miners.device.firmware import StockFirmware
from pyasic.web.iceriver import IceRiverWebAPI
ICERIVER_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_userpanel", "userpanel")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[WebAPICommand("web_userpanel", "userpanel")],
),
}
)
class IceRiver(StockFirmware):
"""Handler for IceRiver miners"""
_web_cls = IceRiverWebAPI
web: IceRiverWebAPI
data_locations = ICERIVER_DATA_LOC
async def fault_light_off(self) -> bool:
try:
await self.web.locate(False)
except APIError:
return False
return True
async def fault_light_on(self) -> bool:
try:
await self.web.locate(True)
except APIError:
return False
return True
async def get_config(self) -> MinerConfig:
web_userpanel = await self.web.userpanel()
return MinerConfig.from_iceriver(web_userpanel)
async def _get_fans(self, web_userpanel: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
return []
if web_userpanel is not None:
try:
return [
Fan(speed=spd) for spd in web_userpanel["userpanel"]["data"]["fans"]
]
except (LookupError, ValueError, TypeError):
pass
return []
async def _get_mac(self, web_userpanel: dict | None = None) -> str | None:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
return None
if web_userpanel is not None:
try:
return (
web_userpanel["userpanel"]["data"]["mac"].upper().replace("-", ":")
)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_hostname(self, web_userpanel: dict | None = None) -> str | None:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
return None
if web_userpanel is not None:
try:
return web_userpanel["userpanel"]["data"]["host"]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_hashrate(
self, web_userpanel: dict | None = None
) -> AlgoHashRateType | None:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
return None
if web_userpanel is not None:
try:
base_unit = web_userpanel["userpanel"]["data"]["unit"]
return self.algo.hashrate(
rate=float(
web_userpanel["userpanel"]["data"]["rtpow"].replace(
base_unit, ""
)
),
unit=MinerAlgo.SHA256.unit.from_str(base_unit + "H"),
).into(MinerAlgo.SHA256.unit.default)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_fault_light(self, web_userpanel: dict | None = None) -> bool:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
pass
if web_userpanel is not None:
try:
return web_userpanel["userpanel"]["data"]["locate"]
except (LookupError, ValueError, TypeError):
pass
return False
async def _is_mining(self, web_userpanel: dict | None = None) -> bool | None:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
return False
if web_userpanel is not None:
try:
return web_userpanel["userpanel"]["data"]["powstate"]
except (LookupError, ValueError, TypeError):
pass
return False
async def _get_hashboards(
self, web_userpanel: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
pass
hb_list = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if web_userpanel is not None:
try:
for board in web_userpanel["userpanel"]["data"]["boards"]:
idx = int(board["no"] - 1)
hb_list[idx].chip_temp = round(board["outtmp"])
hb_list[idx].temp = round(board["intmp"])
hb_list[idx].hashrate = self.algo.hashrate(
rate=float(board["rtpow"].replace("G", "")),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hb_list[idx].chips = int(board["chipnum"])
hb_list[idx].missing = False
except LookupError:
pass
return hb_list
async def _get_uptime(self, web_userpanel: dict | None = None) -> int | None:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
pass
if web_userpanel is not None:
try:
runtime = web_userpanel["userpanel"]["data"]["runtime"]
days, hours, minutes, seconds = runtime.split(":")
return (
(int(days) * 24 * 60 * 60)
+ (int(hours) * 60 * 60)
+ (int(minutes) * 60)
+ int(seconds)
)
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_pools(self, web_userpanel: dict | None = None) -> list[PoolMetrics]:
if web_userpanel is None:
try:
web_userpanel = await self.web.userpanel()
except APIError:
pass
pools_data = []
if web_userpanel is not None:
try:
pools = web_userpanel["userpanel"]["data"]["pools"]
for pool_info in pools:
pool_num = pool_info.get("no")
if pool_num is not None:
pool_num = int(pool_num)
if pool_info["addr"] == "":
continue
url = pool_info.get("addr")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("accepted"),
rejected=pool_info.get("rejected"),
active=pool_info.get("connect"),
alive=int(pool_info.get("state", 0)) == 1,
url=pool_url,
user=pool_info.get("user"),
index=pool_num,
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/espminer.py | pyasic/miners/backends/espminer.py | from pyasic import APIError, MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.device.firmware import MinerFirmware
from pyasic.miners.base import BaseMiner
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, WebAPICommand
from pyasic.web.espminer import ESPMinerWebAPI
ESPMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[WebAPICommand("web_system_info", "system/info")],
),
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_system_info", "system/info")],
),
}
)
class ESPMiner(BaseMiner):
"""Handler for ESPMiner"""
web: ESPMinerWebAPI
_web_cls = ESPMinerWebAPI
firmware = MinerFirmware.STOCK
data_locations = ESPMINER_DATA_LOC
async def reboot(self) -> bool:
await self.web.restart()
return True
async def get_config(self) -> MinerConfig:
web_system_info = await self.web.system_info()
return MinerConfig.from_espminer(web_system_info)
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
await self.web.update_settings(**config.as_espminer())
async def _get_wattage(self, web_system_info: dict | None = None) -> int | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return round(web_system_info["power"])
except KeyError:
pass
return None
async def _get_hashrate(
self, web_system_info: dict | None = None
) -> AlgoHashRateType | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return self.algo.hashrate(
rate=float(web_system_info["hashRate"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except KeyError:
pass
return None
async def _get_expected_hashrate(
self, web_system_info: dict | None = None
) -> AlgoHashRateType | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
small_core_count = web_system_info.get("smallCoreCount")
asic_count = web_system_info.get("asicCount")
frequency = web_system_info.get("frequency")
if asic_count is None:
try:
asic_info = await self.web.asic_info()
asic_count = asic_info.get("asicCount")
except APIError:
pass
if (
small_core_count is not None
and asic_count is not None
and frequency is not None
):
expected_hashrate = small_core_count * asic_count * frequency
return self.algo.hashrate(
rate=float(expected_hashrate),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
except KeyError:
pass
return None
async def _get_uptime(self, web_system_info: dict | None = None) -> int | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return web_system_info["uptimeSeconds"]
except KeyError:
pass
return None
async def _get_hashboards(
self, web_system_info: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return [
HashBoard(
hashrate=self.algo.hashrate(
rate=float(web_system_info["hashRate"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
),
chip_temp=web_system_info.get("temp"),
temp=web_system_info.get("vrTemp"),
chips=web_system_info.get("asicCount", 1),
expected_chips=self.expected_chips,
missing=False,
active=True,
voltage=web_system_info.get("voltage"),
)
]
except KeyError:
pass
return []
async def _get_fans(self, web_system_info: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return [Fan(speed=web_system_info["fanrpm"])]
except KeyError:
pass
return []
async def _get_hostname(self, web_system_info: dict | None = None) -> str | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return web_system_info["hostname"]
except KeyError:
pass
return None
async def _get_api_ver(self, web_system_info: dict | None = None) -> str | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return web_system_info["version"]
except KeyError:
pass
return None
async def _get_fw_ver(self, web_system_info: dict | None = None) -> str | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return web_system_info["version"]
except KeyError:
pass
return None
async def _get_mac(self, web_system_info: dict | None = None) -> str | None:
if web_system_info is None:
try:
web_system_info = await self.web.system_info()
except APIError:
pass
if web_system_info is not None:
try:
return web_system_info["macAddr"].upper()
except KeyError:
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/unknown.py | pyasic/miners/backends/unknown.py | # 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.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData
from pyasic.data.pools import PoolMetrics
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.miners.base import BaseMiner
from pyasic.rpc.unknown import UnknownRPCAPI
class UnknownMiner(BaseMiner):
def __init__(
self,
ip: str,
*args,
**kwargs, # noqa - ignore *args and **kwargs for signature consistency
) -> None:
super().__init__(ip)
self.ip = ip
self.rpc = UnknownRPCAPI(ip)
def __repr__(self) -> str:
return f"Unknown: {str(self.ip)}"
async def check_light(self) -> bool:
if not self.light:
self.light = False
return self.light
async def fault_light_off(self) -> bool:
return False
async def fault_light_on(self) -> bool:
return False
async def get_config(self) -> MinerConfig:
return MinerConfig()
async def reboot(self) -> bool:
return False
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
) -> None:
return None
async def set_power_limit(self, wattage: int) -> bool:
return False
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(self) -> str | None:
return None
async def _get_serial_number(self) -> str | None:
return None
async def _get_version(self) -> tuple[str | None, str | None]:
return None, None
async def _get_hostname(self) -> str | None:
return None
async def _get_hashrate(self) -> AlgoHashRateType | None:
return None
async def _get_hashboards(self) -> list[HashBoard]:
return []
async def _get_env_temp(self) -> float | None:
return None
async def _get_wattage(self) -> int | None:
return None
async def _get_wattage_limit(self) -> int | None:
return None
async def _get_fans(self) -> list[Fan]:
return []
async def _get_fan_psu(self) -> int | None:
return None
async def _get_api_ver(self) -> str | None:
return None
async def _get_fw_ver(self) -> str | None:
return None
async def _get_errors(self) -> list[MinerErrorData]:
return []
async def _get_fault_light(self) -> bool:
return False
async def _get_expected_hashrate(self) -> AlgoHashRateType | None:
return None
async def _is_mining(self, *args, **kwargs) -> bool | None:
return None
async def _get_uptime(self, *args, **kwargs) -> int | None:
return None
async def _get_pools(self) -> list[PoolMetrics]:
return []
async def _get_voltage(self) -> float | None:
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/__init__.py | pyasic/miners/backends/__init__.py | # ------------------------------------------------------------------------------
# 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 .antminer import AntminerModern, AntminerOld
from .auradine import Auradine
from .avalonminer import AvalonMiner
from .bfgminer import BFGMiner
from .bitaxe import BitAxe
from .bmminer import BMMiner
from .braiins_os import BOSer, BOSMiner
from .btminer import BTMiner, BTMinerV2, BTMinerV3
from .cgminer import CGMiner
from .elphapex import ElphapexMiner
from .epic import ePIC
from .goldshell import GoldshellMiner
from .hammer import BlackMiner
from .hiveon import HiveonModern, HiveonOld
from .iceriver import IceRiver
from .innosilicon import Innosilicon
from .luckyminer import LuckyMiner
from .luxminer import LUXMiner
from .marathon import MaraMiner
from .mskminer import MSKMiner
from .unknown import UnknownMiner
from .vnish import VNish
from .whatsminer import M2X, M3X, M5X, M6X, M7X
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/auradine.py | pyasic/miners/backends/auradine.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import logging
from enum import Enum
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.firmware import StockFirmware
from pyasic.rpc.gcminer import GCMinerRPCAPI
from pyasic.web.auradine import AuradineWebAPI
AURADINE_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_ipreport", "ipreport")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_ipreport", "ipreport")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_ipreport", "ipreport")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_devs", "devs"),
WebAPICommand("web_ipreport", "ipreport"),
],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("web_psu", "psu")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[WebAPICommand("web_mode", "mode"), WebAPICommand("web_psu", "psu")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("web_fan", "fan")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_led", "led")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_mode", "mode")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_summary", "summary")],
),
}
)
class AuradineLEDColors(Enum):
OFF = 0
GREEN = 1
RED = 2
YELLOW = 3
GREEN_FLASHING = 4
RED_FLASHING = 5
YELLOW_FLASHING = 6
def __int__(self):
return self.value
class AuradineLEDCodes(Enum):
NO_POWER = 1
NORMAL = 2
LOCATE_MINER = 3
TEMPERATURE = 4
POOL_CONFIG = 5
NETWORK = 6
CONTROL_BOARD = 7
HASH_RATE_LOW = 8
CUSTOM1 = 101
CUSTOM2 = 102
def __int__(self):
return self.value
class Auradine(StockFirmware):
"""Base handler for Auradine miners"""
_rpc_cls = GCMinerRPCAPI
rpc: GCMinerRPCAPI
_web_cls = AuradineWebAPI
web: AuradineWebAPI
data_locations = AURADINE_DATA_LOC
supports_shutdown = True
supports_power_modes = True
supports_autotuning = True
async def fault_light_on(self) -> bool:
try:
await self.web.set_led(code=int(AuradineLEDCodes.LOCATE_MINER))
return True
except APIError:
return False
async def fault_light_off(self) -> bool:
try:
await self.web.set_led(code=int(AuradineLEDCodes.NORMAL))
return True
except APIError:
return False
async def reboot(self) -> bool:
try:
await self.web.reboot()
except APIError:
return False
return True
async def restart_backend(self) -> bool:
try:
await self.web.restart_gcminer()
except APIError:
return False
return True
async def stop_mining(self) -> bool:
try:
await self.web.set_mode(sleep="on")
except APIError:
return False
return True
async def resume_mining(self) -> bool:
try:
await self.web.set_mode(sleep="off")
except APIError:
return False
return True
async def set_power_limit(self, wattage: int) -> bool:
try:
await self.web.set_mode(mode="custom", tune="power", power=wattage)
except APIError:
return False
return True
async def get_config(self) -> MinerConfig:
try:
web_conf = await self.web.multicommand("pools", "mode", "fan")
return MinerConfig.from_auradine(web_conf=web_conf)
except APIError as e:
logging.warning(e)
except LookupError:
pass
return MinerConfig()
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
conf = config.as_auradine(user_suffix=user_suffix)
for key in conf.keys():
await self.web.send_command(command=key, **conf[key])
async def upgrade_firmware(
self,
*,
url: str | None = None,
version: str | None = "latest",
keep_settings: bool = False,
**kwargs,
) -> bool:
"""
Upgrade the firmware of the Auradine device.
Args:
url (str): The URL to download the firmware from.
version (str): The version of the firmware to upgrade to.
keep_settings (bool): Whether to keep the current settings during the upgrade.
Returns:
bool: True if the firmware upgrade was successful, False otherwise.
"""
try:
logging.info("Starting firmware upgrade process.")
if not url and not version:
raise ValueError(
"Either URL or version must be provided for firmware upgrade."
)
if url:
result = await self.web.firmware_upgrade(url=url)
elif version:
result = await self.web.firmware_upgrade(version=version)
else:
raise ValueError(
"Either URL or version must be provided for firmware upgrade."
)
if result.get("STATUS", [{}])[0].get("STATUS") == "S":
logging.info("Firmware upgrade process completed successfully.")
return True
else:
logging.error(
f"Firmware upgrade failed: {result.get('error', 'Unknown error')}"
)
return False
except Exception as e:
logging.error(
f"An error occurred during the firmware upgrade process: {str(e)}"
)
return False
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(self, web_ipreport: dict | None = None) -> str | None:
if web_ipreport is None:
try:
web_ipreport = await self.web.ipreport()
except APIError:
pass
if web_ipreport is not None:
try:
return web_ipreport["IPReport"][0]["mac"].upper()
except (LookupError, AttributeError):
pass
return None
async def _get_fw_ver(self, web_ipreport: dict | None = None) -> str | None:
if web_ipreport is None:
try:
web_ipreport = await self.web.ipreport()
except APIError:
pass
if web_ipreport is not None:
try:
return web_ipreport["IPReport"][0]["version"]
except LookupError:
pass
return None
async def _get_hostname(self, web_ipreport: dict | None = None) -> str | None:
if web_ipreport is None:
try:
web_ipreport = await self.web.ipreport()
except APIError:
pass
if web_ipreport is not None:
try:
return web_ipreport["IPReport"][0]["hostname"]
except LookupError:
pass
return None
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["MHS 5s"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_hashboards(
self, rpc_devs: dict | None = None, web_ipreport: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
if web_ipreport is None:
try:
web_ipreport = await self.web.ipreport()
except APIError:
pass
if rpc_devs is not None:
try:
for board in rpc_devs["DEVS"]:
b_id = board["ID"] - 1
hashboards[b_id].hashrate = self.algo.hashrate(
rate=float(board["MHS 5s"]),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[b_id].temp = round(float(board["Temperature"]))
hashboards[b_id].missing = False
except LookupError:
pass
if web_ipreport is not None:
try:
for board, sn in enumerate(web_ipreport["IPReport"][0]["HBSerialNo"]):
hashboards[board].serial_number = sn
hashboards[board].missing = False
except LookupError:
pass
return hashboards
async def _get_wattage(self, web_psu: dict | None = None) -> int | None:
if web_psu is None:
try:
web_psu = await self.web.get_psu()
except APIError:
pass
if web_psu is not None:
try:
return int(float(web_psu["PSU"][0]["PowerIn"].replace("W", "")))
except (LookupError, TypeError, ValueError):
pass
return None
async def _get_wattage_limit(
self, web_mode: dict | None = None, web_psu: dict | None = None
) -> int | None:
if web_mode is None:
try:
web_mode = await self.web.get_mode()
except APIError:
pass
if web_mode is not None:
try:
return web_mode["Mode"][0]["Power"]
except (LookupError, TypeError, ValueError):
pass
if web_psu is None:
try:
web_psu = await self.web.get_psu()
except APIError:
pass
if web_psu is not None:
try:
return int(float(web_psu["PSU"][0]["PoutMax"].replace("W", "")))
except (LookupError, TypeError, ValueError):
pass
return None
async def _get_fans(self, web_fan: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_fan is None:
try:
web_fan = await self.web.get_fan()
except APIError:
pass
fans = []
if web_fan is not None:
try:
for fan in web_fan["Fan"]:
fans.append(Fan(speed=round(fan["Speed"])))
except LookupError:
pass
return fans
async def _get_fault_light(self, web_led: dict | None = None) -> bool | None:
if web_led is None:
try:
web_led = await self.web.get_led()
except APIError:
pass
if web_led is not None:
try:
return web_led["LED"][0]["Code"] == int(AuradineLEDCodes.LOCATE_MINER)
except LookupError:
pass
return None
async def _is_mining(self, web_mode: dict | None = None) -> bool | None:
if web_mode is None:
try:
web_mode = await self.web.get_mode()
except APIError:
pass
if web_mode is not None:
try:
return web_mode["Mode"][0]["Sleep"] == "off"
except (LookupError, TypeError, ValueError):
pass
return None
async def _get_uptime(self, rpc_summary: dict | None = None) -> int | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
try:
return rpc_summary["SUMMARY"][0]["Elapsed"]
except LookupError:
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/vnish.py | pyasic/miners/backends/vnish.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import logging
from pyasic import MinerConfig
from pyasic.config.mining import MiningModePreset
from pyasic.data.error_codes import VnishError
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.backends.bmminer import BMMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.firmware import VNishFirmware
from pyasic.web.vnish import VNishWebAPI
VNISH_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[WebAPICommand("web_settings", "settings")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[WebAPICommand("web_summary", "summary")],
),
}
)
class VNish(VNishFirmware, BMMiner):
"""Handler for VNish miners"""
_web_cls = VNishWebAPI
web: VNishWebAPI
supports_shutdown = True
supports_presets = True
supports_autotuning = True
data_locations = VNISH_DATA_LOC
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
await self.web.post_settings(
miner_settings=config.as_vnish(user_suffix=user_suffix)
)
async def restart_backend(self) -> bool:
data = await self.web.restart_vnish()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def stop_mining(self) -> bool:
data = await self.web.stop_mining()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def resume_mining(self) -> bool:
data = await self.web.resume_mining()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def _get_mac(self, web_summary: dict | None = None) -> str | None:
if web_summary is not None:
try:
mac = web_summary["system"]["network_status"]["mac"]
return mac
except KeyError:
pass
web_info = await self.web.info()
if web_info is not None:
try:
mac = web_info["system"]["network_status"]["mac"]
return mac
except KeyError:
pass
return None
async def fault_light_off(self) -> bool:
result = await self.web.find_miner()
if result is not None:
if result.get("on") is False:
return True
else:
await self.web.find_miner()
return False
async def fault_light_on(self) -> bool:
result = await self.web.find_miner()
if result is not None:
if result.get("on") is True:
return True
else:
await self.web.find_miner()
return False
async def _get_hostname(self, web_summary: dict | None = None) -> str | None:
if web_summary is None:
web_info = await self.web.info()
if web_info is not None:
try:
hostname = web_info["system"]["network_status"]["hostname"]
return hostname
except KeyError:
pass
else:
try:
hostname = web_summary["system"]["network_status"]["hostname"]
return hostname
except KeyError:
pass
return None
async def _get_wattage(self, web_summary: dict | None = None) -> int | None:
if web_summary is None:
web_summary = await self.web.summary()
if web_summary is not None:
try:
wattage = web_summary["miner"]["power_usage"]
wattage = round(wattage)
return wattage
except KeyError:
pass
return None
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
# get hr from API
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
return None
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["GHS 5s"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_wattage_limit(self, web_settings: dict | None = None) -> int | None:
if web_settings is None:
web_settings = await self.web.summary()
if web_settings is not None:
try:
wattage_limit = web_settings["miner"]["overclock"]["preset"]
if wattage_limit == "disabled":
return None
return int(wattage_limit)
except (KeyError, TypeError):
pass
return None
async def _get_fw_ver(self, web_summary: dict | None = None) -> str | None:
if web_summary is None:
web_summary = await self.web.summary()
fw_ver = None
if web_summary is not None:
try:
fw_ver = web_summary["miner"]["miner_type"]
fw_ver = fw_ver.split("(Vnish ")[1].replace(")", "")
return fw_ver
except LookupError:
return fw_ver
async def _is_mining(self, web_summary: dict | None = None) -> bool | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
return None
if web_summary is not None:
try:
is_mining = web_summary["miner"]["miner_status"]["miner_state"] not in [
"stopped",
"shutting-down",
"failure",
]
return is_mining
except LookupError:
pass
return None
async def _get_errors( # type: ignore[override]
self, web_summary: dict | None = None
) -> list[VnishError]:
errors: list[VnishError] = []
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
return errors
if web_summary is not None:
chains = web_summary.get("miner", {}).get("chains", [])
for chain in chains:
state = chain.get("status", {}).get("state")
description = chain.get("status", {}).get("description", "")
if state == "failure":
errors.append(VnishError(error_message=description))
return errors
async def get_config(self) -> MinerConfig:
try:
web_settings = await self.web.settings()
web_presets_dict = await self.web.autotune_presets()
web_presets = (
web_presets_dict.get("presets", []) if web_presets_dict else []
)
web_perf_summary = (await self.web.perf_summary()) or {}
except APIError:
return self.config or MinerConfig()
self.config = MinerConfig.from_vnish(
web_settings, web_presets, web_perf_summary
)
return self.config
async def set_power_limit(self, wattage: int) -> bool:
config = await self.get_config()
# Check if mining mode is preset mode and has available presets
if not isinstance(config.mining_mode, MiningModePreset):
return False
valid_presets = [
preset.power
for preset in config.mining_mode.available_presets
if (preset.tuned and preset.power is not None and preset.power <= wattage)
]
if not valid_presets:
return False
new_wattage = max(valid_presets)
# Set power to highest preset <= wattage
try:
await self.web.set_power_limit(new_wattage)
updated_settings = await self.web.settings()
except APIError:
raise
except Exception as e:
logging.warning(f"{self} - Failed to set power limit: {e}")
return False
if int(updated_settings["miner"]["overclock"]["preset"]) == new_wattage:
return True
else:
return False
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/marathon.py | pyasic/miners/backends/marathon.py | from pyasic import MinerConfig
from pyasic.config import MiningModeConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, WebAPICommand
from pyasic.miners.device.firmware import MaraFirmware
from pyasic.misc import merge_dicts
from pyasic.rpc.marathon import MaraRPCAPI
from pyasic.web.marathon import MaraWebAPI
MARA_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_overview", "overview")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_overview", "overview")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_network_config", "network_config")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[WebAPICommand("web_brief", "brief")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[WebAPICommand("web_brief", "brief")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[WebAPICommand("web_hashboards", "hashboards")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("web_brief", "brief")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[WebAPICommand("web_miner_config", "miner_config")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("web_fans", "fans")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_locate_miner", "locate_miner")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_brief", "brief")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_brief", "brief")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[WebAPICommand("web_pools", "pools")],
),
}
)
class MaraMiner(MaraFirmware):
_rpc_cls = MaraRPCAPI
rpc: MaraRPCAPI
_web_cls = MaraWebAPI
web: MaraWebAPI
data_locations = MARA_DATA_LOC
async def fault_light_off(self) -> bool:
res = await self.web.set_locate_miner(blinking=False)
return res.get("blinking") is False
async def fault_light_on(self) -> bool:
res = await self.web.set_locate_miner(blinking=True)
return res.get("blinking") is True
async def get_config(self) -> MinerConfig:
data = await self.web.get_miner_config()
if data:
self.config = MinerConfig.from_mara(data)
return self.config
return MinerConfig()
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
data = await self.web.get_miner_config()
cfg_data = config.as_mara(user_suffix=user_suffix)
merged_cfg = merge_dicts(data, cfg_data)
await self.web.set_miner_config(**merged_cfg)
async def set_power_limit(self, wattage: int) -> bool:
cfg = await self.get_config()
cfg.mining_mode = MiningModeConfig.power_tuning(power=wattage)
await self.send_config(cfg)
return True
async def stop_mining(self) -> bool:
data = await self.web.get_miner_config()
data["mode"]["work-mode-selector"] = "Sleep"
await self.web.set_miner_config(**data)
return True
async def resume_mining(self) -> bool:
data = await self.web.get_miner_config()
data["mode"]["work-mode-selector"] = "Auto"
await self.web.set_miner_config(**data)
return True
async def reboot(self) -> bool:
await self.web.reboot()
return True
async def restart_backend(self) -> bool:
await self.web.reload()
return True
async def _get_wattage(self, web_brief: dict | None = None) -> int | None:
if web_brief is None:
try:
web_brief = await self.web.brief()
except APIError:
pass
return None
if web_brief is not None:
try:
return round(web_brief["power_consumption_estimated"])
except LookupError:
pass
async def _is_mining(self, web_brief: dict | None = None) -> bool | None:
if web_brief is None:
try:
web_brief = await self.web.brief()
except APIError:
pass
return None
if web_brief is not None:
try:
return web_brief["status"] == "Mining"
except LookupError:
pass
async def _get_uptime(self, web_brief: dict | None = None) -> int | None:
if web_brief is None:
try:
web_brief = await self.web.brief()
except APIError:
pass
return None
if web_brief is not None:
try:
return web_brief["elapsed"]
except LookupError:
pass
async def _get_hashboards(
self, web_hashboards: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if web_hashboards is None:
try:
web_hashboards = await self.web.hashboards()
except APIError:
pass
if web_hashboards is not None:
try:
for hb in web_hashboards["hashboards"]:
idx = hb["index"]
hashboards[idx].hashrate = self.algo.hashrate(
rate=float(hb["hashrate_average"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[idx].temp = round(
sum(hb["temperature_pcb"]) / len(hb["temperature_pcb"])
)
hashboards[idx].chip_temp = round(
sum(hb["temperature_chip"]) / len(hb["temperature_chip"])
)
hashboards[idx].chips = hb["asic_num"]
hashboards[idx].serial_number = hb["serial_number"]
hashboards[idx].missing = False
except LookupError:
pass
return hashboards
async def _get_mac(self, web_overview: dict | None = None) -> str | None:
if web_overview is None:
try:
web_overview = await self.web.overview()
except APIError:
pass
if web_overview is not None:
try:
return web_overview["mac"].upper()
except LookupError:
pass
return None
async def _get_fw_ver(self, web_overview: dict | None = None) -> str | None:
if web_overview is None:
try:
web_overview = await self.web.overview()
except APIError:
pass
if web_overview is not None:
try:
return web_overview["version_firmware"]
except LookupError:
pass
return None
async def _get_hostname(self, web_network_config: dict | None = None) -> str | None:
if web_network_config is None:
try:
web_network_config = await self.web.get_network_config()
except APIError:
pass
if web_network_config is not None:
try:
return web_network_config["hostname"]
except LookupError:
pass
return None
async def _get_hashrate(
self, web_brief: dict | None = None
) -> AlgoHashRateType | None:
if web_brief is None:
try:
web_brief = await self.web.brief()
except APIError:
pass
if web_brief is not None:
try:
return self.algo.hashrate(
rate=float(web_brief["hashrate_realtime"]),
unit=self.algo.unit.TH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _get_fans(self, web_fans: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_fans is None:
try:
web_fans = await self.web.fans()
except APIError:
pass
if web_fans is not None:
fans = []
for n in range(self.expected_fans):
try:
fans.append(Fan(speed=web_fans["fans"][n]["current_speed"]))
except (IndexError, KeyError):
pass
return fans
return [Fan() for _ in range(self.expected_fans)]
async def _get_fault_light(self, web_locate_miner: dict | None = None) -> bool:
if web_locate_miner is None:
try:
web_locate_miner = await self.web.get_locate_miner()
except APIError:
pass
if web_locate_miner is not None:
try:
return web_locate_miner["blinking"]
except LookupError:
pass
return False
async def _get_expected_hashrate(
self, web_brief: dict | None = None
) -> AlgoHashRateType | None:
if web_brief is None:
try:
web_brief = await self.web.brief()
except APIError:
pass
if web_brief is not None:
try:
return self.algo.hashrate(
rate=float(web_brief["hashrate_ideal"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _get_wattage_limit(
self, web_miner_config: dict | None = None
) -> int | None:
if web_miner_config is None:
try:
web_miner_config = await self.web.get_miner_config()
except APIError:
pass
if web_miner_config is not None:
try:
return web_miner_config["mode"]["concorde"]["power-target"]
except LookupError:
pass
return None
async def _get_pools(self, web_pools: list | None = None) -> list[PoolMetrics]:
if web_pools is None:
try:
web_pools = await self.web.pools()
except APIError:
return []
active_pool_index = None
highest_priority = float("inf")
for pool_info in web_pools:
if (
pool_info.get("status") == "Alive"
and pool_info.get("priority", float("inf")) < highest_priority
):
highest_priority = pool_info["priority"]
active_pool_index = pool_info["index"]
pools_data = []
if web_pools is not None:
try:
for pool_info in web_pools:
url = pool_info.get("url")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("accepted"),
rejected=pool_info.get("rejected"),
get_failures=pool_info.get("stale"),
remote_failures=pool_info.get("discarded"),
active=pool_info.get("index") == active_pool_index,
alive=pool_info.get("status") == "Alive",
url=pool_url,
user=pool_info.get("user"),
index=pool_info.get("index"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/antminer.py | pyasic/miners/backends/antminer.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import logging
from pathlib import Path
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import X19Error
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.backends.bmminer import BMMiner
from pyasic.miners.backends.cgminer import CGMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.rpc.antminer import AntminerRPCAPI
from pyasic.ssh.antminer import AntminerModernSSH
from pyasic.web.antminer import AntminerModernWebAPI, AntminerOldWebAPI
ANTMINER_MODERN_DATA_LOC = DataLocations(
**{
str(DataOptions.SERIAL_NUMBER): DataFunction(
"_get_serial_number",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_get_blink_status", "get_blink_status")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_get_conf", "get_miner_conf")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class AntminerModern(BMMiner):
"""Handler for AntMiners with the modern web interface, such as S19"""
_web_cls = AntminerModernWebAPI
web: AntminerModernWebAPI
_rpc_cls = AntminerRPCAPI
rpc: AntminerRPCAPI
_ssh_cls = AntminerModernSSH
ssh: AntminerModernSSH
data_locations = ANTMINER_MODERN_DATA_LOC
supports_shutdown = True
supports_power_modes = True
async def get_config(self) -> MinerConfig:
data = await self.web.get_miner_conf()
if data:
self.config = MinerConfig.from_am_modern(data)
return self.config or MinerConfig()
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
await self.web.set_miner_conf(config.as_am_modern(user_suffix=user_suffix))
# if data:
# if data.get("code") == "M000":
# return
#
# for i in range(7):
# data = await self.get_config()
# if data == self.config:
# break
# await asyncio.sleep(1)
async def upgrade_firmware(
self,
*,
file: str | None = None,
url: str | None = None,
version: str | None = None,
keep_settings: bool = True,
) -> bool:
"""
Upgrade the firmware of the AntMiner device.
Args:
file: Path to the firmware file as a string.
url: URL to download firmware from (not implemented).
version: Version to upgrade to (not implemented).
keep_settings: Whether to keep the current settings after the update.
Returns:
bool: True if upgrade was successful, False otherwise.
"""
if not file:
logging.error("File location must be provided for firmware upgrade.")
return False
if url or version:
logging.warning(
"URL and version parameters are not implemented for Antminer."
)
try:
file_path = Path(file)
if not hasattr(self.web, "update_firmware"):
logging.error(
"Firmware upgrade not supported via web API for this Antminer model."
)
return False
result = await self.web.update_firmware(
file=file_path, keep_settings=keep_settings
)
if result.get("success"):
logging.info(
"Firmware upgrade process completed successfully for AntMiner."
)
return True
else:
error_message = result.get("message", "Unknown error")
logging.error(f"Firmware upgrade failed. Response: {error_message}")
return False
except Exception as e:
logging.error(
f"An error occurred during the firmware upgrade process: {e}",
exc_info=True,
)
return False
async def fault_light_on(self) -> bool:
data = await self.web.blink(blink=True)
if data:
if data.get("code") == "B000":
self.light = True
return self.light or False
async def fault_light_off(self) -> bool:
data = await self.web.blink(blink=False)
if data:
if data.get("code") == "B100":
self.light = False
return self.light or False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
return True
return False
async def stop_mining(self) -> bool:
cfg = await self.get_config()
cfg.mining_mode = MiningModeConfig.sleep()
await self.send_config(cfg)
return True
async def resume_mining(self) -> bool:
cfg = await self.get_config()
cfg.mining_mode = MiningModeConfig.normal()
await self.send_config(cfg)
return True
async def _get_hostname(
self, web_get_system_info: dict | None = None
) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["hostname"]
except KeyError:
pass
return None
async def _get_mac(self, web_get_system_info: dict | None = None) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["macaddr"]
except KeyError:
pass
try:
data = await self.web.get_network_info()
if data:
return data["macaddr"]
except KeyError:
pass
return None
async def _get_errors( # type: ignore[override]
self, web_summary: dict | None = None
) -> list[X19Error]:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
errors = []
if web_summary is not None:
try:
for item in web_summary["SUMMARY"][0]["status"]:
try:
if not item["status"] == "s":
errors.append(X19Error(error_message=item["msg"]))
except KeyError:
continue
except LookupError:
pass
return errors
async def _get_hashboards(self) -> list[HashBoard]: # type: ignore[override]
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=idx, expected_chips=self.expected_chips)
for idx in range(self.expected_hashboards)
]
try:
rpc_stats = await self.rpc.stats(new_api=True)
except APIError:
return hashboards
if rpc_stats is not None:
try:
for board in rpc_stats["STATS"][0]["chain"]:
hashboards[board["index"]].hashrate = self.algo.hashrate(
rate=board["rate_real"],
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[board["index"]].chips = board["asic_num"]
if "S21+ Hyd" in self.model:
hashboards[board["index"]].inlet_temp = board["temp_pcb"][0]
hashboards[board["index"]].outlet_temp = board["temp_pcb"][2]
hashboards[board["index"]].chip_temp = board["temp_pic"][0]
board_temp_data = list(
filter(
lambda x: not x == 0,
[
board["temp_pic"][1],
board["temp_pic"][2],
board["temp_pic"][3],
board["temp_pcb"][1],
board["temp_pcb"][3],
],
)
)
hashboards[board["index"]].temp = (
sum(board_temp_data) / len(board_temp_data)
if len(board_temp_data) > 0
else 0
)
else:
board_temp_data = list(
filter(lambda x: not x == 0, board["temp_pcb"])
)
hashboards[board["index"]].temp = (
sum(board_temp_data) / len(board_temp_data)
if len(board_temp_data) > 0
else 0
)
chip_temp_data = list(
filter(lambda x: not x == 0, board["temp_chip"])
)
hashboards[board["index"]].chip_temp = (
sum(chip_temp_data) / len(chip_temp_data)
if len(chip_temp_data) > 0
else 0
)
hashboards[board["index"]].serial_number = board["sn"]
hashboards[board["index"]].missing = False
except LookupError:
pass
return hashboards
async def _get_fault_light(
self, web_get_blink_status: dict | None = None
) -> bool | None:
if self.light:
return self.light
if web_get_blink_status is None:
try:
web_get_blink_status = await self.web.get_blink_status()
except APIError:
pass
if web_get_blink_status is not None:
try:
self.light = web_get_blink_status["blink"]
except KeyError:
pass
return self.light
async def _get_expected_hashrate(
self, rpc_stats: dict | None = None
) -> AlgoHashRateType | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
expected_rate = rpc_stats["STATS"][1]["total_rateideal"]
try:
rate_unit = rpc_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "GH"
return self.algo.hashrate(
rate=float(expected_rate), unit=self.algo.unit.from_str(rate_unit)
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _get_serial_number(
self, web_get_system_info: dict | None = None
) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["serinum"]
except LookupError:
pass
return None
async def set_static_ip(
self,
ip: str,
dns: str,
gateway: str,
subnet_mask: str = "255.255.255.0",
hostname: str | None = None,
):
if not hostname:
hostname = await self.get_hostname() or ""
await self.web.set_network_conf(
ip=ip,
dns=dns,
gateway=gateway,
subnet_mask=subnet_mask,
hostname=hostname,
protocol=2,
)
async def set_dhcp(self, hostname: str | None = None):
if not hostname:
hostname = await self.get_hostname() or ""
await self.web.set_network_conf(
ip="", dns="", gateway="", subnet_mask="", hostname=hostname, protocol=1
)
async def set_hostname(self, hostname: str):
cfg = await self.web.get_network_info()
dns = cfg["conf_dnsservers"]
gateway = cfg["conf_gateway"]
ip = cfg["conf_ipaddress"]
subnet_mask = cfg["conf_netmask"]
protocol = 1 if cfg["conf_nettype"] == "DHCP" else 2
await self.web.set_network_conf(
ip=ip,
dns=dns,
gateway=gateway,
subnet_mask=subnet_mask,
hostname=hostname,
protocol=protocol,
)
async def _is_mining(self, web_get_conf: dict | None = None) -> bool | None:
if web_get_conf is None:
try:
web_get_conf = await self.web.get_miner_conf()
except APIError:
pass
if web_get_conf is not None:
try:
if str(web_get_conf["bitmain-work-mode"]).isdigit():
return (
False if int(web_get_conf["bitmain-work-mode"]) == 1 else True
)
return False
except LookupError:
pass
return None
async def _get_uptime(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return int(rpc_stats["STATS"][1]["Elapsed"])
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
ANTMINER_OLD_DATA_LOC = DataLocations(
**{
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_get_blink_status", "get_blink_status")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_get_conf", "get_miner_conf")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
}
)
class AntminerOld(CGMiner):
"""Handler for AntMiners with the old web interface, such as S17"""
_web_cls = AntminerOldWebAPI
web: AntminerOldWebAPI
data_locations = ANTMINER_OLD_DATA_LOC
async def get_config(self) -> MinerConfig:
data = await self.web.get_miner_conf()
if data:
self.config = MinerConfig.from_am_old(data)
return self.config or MinerConfig()
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
await self.web.set_miner_conf(config.as_am_old(user_suffix=user_suffix))
async def _get_mac(self) -> str | None:
try:
data = await self.web.get_system_info()
if data:
return data["macaddr"]
except KeyError:
pass
return None
async def fault_light_on(self) -> bool:
# this should time out, after it does do a check
await self.web.blink(blink=True)
try:
data = await self.web.get_blink_status()
if data:
if data["isBlinking"]:
self.light = True
except KeyError:
pass
return self.light or False
async def fault_light_off(self) -> bool:
await self.web.blink(blink=False)
try:
data = await self.web.get_blink_status()
if data:
if not data["isBlinking"]:
self.light = False
except KeyError:
pass
return self.light or False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
return True
return False
async def _get_fault_light(
self, web_get_blink_status: dict | None = None
) -> bool | None:
if self.light:
return self.light
if web_get_blink_status is None:
try:
web_get_blink_status = await self.web.get_blink_status()
except APIError:
pass
if web_get_blink_status is not None:
try:
self.light = web_get_blink_status["isBlinking"]
except KeyError:
pass
return self.light
async def _get_hostname(
self, web_get_system_info: dict | None = None
) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["hostname"]
except KeyError:
pass
return None
async def _get_fans(self, rpc_stats: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
fans_data = [Fan() for _ in range(self.expected_fans)]
if rpc_stats is not None:
try:
fan_offset = -1
for fan_num in range(1, 8, 4):
for _f_num in range(4):
f = rpc_stats["STATS"][1].get(f"fan{fan_num + _f_num}")
if f and not f == 0 and fan_offset == -1:
fan_offset = fan_num + 2
if fan_offset == -1:
fan_offset = 3
for fan in range(self.expected_fans):
fans_data[fan].speed = rpc_stats["STATS"][1].get(
f"fan{fan_offset + fan}", 0
)
except LookupError:
pass
return fans_data
async def _get_hashboards(self, rpc_stats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards: list[HashBoard] = []
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
board_offset = -1
boards = rpc_stats["STATS"]
if len(boards) > 1:
for board_num in range(1, 16, 5):
for _b_num in range(5):
b = boards[1].get(f"chain_acn{board_num + _b_num}")
if b and not b == 0 and board_offset == -1:
board_offset = board_num
if board_offset == -1:
board_offset = 1
for i in range(
board_offset, board_offset + self.expected_hashboards
):
hashboard = HashBoard(
slot=i - board_offset, expected_chips=self.expected_chips
)
chip_temp = boards[1].get(f"temp{i}")
if chip_temp:
hashboard.chip_temp = round(chip_temp)
temp = boards[1].get(f"temp2_{i}")
if temp:
hashboard.temp = round(temp)
hashrate = boards[1].get(f"chain_rate{i}")
if hashrate:
hashboard.hashrate = self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
chips = boards[1].get(f"chain_acn{i}")
if chips:
hashboard.chips = chips
hashboard.missing = False
if (not chips) or (not chips > 0):
hashboard.missing = True
hashboards.append(hashboard)
except LookupError:
return [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
return hashboards
async def _is_mining(self, web_get_conf: dict | None = None) -> bool | None:
if web_get_conf is None:
try:
web_get_conf = await self.web.get_miner_conf()
except APIError:
pass
if web_get_conf is not None:
try:
return False if int(web_get_conf["bitmain-work-mode"]) == 1 else True
except LookupError:
pass
rpc_summary = None
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
if rpc_summary is not None:
if not rpc_summary == {}:
return True
else:
return False
return None
async def _get_uptime(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return int(rpc_stats["STATS"][1]["Elapsed"])
except LookupError:
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/hiveon.py | pyasic/miners/backends/hiveon.py | # ------------------------------------------------------------------------------
# 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 import APIError
from pyasic.config import MinerConfig, MiningModeConfig
from pyasic.miners.backends import BMMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.firmware import HiveonFirmware
from pyasic.web.hiveon import HiveonWebAPI
HIVEON_MODERN_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_get_system_info", "get_system_info")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_get_blink_status", "get_blink_status")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_get_conf", "get_miner_conf")],
),
}
)
class HiveonModern(HiveonFirmware, BMMiner):
data_locations = HIVEON_MODERN_DATA_LOC
web: HiveonWebAPI
_web_cls = HiveonWebAPI
async def get_config(self) -> MinerConfig | None: # type: ignore[override]
data = await self.web.get_miner_conf()
if data:
self.config = MinerConfig.from_hiveon_modern(data)
return self.config
async def fault_light_on(self) -> bool:
data = await self.web.blink(blink=True)
if data:
if data.get("code") == "B000":
self.light = True
return True
return False
async def fault_light_off(self) -> bool:
data = await self.web.blink(blink=False)
if data:
if data.get("code") == "B100":
self.light = False
return True
return False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
return True
return False
async def stop_mining(self) -> bool:
cfg = await self.get_config()
if cfg is not None:
cfg.mining_mode = MiningModeConfig.sleep()
await self.send_config(cfg)
return True
return False
async def resume_mining(self) -> bool:
cfg = await self.get_config()
if cfg is not None:
cfg.mining_mode = MiningModeConfig.normal()
await self.send_config(cfg)
return True
return False
async def _get_wattage(self, rpc_stats: dict | None = None) -> int | None:
if not rpc_stats:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats:
boards = rpc_stats.get("STATS")
if boards:
try:
wattage_raw = boards[1]["chain_power"]
except (KeyError, IndexError):
pass
else:
# parse wattage position out of raw data
return round(float(wattage_raw.split(" ")[0]))
return None
async def _get_hostname(
self, web_get_system_info: dict | None = None
) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["hostname"]
except KeyError:
pass
return None
async def _get_mac(self, web_get_system_info: dict | None = None) -> str | None:
if web_get_system_info is None:
try:
web_get_system_info = await self.web.get_system_info()
except APIError:
pass
if web_get_system_info is not None:
try:
return web_get_system_info["macaddr"]
except KeyError:
pass
try:
data = await self.web.get_network_info()
if data:
return data["macaddr"]
except KeyError:
pass
return None
async def _get_fault_light(
self, web_get_blink_status: dict | None = None
) -> bool | None:
if self.light:
return self.light
if web_get_blink_status is None:
try:
web_get_blink_status = await self.web.get_blink_status()
except APIError:
pass
if web_get_blink_status is not None:
try:
self.light = web_get_blink_status["blink"]
except KeyError:
pass
return self.light
async def _is_mining(self, web_get_conf: dict | None = None) -> bool | None:
if web_get_conf is None:
try:
web_get_conf = await self.web.get_miner_conf()
except APIError:
pass
if web_get_conf is not None:
try:
if str(web_get_conf["bitmain-work-mode"]).isdigit():
return (
False if int(web_get_conf["bitmain-work-mode"]) == 1 else True
)
return False
except LookupError:
pass
return None
HIVEON_OLD_DATA_LOC = DataLocations(
**{
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_stats", "stats")],
),
}
)
class HiveonOld(HiveonFirmware, BMMiner):
data_locations = HIVEON_OLD_DATA_LOC
async def _get_wattage(self, rpc_stats: dict | None = None) -> int | None:
if not rpc_stats:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats:
boards = rpc_stats.get("STATS")
if boards:
try:
wattage_raw = boards[1]["chain_power"]
except (KeyError, IndexError):
pass
else:
# parse wattage position out of raw data
return round(float(wattage_raw.split(" ")[0]))
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/luxminer.py | pyasic/miners/backends/luxminer.py | # ------------------------------------------------------------------------------
# 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. -
# ------------------------------------------------------------------------------
import logging
from pyasic.config import MinerConfig
from pyasic.config.mining import MiningModePreset
from pyasic.data import Fan, HashBoard
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.miners.device.firmware import LuxOSFirmware
from pyasic.rpc.luxminer import LUXMinerRPCAPI
LUXMINER_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[RPCAPICommand("rpc_config", "config")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[RPCAPICommand("rpc_power", "power")],
),
str(DataOptions.WATTAGE_LIMIT): DataFunction(
"_get_wattage_limit",
[
RPCAPICommand("rpc_config", "config"),
RPCAPICommand("rpc_profiles", "profiles"),
],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_fans", "fans")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime", [RPCAPICommand("rpc_stats", "stats")]
),
str(DataOptions.POOLS): DataFunction(
"_get_pools", [RPCAPICommand("rpc_pools", "pools")]
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver", [RPCAPICommand("rpc_version", "version")]
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver", [RPCAPICommand("rpc_version", "version")]
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light", [RPCAPICommand("rpc_config", "config")]
),
}
)
class LUXMiner(LuxOSFirmware):
"""Handler for LuxOS miners"""
_rpc_cls = LUXMinerRPCAPI
rpc: LUXMinerRPCAPI
supports_shutdown = True
supports_presets = True
supports_autotuning = True
data_locations = LUXMINER_DATA_LOC
async def fault_light_on(self) -> bool:
try:
await self.rpc.ledset("red", "blink")
return True
except (APIError, LookupError):
pass
return False
async def fault_light_off(self) -> bool:
try:
await self.rpc.ledset("red", "off")
return True
except (APIError, LookupError):
pass
return False
async def restart_backend(self) -> bool:
return await self.restart_luxminer()
async def restart_luxminer(self) -> bool:
try:
await self.rpc.resetminer()
return True
except (APIError, LookupError):
pass
return False
async def stop_mining(self) -> bool:
try:
await self.rpc.sleep()
return True
except (APIError, LookupError):
pass
return False
async def resume_mining(self) -> bool:
try:
await self.rpc.wakeup()
return True
except (APIError, LookupError):
pass
return False
async def reboot(self) -> bool:
try:
await self.rpc.rebootdevice()
return True
except (APIError, LookupError):
pass
return False
async def get_config(self) -> MinerConfig:
data = await self.rpc.multicommand(
"tempctrl", "fans", "pools", "groups", "config", "profiles"
)
return MinerConfig.from_luxos(
rpc_tempctrl=data.get("tempctrl", [{}])[0],
rpc_fans=data.get("fans", [{}])[0],
rpc_pools=data.get("pools", [{}])[0],
rpc_groups=data.get("groups", [{}])[0],
rpc_config=data.get("config", [{}])[0],
rpc_profiles=data.get("profiles", [{}])[0],
)
async def upgrade_firmware(self, *args, **kwargs) -> bool:
"""
Upgrade the firmware on a LuxOS miner by calling the 'updaterun' API command.
Returns:
bool: True if the firmware upgrade was successfully initiated, False otherwise.
"""
try:
await self.rpc.updaterun()
logging.info(f"{self.ip}: Firmware upgrade initiated successfully.")
return True
except APIError as e:
logging.error(f"{self.ip}: Firmware upgrade failed: {e}")
return False
async def atm_enabled(self) -> bool | None:
try:
result = await self.rpc.atm()
return result["ATM"][0]["Enabled"]
except (APIError, LookupError):
pass
return None
async def set_power_limit(self, wattage: int) -> bool:
config = await self.get_config()
# Check if we have preset mode with available presets
if not hasattr(config.mining_mode, "available_presets"):
logging.warning(f"{self} - Mining mode does not support presets")
return False
available_presets = getattr(config.mining_mode, "available_presets", [])
if not available_presets:
logging.warning(f"{self} - No available presets found")
return False
valid_presets = {
preset.name: preset.power
for preset in available_presets
if preset.power is not None and preset.power <= wattage
}
if not valid_presets:
logging.warning(f"{self} - No valid presets found for wattage {wattage}")
return False
# Set power to highest preset <= wattage
# If ATM enabled, must disable it before setting power limit
new_preset = max(valid_presets, key=lambda x: valid_presets[x])
re_enable_atm = False
try:
if await self.atm_enabled():
re_enable_atm = True
await self.rpc.atmset(enabled=False)
result = await self.rpc.profileset(new_preset)
if re_enable_atm:
await self.rpc.atmset(enabled=True)
except APIError:
raise
except Exception as e:
logging.warning(f"{self} - Failed to set power limit: {e}")
return False
if result["PROFILE"][0]["Profile"] == new_preset:
return True
else:
return False
##################################################
### DATA GATHERING FUNCTIONS (get_{some_data}) ###
##################################################
async def _get_mac(self, rpc_config: dict | None = None) -> str | None:
if rpc_config is None:
try:
rpc_config = await self.rpc.config()
except APIError:
pass
return None
if rpc_config is not None:
try:
return rpc_config["CONFIG"][0]["MACAddr"].upper()
except KeyError:
pass
async def _get_hashrate(
self, rpc_summary: dict | None = None
) -> AlgoHashRateType | None:
if rpc_summary is None:
try:
rpc_summary = await self.rpc.summary()
except APIError:
pass
return None
if rpc_summary is not None:
try:
return self.algo.hashrate(
rate=float(rpc_summary["SUMMARY"][0]["GHS 5s"]),
unit=self.algo.unit.GH,
).into(self.algo.unit.default)
except (LookupError, ValueError, TypeError):
pass
async def _get_hashboards(self, rpc_stats: dict | None = None) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
hashboards = [
HashBoard(slot=idx, expected_chips=self.expected_chips)
for idx in range(self.expected_hashboards)
]
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
# TODO: bugged on S9 because of index issues, fix later.
board_stats = rpc_stats["STATS"][1]
for idx in range(3):
board_n = idx + 1
hashboards[idx].hashrate = self.algo.hashrate(
rate=float(board_stats[f"chain_rate{board_n}"]),
unit=self.algo.unit.GH, # type: ignore[attr-defined]
).into(
self.algo.unit.default # type: ignore[attr-defined]
)
hashboards[idx].chips = int(board_stats[f"chain_acn{board_n}"])
chip_temp_data = list(
filter(
lambda x: not x == 0,
map(int, board_stats[f"temp_chip{board_n}"].split("-")),
)
)
hashboards[idx].chip_temp = (
sum([chip_temp_data[0], chip_temp_data[3]]) / 2
)
board_temp_data = list(
filter(
lambda x: not x == 0,
map(int, board_stats[f"temp_pcb{board_n}"].split("-")),
)
)
hashboards[idx].temp = (
sum([board_temp_data[1], board_temp_data[2]]) / 2
)
hashboards[idx].missing = False
except LookupError:
pass
return hashboards
async def _get_wattage(self, rpc_power: dict | None = None) -> int | None:
if rpc_power is None:
try:
rpc_power = await self.rpc.power()
except APIError:
pass
return None
if rpc_power is not None:
try:
return rpc_power["POWER"][0]["Watts"]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_wattage_limit(
self, rpc_config: dict | None = None, rpc_profiles: dict | None = None
) -> int | None:
if rpc_config is None or rpc_profiles is None:
return None
try:
active_preset = MiningModePreset.get_active_preset_from_luxos(
rpc_config, rpc_profiles
)
return active_preset.power
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_fans(self, rpc_fans: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_fans is None:
try:
rpc_fans = await self.rpc.fans()
except APIError:
pass
fans = []
if rpc_fans is not None:
for fan in range(self.expected_fans):
try:
fans.append(Fan(speed=rpc_fans["FANS"][fan]["RPM"]))
except (LookupError, ValueError, TypeError):
fans.append(Fan())
return fans
async def _get_expected_hashrate(
self, rpc_stats: dict | None = None
) -> AlgoHashRateType | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
expected_rate = rpc_stats["STATS"][1]["total_rateideal"]
try:
rate_unit = rpc_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "GH"
return self.algo.hashrate(
rate=float(expected_rate), unit=self.algo.unit.from_str(rate_unit)
).into(self.algo.unit.default) # type: ignore[attr-defined]
except LookupError:
pass
return None
async def _get_uptime(self, rpc_stats: dict | None = None) -> int | None:
if rpc_stats is None:
try:
rpc_stats = await self.rpc.stats()
except APIError:
pass
if rpc_stats is not None:
try:
return int(rpc_stats["STATS"][1]["Elapsed"])
except LookupError:
pass
return None
async def _get_fw_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
return rpc_version["VERSION"][0]["Miner"]
except LookupError:
pass
return None
async def _get_api_ver(self, rpc_version: dict | None = None) -> str | None:
if rpc_version is None:
try:
rpc_version = await self.rpc.version()
except APIError:
pass
if rpc_version is not None:
try:
return rpc_version["VERSION"][0]["API"]
except LookupError:
pass
return None
async def _get_fault_light(self, rpc_config: dict | None = None) -> bool | None:
if rpc_config is None:
try:
rpc_config = await self.rpc.config()
except APIError:
pass
if rpc_config is not None:
try:
return not rpc_config["CONFIG"][0]["RedLed"] == "off"
except LookupError:
pass
return None
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for pool_info in pools:
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
get_failures=pool_info.get("Get Failures"),
remote_failures=pool_info.get("Remote Failures"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=pool_info.get("POOL"),
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/backends/epic.py | pyasic/miners/backends/epic.py | # ------------------------------------------------------------------------------
# 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.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data.error_codes import MinerErrorData, X19Error
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType, ScryptAlgo
from pyasic.errors import APIError
from pyasic.logger import logger
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, WebAPICommand
from pyasic.miners.device.firmware import ePICFirmware
from pyasic.web.epic import ePICWebAPI
EPIC_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_network", "network")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.HOSTNAME): DataFunction(
"_get_hostname",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
WebAPICommand("web_summary", "summary"),
WebAPICommand("web_capabilities", "capabilities"),
],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.ERRORS): DataFunction(
"_get_errors",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.FAULT_LIGHT): DataFunction(
"_get_fault_light",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.IS_MINING): DataFunction(
"_is_mining",
[WebAPICommand("web_summary", "summary")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[WebAPICommand("web_summary", "summary")],
),
}
)
class ePIC(ePICFirmware):
"""Handler for miners with the ePIC board"""
_web_cls = ePICWebAPI
web: ePICWebAPI
data_locations = EPIC_DATA_LOC
supports_shutdown = True
async def get_config(self) -> MinerConfig:
summary = None
try:
summary = await self.web.summary()
except APIError as e:
logger.warning(e)
except LookupError:
pass
if summary is not None:
cfg = MinerConfig.from_epic(summary)
else:
cfg = MinerConfig()
self.config = cfg
return self.config
async def send_config(
self, config: MinerConfig, user_suffix: str | None = None
) -> None:
self.config = config
conf = self.config.as_epic(user_suffix=user_suffix)
try:
# Temps
if not conf.get("temps", {}) == {}:
await self.web.set_shutdown_temp(conf["temps"]["shutdown"])
await self.web.set_critical_temp(conf["temps"]["critical"])
# Fans
# set with sub-keys instead of conf["fans"] because sometimes both can be set
if not conf["fans"].get("Manual", {}) == {}:
await self.web.set_fan({"Manual": conf["fans"]["Manual"]})
elif not conf["fans"].get("Auto", {}) == {}:
await self.web.set_fan({"Auto": conf["fans"]["Auto"]})
# Mining Mode -- Need to handle that you may not be able to change while miner is tuning
if conf["ptune"].get("enabled", True):
await self.web.set_ptune_enable(True)
await self.web.set_ptune_algo(conf["ptune"])
## Pools
if self.algo == ScryptAlgo:
conf["pools"]["coin"] = "Ltc"
await self.web.set_pools(conf["pools"])
except APIError:
pass
async def restart_backend(self) -> bool:
data = await self.web.restart_epic()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def stop_mining(self) -> bool:
data = await self.web.stop_mining()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def resume_mining(self) -> bool:
data = await self.web.resume_mining()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def reboot(self) -> bool:
data = await self.web.reboot()
if data:
try:
return data["success"]
except KeyError:
pass
return False
async def _get_mac(self, web_network: dict | None = None) -> str | None:
if web_network is None:
try:
web_network = await self.web.network()
except APIError:
pass
if web_network is not None:
try:
for network in web_network:
mac = web_network[network]["mac_address"]
return mac
except KeyError:
pass
return None
async def _get_hostname(self, web_summary: dict | None = None) -> str | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
hostname = web_summary["Hostname"]
return hostname
except KeyError:
pass
return None
async def _get_wattage(self, web_summary: dict | None = None) -> int | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
wattage = web_summary["Power Supply Stats"]["Input Power"]
wattage = round(wattage)
return wattage
except KeyError:
pass
return None
async def _get_hashrate(
self, web_summary: dict | None = None
) -> AlgoHashRateType | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
hashrate = 0
if web_summary["HBs"] is not None:
for hb in web_summary["HBs"]:
hashrate += hb["Hashrate"][0]
return self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.TH) # type: ignore[attr-defined]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_expected_hashrate(
self, web_summary: dict | None = None
) -> AlgoHashRateType | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
hashrate = 0
if web_summary.get("HBs") is not None:
for hb in web_summary["HBs"]:
if hb["Hashrate"][1] == 0:
ideal = 1.0
else:
ideal = hb["Hashrate"][1] / 100
hashrate += hb["Hashrate"][0] / ideal
return self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
except (LookupError, ValueError, TypeError):
pass
return None
async def _get_fw_ver(self, web_summary: dict | None = None) -> str | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
fw_ver = web_summary["Software"]
fw_ver = fw_ver.split(" ")[1].replace("v", "")
return fw_ver
except KeyError:
pass
return None
async def _get_fans(self, web_summary: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
fans = []
if web_summary is not None:
for fan in web_summary["Fans Rpm"]:
try:
fans.append(Fan(speed=web_summary["Fans Rpm"][fan]))
except (LookupError, ValueError, TypeError):
fans.append(Fan())
return fans
async def _get_hashboards(
self, web_summary: dict | None = None, web_capabilities: dict | None = None
) -> list[HashBoard]:
if self.expected_hashboards is None:
return []
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_capabilities is None:
try:
web_capabilities = await self.web.capabilities()
except APIError:
pass
tuned = True
active = False
if web_summary is not None:
tuner_running = web_summary["PerpetualTune"]["Running"]
if tuner_running:
active = True
algo_info = web_summary["PerpetualTune"]["Algorithm"]
if algo_info.get("VoltageOptimizer") is not None:
tuned = algo_info["VoltageOptimizer"].get("Optimized")
elif algo_info.get("BoardTune") is not None:
tuned = algo_info["BoardTune"].get("Optimized")
else:
tuned = algo_info["ChipTune"].get("Optimized")
# To be extra detailed, also ensure the miner is in "Mining" state
tuned = tuned and web_summary["Status"]["Operating State"] == "Mining"
active = active and web_summary["Status"]["Operating State"] == "Mining"
hb_list = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if web_summary is not None and web_capabilities is not None:
if web_summary.get("HBs") is not None:
for hb in web_summary["HBs"]:
if web_capabilities.get("Performance Estimator") is not None:
num_of_chips = web_capabilities["Performance Estimator"][
"Chip Count"
]
else:
num_of_chips = self.expected_chips
if web_capabilities.get("Board Serial Numbers") is not None:
if hb["Index"] < len(web_capabilities["Board Serial Numbers"]):
hb_list[hb["Index"]].serial_number = web_capabilities[
"Board Serial Numbers"
][hb["Index"]]
hashrate = hb["Hashrate"][0]
# Update the Hashboard object
hb_list[hb["Index"]].missing = False
hb_list[hb["Index"]].hashrate = self.algo.hashrate(
rate=float(hashrate),
unit=self.algo.unit.MH, # type: ignore[attr-defined]
).into(self.algo.unit.default) # type: ignore[attr-defined]
hb_list[hb["Index"]].chips = num_of_chips
hb_list[hb["Index"]].temp = int(hb["Temperature"])
hb_list[hb["Index"]].tuned = tuned
hb_list[hb["Index"]].active = active
hb_list[hb["Index"]].voltage = hb["Input Voltage"]
return hb_list
return hb_list
async def _is_mining(self, web_summary: dict | None = None) -> bool | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
op_state = web_summary["Status"]["Operating State"]
return not op_state == "Idling"
except KeyError:
pass
return None
async def _get_uptime(self, web_summary: dict | None = None) -> int | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
uptime = web_summary["Session"]["Uptime"]
return uptime
except KeyError:
pass
return None
async def _get_fault_light(self, web_summary: dict | None = None) -> bool | None:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
if web_summary is not None:
try:
light = web_summary["Misc"]["Locate Miner State"]
return light
except KeyError:
pass
return False
async def _get_errors(
self, web_summary: dict | None = None
) -> list[MinerErrorData]:
if not web_summary:
try:
web_summary = await self.web.summary()
except APIError:
pass
errors = []
if web_summary is not None:
try:
error = web_summary["Status"]["Last Error"]
if error is not None:
errors.append(X19Error(error_message=str(error)))
except KeyError:
pass
return errors # type: ignore[return-value]
async def _get_pools(self, web_summary: dict | None = None) -> list[PoolMetrics]:
if web_summary is None:
try:
web_summary = await self.web.summary()
except APIError:
pass
pool_data = []
try:
if web_summary is not None:
if (
web_summary.get("Session") is not None
and web_summary.get("Stratum") is not None
):
url = web_summary["Stratum"].get("Current Pool")
# TODO: when scheme gets put in, update this
if url is not None:
url = PoolUrl.from_str(f"stratum+tcp://{url}")
pool_data.append(
PoolMetrics(
accepted=web_summary["Session"].get("Accepted"),
rejected=web_summary["Session"].get("Rejected"),
get_failures=0,
remote_failures=0,
active=web_summary["Stratum"].get("IsPoolConnected"),
alive=web_summary["Stratum"].get("IsPoolConnected"),
url=url,
user=web_summary["Stratum"].get("Current User"),
index=web_summary["Stratum"].get("Config Id"),
)
)
return pool_data
except LookupError:
pass
return []
async def upgrade_firmware(
self,
*,
file: str | None = None,
url: str | None = None,
version: str | None = None,
keep_settings: bool = True,
) -> bool:
"""
Upgrade the firmware of the ePIC miner device.
Args:
file: The local file path of the firmware to be uploaded.
url: The URL to download the firmware from. Must be a valid URL if provided.
version: The version of the firmware to upgrade to. If None, the version will be inferred from the file or URL.
keep_settings: Whether to keep the current settings after the update.
Returns:
bool: Whether the firmware update succeeded.
"""
if file is not None:
await self.web.system_update(file=file, keep_settings=keep_settings)
return True
return False
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/__init__.py | pyasic/miners/goldshell/__init__.py | # ------------------------------------------------------------------------------
# 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 .bfgminer import *
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/__init__.py | pyasic/miners/goldshell/bfgminer/__init__.py | # ------------------------------------------------------------------------------
# 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 .byte import *
from .mini_doge import *
from .X5 import *
from .XBox import *
from .XMax import *
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/XMax/KDMax.py | pyasic/miners/goldshell/bfgminer/XMax/KDMax.py | # ------------------------------------------------------------------------------
# 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 GoldshellMiner
from pyasic.miners.device.models import KDMax
class GoldshellKDMax(GoldshellMiner, KDMax):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/XMax/__init__.py | pyasic/miners/goldshell/bfgminer/XMax/__init__.py | # ------------------------------------------------------------------------------
# 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 .KDMax import GoldshellKDMax
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/X5/HS5.py | pyasic/miners/goldshell/bfgminer/X5/HS5.py | # ------------------------------------------------------------------------------
# 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 GoldshellMiner
from pyasic.miners.device.models import HS5
class GoldshellHS5(GoldshellMiner, HS5):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/X5/KD5.py | pyasic/miners/goldshell/bfgminer/X5/KD5.py | # ------------------------------------------------------------------------------
# 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 GoldshellMiner
from pyasic.miners.device.models import KD5
class GoldshellKD5(GoldshellMiner, KD5):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/X5/CK5.py | pyasic/miners/goldshell/bfgminer/X5/CK5.py | # ------------------------------------------------------------------------------
# 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 GoldshellMiner
from pyasic.miners.device.models import CK5
class GoldshellCK5(GoldshellMiner, CK5):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/X5/__init__.py | pyasic/miners/goldshell/bfgminer/X5/__init__.py | # ------------------------------------------------------------------------------
# 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 .CK5 import GoldshellCK5
from .HS5 import GoldshellHS5
from .KD5 import GoldshellKD5
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/mini_doge/__init__.py | pyasic/miners/goldshell/bfgminer/mini_doge/__init__.py | # ------------------------------------------------------------------------------
# Copyright 2025 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 .mini_doge import GoldshellMiniDoge
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/mini_doge/mini_doge.py | pyasic/miners/goldshell/bfgminer/mini_doge/mini_doge.py | # ------------------------------------------------------------------------------
# Copyright 2025 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.config import MinerConfig
from pyasic.data.boards import HashBoard
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.errors import APIError
from pyasic.logger import logger
from pyasic.miners.backends import GoldshellMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.models import MiniDoge
GOLDSHELL_MINI_DOGE_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_setting", "setting")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[RPCAPICommand("rpc_version", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_status", "status")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_summary", "summary")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_devs", "devs"),
RPCAPICommand("rpc_devdetails", "devdetails"),
],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_stats", "stats")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_devs", "devs")],
),
}
)
class GoldshellMiniDoge(GoldshellMiner, MiniDoge):
data_locations = GOLDSHELL_MINI_DOGE_DATA_LOC
supports_shutdown = False
supports_power_modes = False
async def get_config(self) -> MinerConfig | None: # type: ignore[override]
try:
pools = await self.web.pools()
except APIError:
if self.config is not None:
return self.config
self.config = MinerConfig.from_goldshell(pools)
return self.config
async def _get_expected_hashrate(
self, rpc_devs: dict | None = None
) -> AlgoHashRateType | None:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
if rpc_devs is not None:
try:
hash_rate = rpc_devs["DEVS"][0]["estimate_hash_rate"]
return self.algo.hashrate(
rate=float(hash_rate), unit=self.algo.unit.H
).into(self.algo.unit.default)
except KeyError:
pass
return None
async def _get_hashboards(
self, rpc_devs: dict | None = None, rpc_devdetails: dict | None = None
) -> list[HashBoard]:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_devs is not None:
if rpc_devs.get("DEVS"):
for board in rpc_devs["DEVS"]:
if board.get("ID") is not None:
try:
b_id = board["ID"]
hashboards[b_id].hashrate = self.algo.hashrate(
rate=float(board["MHS 20s"]), unit=self.algo.unit.MH
).into(self.algo.unit.default)
hashboards[b_id].chip_temp = board["tstemp-0"]
hashboards[b_id].temp = board["tstemp-1"]
hashboards[b_id].voltage = board["voltage"]
hashboards[b_id].active = board["Status"] == "Alive"
hashboards[b_id].missing = False
except KeyError:
pass
else:
logger.error(self, rpc_devs)
if rpc_devdetails is None:
try:
rpc_devdetails = await self.rpc.devdetails()
except APIError:
pass
if rpc_devdetails is not None:
if rpc_devdetails.get("DEVS"):
for board in rpc_devdetails["DEVS"]:
if board.get("ID") is not None:
try:
b_id = board["ID"]
hashboards[b_id].chips = board["chips-nr"]
except KeyError:
pass
else:
logger.error(self, rpc_devdetails)
return hashboards
async def _get_uptime(self, web_devs: dict | None = None) -> int | None:
if web_devs is None:
try:
web_devs = await self.web.devs()
except APIError:
pass
if web_devs is not None:
try:
uptime = int(web_devs["data"][0]["time"])
return uptime
except KeyError:
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/XBox/KDBox.py | pyasic/miners/goldshell/bfgminer/XBox/KDBox.py | # ------------------------------------------------------------------------------
# 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 GoldshellMiner
from pyasic.miners.device.models import KDBoxII, KDBoxPro
class GoldshellKDBoxII(GoldshellMiner, KDBoxII):
pass
class GoldshellKDBoxPro(GoldshellMiner, KDBoxPro):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/XBox/__init__.py | pyasic/miners/goldshell/bfgminer/XBox/__init__.py | # ------------------------------------------------------------------------------
# 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 .KDBox import GoldshellKDBoxII, GoldshellKDBoxPro
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/byte/byte.py | pyasic/miners/goldshell/bfgminer/byte/byte.py | # ------------------------------------------------------------------------------
# Copyright 2025 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.config import MinerConfig
from pyasic.data import Fan, MinerData
from pyasic.data.boards import HashBoard
from pyasic.data.pools import PoolMetrics, PoolUrl
from pyasic.device.algorithm import AlgoHashRateType, MinerAlgo
from pyasic.errors import APIError
from pyasic.miners.backends import GoldshellMiner
from pyasic.miners.data import (
DataFunction,
DataLocations,
DataOptions,
RPCAPICommand,
WebAPICommand,
)
from pyasic.miners.device.models import Byte
ALGORITHM_SCRYPT_NAME = "scrypt(LTC)"
ALGORITHM_ZKSNARK_NAME = "zkSNARK(ALEO)"
EXPECTED_CHIPS_PER_SCRYPT_BOARD = 5
EXPECTED_CHIPS_PER_ZKSNARK_BOARD = 3
GOLDSHELL_BYTE_DATA_LOC = DataLocations(
**{
str(DataOptions.MAC): DataFunction(
"_get_mac",
[WebAPICommand("web_setting", "setting")],
),
str(DataOptions.API_VERSION): DataFunction(
"_get_api_ver",
[WebAPICommand("web_setting", "version")],
),
str(DataOptions.FW_VERSION): DataFunction(
"_get_fw_ver",
[WebAPICommand("web_status", "status")],
),
str(DataOptions.HASHRATE): DataFunction(
"_get_hashrate",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.EXPECTED_HASHRATE): DataFunction(
"_get_expected_hashrate",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.HASHBOARDS): DataFunction(
"_get_hashboards",
[
RPCAPICommand("rpc_devs", "devs"),
RPCAPICommand("rpc_devdetails", "devdetails"),
],
),
str(DataOptions.FANS): DataFunction(
"_get_fans",
[RPCAPICommand("rpc_devs", "devs")],
),
str(DataOptions.POOLS): DataFunction(
"_get_pools",
[RPCAPICommand("rpc_pools", "pools")],
),
str(DataOptions.UPTIME): DataFunction(
"_get_uptime",
[WebAPICommand("web_devs", "devs")],
),
str(DataOptions.WATTAGE): DataFunction(
"_get_wattage",
[WebAPICommand("web_devs", "devs")],
),
}
)
class GoldshellByte(GoldshellMiner, Byte):
data_locations = GOLDSHELL_BYTE_DATA_LOC
supports_shutdown = False
supports_power_modes = False
web_devs: dict | None = None
async def get_data(
self,
allow_warning: bool = False,
include: list[str | DataOptions] | None = None,
exclude: list[str | DataOptions] | None = None,
) -> MinerData:
if self.web_devs is None:
try:
self.web_devs = await self.web.devs()
except APIError:
pass
scrypt_board_count = 0
zksnark_board_count = 0
for minfo in (self.web_devs or {}).get("minfos", []):
algo_name = minfo.get("name")
for _ in minfo.get("infos", []):
self.expected_hashboards += 1
self.expected_fans += 1
if algo_name == ALGORITHM_SCRYPT_NAME:
scrypt_board_count += 1
elif algo_name == ALGORITHM_ZKSNARK_NAME:
zksnark_board_count += 1
self.expected_chips = (EXPECTED_CHIPS_PER_SCRYPT_BOARD * scrypt_board_count) + (
EXPECTED_CHIPS_PER_ZKSNARK_BOARD * zksnark_board_count
)
if scrypt_board_count > 0 and zksnark_board_count == 0:
self.algo = MinerAlgo.SCRYPT # type: ignore[assignment]
elif zksnark_board_count > 0 and scrypt_board_count == 0:
self.algo = MinerAlgo.ZKSNARK # type: ignore[assignment]
data = await super().get_data(allow_warning, include, exclude)
data.expected_chips = self.expected_chips
return data
async def get_config(self) -> MinerConfig:
try:
pools = await self.web.pools()
except APIError:
return self.config or MinerConfig()
self.config = MinerConfig.from_goldshell_byte(pools.get("groups", []))
return self.config
async def _get_api_ver(self, web_setting: dict | None = None) -> str | None:
if web_setting is None:
try:
web_setting = await self.web.setting()
except APIError:
pass
if web_setting is not None:
try:
version = web_setting.get("version")
if version is not None:
self.api_ver = version.strip("v")
return self.api_ver
except KeyError:
pass
return self.api_ver
async def _get_expected_hashrate(
self, rpc_devs: dict | None = None
) -> AlgoHashRateType | None:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
total_hash_rate_mh = 0.0
if rpc_devs is not None:
for board in rpc_devs.get("DEVS", []):
algo_name = board.get("pool")
if algo_name == ALGORITHM_SCRYPT_NAME:
total_hash_rate_mh += (
self.algo.hashrate(
rate=float(board.get("estimate_hash_rate", 0)),
unit=self.algo.unit.H,
)
.into(self.algo.unit.MH)
.rate
)
elif algo_name == ALGORITHM_ZKSNARK_NAME:
total_hash_rate_mh += float(board.get("theory_hash", 0))
hash_rate = self.algo.hashrate(
rate=total_hash_rate_mh, unit=self.algo.unit.MH
).into(self.algo.unit.default)
return hash_rate
async def _get_hashrate(
self, rpc_devs: dict | None = None
) -> AlgoHashRateType | None:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
total_hash_rate_mh = 0.0
if rpc_devs is not None:
for board in rpc_devs.get("DEVS", []):
total_hash_rate_mh += float(board.get("MHS 20s", 0))
hash_rate = self.algo.hashrate(
rate=total_hash_rate_mh, unit=self.algo.unit.MH
).into(self.algo.unit.default)
return hash_rate
async def _get_pools(self, rpc_pools: dict | None = None) -> list[PoolMetrics]:
if rpc_pools is None:
try:
rpc_pools = await self.rpc.pools()
except APIError:
pass
pools_data = []
if rpc_pools is not None:
try:
pools = rpc_pools.get("POOLS", [])
for index, pool_info in enumerate(pools):
url = pool_info.get("URL")
pool_url = PoolUrl.from_str(url) if url else None
pool_data = PoolMetrics(
accepted=pool_info.get("Accepted"),
rejected=pool_info.get("Rejected"),
active=pool_info.get("Stratum Active"),
alive=pool_info.get("Status") == "Alive",
url=pool_url,
user=pool_info.get("User"),
index=index,
)
pools_data.append(pool_data)
except LookupError:
pass
return pools_data
async def _get_hashboards(
self, rpc_devs: dict | None = None, rpc_devdetails: dict | None = None
) -> list[HashBoard]:
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
hashboards = [
HashBoard(slot=i, expected_chips=self.expected_chips)
for i in range(self.expected_hashboards)
]
if rpc_devs is not None:
for board in rpc_devs.get("DEVS", []):
b_id = board["PGA"]
hashboards[b_id].hashrate = self.algo.hashrate(
rate=float(board["MHS 20s"]), unit=self.algo.unit.MH
).into(self.algo.unit.default)
hashboards[b_id].chip_temp = board["tstemp-1"]
hashboards[b_id].temp = board["tstemp-2"]
hashboards[b_id].voltage = board["voltage"]
hashboards[b_id].active = board["Status"] == "Alive"
hashboards[b_id].missing = False
algo_name = board.get("pool")
if algo_name == ALGORITHM_SCRYPT_NAME:
hashboards[b_id].expected_chips = EXPECTED_CHIPS_PER_SCRYPT_BOARD
elif algo_name == ALGORITHM_ZKSNARK_NAME:
hashboards[b_id].expected_chips = EXPECTED_CHIPS_PER_ZKSNARK_BOARD
if rpc_devdetails is None:
try:
rpc_devdetails = await self.rpc.devdetails()
except APIError:
pass
if rpc_devdetails is not None:
for board in rpc_devdetails.get("DEVS", []):
b_id = board["DEVDETAILS"]
hashboards[b_id].chips = board["chips-nr"]
return hashboards
async def _get_fans(self, rpc_devs: dict | None = None) -> list[Fan]:
if self.expected_fans is None:
return []
if rpc_devs is None:
try:
rpc_devs = await self.rpc.devs()
except APIError:
pass
fans_data = []
if rpc_devs is not None:
for board in rpc_devs.get("DEVS", []):
if board.get("PGA") is not None:
try:
b_id = board["PGA"]
fan_speed = board[f"fan{b_id}"]
fans_data.append(fan_speed)
except KeyError:
pass
fans = [Fan(speed=d) if d else Fan() for d in fans_data]
return fans
async def _get_uptime(self, web_devs: dict | None = None) -> int | None:
if web_devs is None:
try:
web_devs = await self.web.devs()
except APIError:
pass
if web_devs is not None:
try:
for minfo in (self.web_devs or {}).get("minfos", []):
for info in minfo.get("infos", []):
uptime = int(float(info["time"]))
return uptime
except KeyError:
pass
return None
async def _get_wattage(self, web_devs: dict | None = None) -> int | None:
if web_devs is None:
try:
web_devs = await self.web.devs()
except APIError:
pass
if web_devs is not None:
try:
for minfo in (self.web_devs or {}).get("minfos", []):
for info in minfo.get("infos", []):
wattage = int(float(info["power"]))
return wattage
except KeyError:
pass
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/goldshell/bfgminer/byte/__init__.py | pyasic/miners/goldshell/bfgminer/byte/__init__.py | # ------------------------------------------------------------------------------
# Copyright 2025 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 .byte import GoldshellByte
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/__init__.py | pyasic/miners/bitaxe/__init__.py | from .espminer import *
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/espminer/__init__.py | pyasic/miners/bitaxe/espminer/__init__.py | from .BM import *
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/espminer/BM/BM1397.py | pyasic/miners/bitaxe/espminer/BM/BM1397.py | from pyasic.miners.backends.bitaxe import BitAxe
from pyasic.miners.device.models.bitaxe import Max
class BitAxeMax(BitAxe, Max):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/espminer/BM/BM1366.py | pyasic/miners/bitaxe/espminer/BM/BM1366.py | from pyasic.miners.backends.bitaxe import BitAxe
from pyasic.miners.device.models.bitaxe import Ultra
class BitAxeUltra(BitAxe, Ultra):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/espminer/BM/__init__.py | pyasic/miners/bitaxe/espminer/BM/__init__.py | from .BM1366 import BitAxeUltra
from .BM1368 import BitAxeSupra
from .BM1370 import BitAxeGamma
from .BM1397 import BitAxeMax
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/espminer/BM/BM1370.py | pyasic/miners/bitaxe/espminer/BM/BM1370.py | from pyasic.miners.backends.bitaxe import BitAxe
from pyasic.miners.device.models.bitaxe import Gamma
class BitAxeGamma(BitAxe, Gamma):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/miners/bitaxe/espminer/BM/BM1368.py | pyasic/miners/bitaxe/espminer/BM/BM1368.py | from pyasic.miners.backends.bitaxe import BitAxe
from pyasic.miners.device.models.bitaxe import Supra
class BitAxeSupra(BitAxe, Supra):
pass
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/ssh/braiins_os.py | pyasic/ssh/braiins_os.py | from pyasic import settings
from pyasic.ssh.base import BaseSSH
class BOSMinerSSH(BaseSSH):
def __init__(self, ip: str):
"""
Initialize a BOSMinerSSH instance.
Args:
ip (str): The IP address of the BOSMiner device.
"""
super().__init__(ip)
self.pwd = settings.get("default_bosminer_ssh_password", "root")
async def get_board_info(self):
"""
Retrieve information about the BOSMiner board.
Returns:
str: Information about the BOSMiner board.
"""
return await self.send_command("bosminer model -d")
async def fault_light_on(self):
"""
Turn on the fault light of the BOSMiner device.
Returns:
str: Confirmation message after turning on the fault light.
"""
return await self.send_command("miner fault_light on")
async def fault_light_off(self):
"""
Turn off the fault light of the BOSMiner device.
Returns:
str: Confirmation message after turning off the fault light.
"""
return await self.send_command("miner fault_light off")
async def restart_bosminer(self):
"""
Restart the BOSMiner service on the device.
Returns:
str: Confirmation message after restarting the BOSMiner service.
"""
return await self.send_command("/etc/init.d/bosminer restart")
async def reboot(self):
"""
Reboot the BOSMiner device.
Returns:
str: Confirmation message after initiating the reboot process.
"""
return await self.send_command("/sbin/reboot")
async def get_config_file(self):
"""
Retrieve the configuration file of BOSMiner.
Returns:
str: Content of the BOSMiner configuration file.
"""
return await self.send_command("cat /etc/bosminer.toml")
async def get_network_config(self):
"""
Retrieve the network configuration of the BOSMiner device.
Returns:
str: Content of the network configuration file.
"""
return await self.send_command("cat /etc/config/network")
async def get_hostname(self):
"""
Retrieve the hostname of the BOSMiner device.
Returns:
str: Hostname of the BOSMiner device.
"""
return await self.send_command("cat /proc/sys/kernel/hostname")
async def get_led_status(self):
"""
Retrieve the status of the LED on the BOSMiner device.
Returns:
str: Status of the LED.
"""
return await self.send_command("cat /sys/class/leds/'Red LED'/delay_off")
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/ssh/__init__.py | pyasic/ssh/__init__.py | # ------------------------------------------------------------------------------
# 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 .antminer import AntminerModernSSH
from .braiins_os import BOSMinerSSH
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/ssh/base.py | pyasic/ssh/base.py | import asyncio
import logging
import asyncssh
class BaseSSH:
def __init__(self, ip: str) -> None:
self.ip = ip
self.pwd: str | None = None
self.username: str = "root"
self.port: int = 22
async def _get_connection(self) -> asyncssh.connect:
"""Create a new asyncssh connection"""
try:
conn = await asyncssh.connect(
str(self.ip),
port=self.port,
known_hosts=None,
username=self.username,
password=self.pwd,
server_host_key_algs=["ssh-rsa"],
)
return conn
except asyncssh.misc.PermissionDenied as e:
raise ConnectionRefusedError from e
except Exception as e:
raise ConnectionError from e
async def send_command(self, cmd: str) -> str | None:
"""Send an ssh command to the miner"""
try:
conn = await asyncio.wait_for(self._get_connection(), timeout=10)
except (ConnectionError, asyncio.TimeoutError):
return None
try:
async with conn:
resp = await conn.run(cmd)
result = str(max(resp.stdout, resp.stderr, key=len))
return result
except Exception as e:
logging.error(f"{self} command {cmd} error: {e}")
return None
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/ssh/antminer.py | pyasic/ssh/antminer.py | from pyasic import settings
from pyasic.ssh.base import BaseSSH
class AntminerModernSSH(BaseSSH):
"""
Initialize an AntminerModernSSH instance.
Args:
ip (str): The IP address of the Antminer device.
"""
def __init__(self, ip: str):
super().__init__(ip)
self.pwd = settings.get("default_antminer_ssh_password", "root")
self.username = "miner"
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/config/temperature.py | pyasic/config/temperature.py | # ------------------------------------------------------------------------------
# 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 __future__ import annotations
from pyasic.config.base import MinerConfigValue
class TemperatureConfig(MinerConfigValue):
target: int | None = None
hot: int | None = None
danger: int | None = None
@classmethod
def default(cls):
return cls()
def as_bosminer(self) -> dict:
temp_cfg = {}
if self.target is not None:
temp_cfg["target_temp"] = self.target
if self.hot is not None:
temp_cfg["hot_temp"] = self.hot
if self.danger is not None:
temp_cfg["dangerous_temp"] = self.danger
if len(temp_cfg) == 0:
return {}
return {"temp_control": temp_cfg}
def as_epic(self) -> dict:
temps_config: dict = {"temps": {}, "fans": {"Auto": {}}}
if self.target is not None:
temps_config["fans"]["Auto"]["Target Temperature"] = self.target
else:
temps_config["fans"]["Auto"]["Target Temperature"] = 60
if self.danger is not None:
temps_config["temps"]["critical"] = self.danger
if self.hot is not None:
temps_config["temps"]["shutdown"] = self.hot
return temps_config
def as_luxos(self) -> dict:
return {"tempctrlset": [self.target or "", self.hot or "", self.danger or ""]}
def as_vnish(self) -> dict:
return {"misc": {"restart_temp": self.danger}}
@classmethod
def from_dict(cls, dict_conf: dict | None) -> TemperatureConfig:
if dict_conf is None:
return cls()
return cls(
target=dict_conf.get("target"),
hot=dict_conf.get("hot"),
danger=dict_conf.get("danger"),
)
@classmethod
def from_bosminer(cls, toml_conf: dict) -> TemperatureConfig:
temp_control = toml_conf.get("temp_control")
if temp_control is not None:
return cls(
target=temp_control.get("target_temp"),
hot=temp_control.get("hot_temp"),
danger=temp_control.get("dangerous_temp"),
)
return cls()
@classmethod
def from_epic(cls, web_conf: dict) -> TemperatureConfig:
try:
dangerous_temp = web_conf["Misc"]["Critical Temp"]
except KeyError:
dangerous_temp = None
try:
hot_temp = web_conf["Misc"]["Shutdown Temp"]
except KeyError:
hot_temp = None
# Need to do this in two blocks to avoid KeyError if one is missing
try:
target_temp = web_conf["Fans"]["Fan Mode"]["Auto"]["Target Temperature"]
except KeyError:
target_temp = None
return cls(target=target_temp, hot=hot_temp, danger=dangerous_temp)
@classmethod
def from_vnish(cls, web_settings: dict) -> TemperatureConfig:
try:
dangerous_temp = web_settings["misc"]["restart_temp"]
except KeyError:
dangerous_temp = None
try:
if web_settings["miner"]["cooling"]["mode"]["name"] == "auto":
return cls(
target=web_settings["miner"]["cooling"]["mode"]["param"],
danger=dangerous_temp,
)
except KeyError:
pass
return cls()
@classmethod
def from_boser(cls, grpc_miner_conf: dict) -> TemperatureConfig:
try:
temperature_conf = grpc_miner_conf["temperature"]
except KeyError:
return cls.default()
root_key = None
for key in ["auto", "manual", "disabled"]:
if key in temperature_conf.keys():
root_key = key
break
if root_key is None:
return cls.default()
conf = {}
keys = temperature_conf[root_key].keys()
if "targetTemperature" in keys:
conf["target"] = int(
temperature_conf[root_key]["targetTemperature"]["degreeC"]
)
if "hotTemperature" in keys:
conf["hot"] = int(temperature_conf[root_key]["hotTemperature"]["degreeC"])
if "dangerousTemperature" in keys:
conf["danger"] = int(
temperature_conf[root_key]["dangerousTemperature"]["degreeC"]
)
return cls(**conf)
return cls.default()
@classmethod
def from_luxos(cls, rpc_tempctrl: dict) -> TemperatureConfig:
try:
tempctrl_config = rpc_tempctrl["TEMPCTRL"][0]
return cls(
target=tempctrl_config.get("Target"),
hot=tempctrl_config.get("Hot"),
danger=tempctrl_config.get("Dangerous"),
)
except LookupError:
pass
return cls.default()
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
UpstreamData/pyasic | https://github.com/UpstreamData/pyasic/blob/820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3/pyasic/config/fans.py | pyasic/config/fans.py | # ------------------------------------------------------------------------------
# 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 __future__ import annotations
from typing import TypeVar
from pydantic import Field
from pyasic.config.base import MinerConfigOption, MinerConfigValue
class FanModeNormal(MinerConfigValue):
mode: str = Field(init=False, default="normal")
minimum_fans: int = 1
minimum_speed: int = 0
@classmethod
def from_dict(cls, dict_conf: dict) -> FanModeNormal:
cls_conf = {}
if dict_conf.get("minimum_fans") is not None:
cls_conf["minimum_fans"] = dict_conf["minimum_fans"]
if dict_conf.get("minimum_speed") is not None:
cls_conf["minimum_speed"] = dict_conf["minimum_speed"]
return cls(**cls_conf)
@classmethod
def from_vnish(cls, web_cooling_settings: dict) -> FanModeNormal:
cls_conf = {}
if web_cooling_settings.get("fan_min_count") is not None:
cls_conf["minimum_fans"] = web_cooling_settings["fan_min_count"]
if web_cooling_settings.get("fan_min_duty") is not None:
cls_conf["minimum_speed"] = web_cooling_settings["fan_min_duty"]
return cls(**cls_conf)
@classmethod
def from_bosminer(cls, toml_fan_conf: dict):
cls_conf = {}
if toml_fan_conf.get("min_fans") is not None:
cls_conf["minimum_fans"] = toml_fan_conf["min_fans"]
return cls(**cls_conf)
def as_am_modern(self) -> dict:
return {"bitmain-fan-ctrl": False, "bitmain-fan-pwn": "100"}
def as_hiveon_modern(self) -> dict:
return {"bitmain-fan-ctrl": False, "bitmain-fan-pwn": "100"}
def as_elphapex(self) -> dict:
return {"fc-fan-ctrl": False, "fc-fan-pwn": "100"}
def as_bosminer(self) -> dict:
return {
"temp_control": {"mode": "auto"},
"fan_control": {"min_fans": self.minimum_fans},
}
def as_epic(self) -> dict:
return {
"fans": {
"Auto": {
"Idle Speed": (
self.minimum_speed if not self.minimum_speed == 0 else 100
)
}
}
}
def as_mara(self) -> dict:
return {
"general-config": {"environment-profile": "AirCooling"},
"advance-config": {
"override-fan-control": False,
"fan-fixed-percent": 0,
},
}
def as_espminer(self) -> dict:
return {"autoFanspeed": 1}
def as_luxos(self) -> dict:
return {"fanset": {"speed": -1, "min_fans": self.minimum_fans}}
def as_vnish(self) -> dict:
return {
"cooling": {
"fan_min_count": self.minimum_fans,
"fan_min_duty": self.minimum_speed,
"mode": {
"name": "auto",
"param": None, # Target temp, must be set later...
},
}
}
class FanModeManual(MinerConfigValue):
mode: str = Field(init=False, default="manual")
speed: int = 100
minimum_fans: int = 1
@classmethod
def from_dict(cls, dict_conf: dict) -> FanModeManual:
cls_conf = {}
if dict_conf.get("speed") is not None:
cls_conf["speed"] = dict_conf["speed"]
if dict_conf.get("minimum_fans") is not None:
cls_conf["minimum_fans"] = dict_conf["minimum_fans"]
return cls(**cls_conf)
@classmethod
def from_bosminer(cls, toml_fan_conf: dict) -> FanModeManual:
cls_conf = {}
if toml_fan_conf.get("min_fans") is not None:
cls_conf["minimum_fans"] = toml_fan_conf["min_fans"]
if toml_fan_conf.get("speed") is not None:
cls_conf["speed"] = toml_fan_conf["speed"]
return cls(**cls_conf)
@classmethod
def from_vnish(cls, web_cooling_settings: dict) -> FanModeManual:
cls_conf = {}
if web_cooling_settings.get("fan_min_count") is not None:
cls_conf["minimum_fans"] = web_cooling_settings["fan_min_count"]
if web_cooling_settings["mode"].get("param") is not None:
cls_conf["speed"] = web_cooling_settings["mode"]["param"]
return cls(**cls_conf)
def as_am_modern(self) -> dict:
return {"bitmain-fan-ctrl": True, "bitmain-fan-pwm": str(self.speed)}
def as_hiveon_modern(self) -> dict:
return {"bitmain-fan-ctrl": True, "bitmain-fan-pwm": str(self.speed)}
def as_elphapex(self) -> dict:
return {"fc-fan-ctrl": True, "fc-fan-pwm": str(self.speed)}
def as_bosminer(self) -> dict:
return {
"temp_control": {"mode": "manual"},
"fan_control": {"min_fans": self.minimum_fans, "speed": self.speed},
}
def as_auradine(self) -> dict:
return {"fan": {"percentage": self.speed}}
def as_epic(self) -> dict:
return {"fans": {"Manual": {"speed": self.speed}}}
def as_mara(self) -> dict:
return {
"general-config": {"environment-profile": "AirCooling"},
"advance-config": {
"override-fan-control": True,
"fan-fixed-percent": self.speed,
},
}
def as_espminer(self) -> dict:
return {"autoFanspeed": 0, "fanspeed": self.speed}
def as_luxos(self) -> dict:
return {"fanset": {"speed": self.speed, "min_fans": self.minimum_fans}}
def as_vnish(self) -> dict:
return {
"cooling": {
"fan_min_count": self.minimum_fans,
"fan_min_duty": self.speed,
"mode": {
"name": "manual",
"param": self.speed, # Speed value
},
}
}
class FanModeImmersion(MinerConfigValue):
mode: str = Field(init=False, default="immersion")
@classmethod
def from_dict(cls, dict_conf: dict | None) -> FanModeImmersion:
return cls()
def as_am_modern(self) -> dict:
return {"bitmain-fan-ctrl": True, "bitmain-fan-pwm": "0"}
def as_hiveon_modern(self) -> dict:
return {"bitmain-fan-ctrl": True, "bitmain-fan-pwm": "0"}
def as_elphapex(self) -> dict:
return {"fc-fan-ctrl": True, "fc-fan-pwm": "0"}
def as_bosminer(self) -> dict:
return {
"fan_control": {"min_fans": 0},
}
def as_auradine(self) -> dict:
return {"fan": {"percentage": 0}}
def as_mara(self) -> dict:
return {"general-config": {"environment-profile": "OilImmersionCooling"}}
def as_luxos(self) -> dict:
return {"fanset": {"speed": 0, "min_fans": 0}}
def as_vnish(self) -> dict:
return {"cooling": {"mode": {"name": "immers"}}}
class FanModeConfig(MinerConfigOption):
normal = FanModeNormal
manual = FanModeManual
immersion = FanModeImmersion
@classmethod
def default(cls):
return cls.normal()
@classmethod
def from_dict(cls, dict_conf: dict | None):
if dict_conf is None:
return cls.default()
mode = dict_conf.get("mode")
if mode is None:
return cls.default()
cls_attr = getattr(cls, mode)
if cls_attr is not None:
return cls_attr().from_dict(dict_conf)
@classmethod
def from_am_modern(cls, web_conf: dict):
if web_conf.get("bitmain-fan-ctrl") is not None:
fan_manual = web_conf["bitmain-fan-ctrl"]
if fan_manual:
speed = int(web_conf["bitmain-fan-pwm"])
if speed == 0:
return cls.immersion()
return cls.manual(speed=speed)
else:
return cls.normal()
else:
return cls.default()
@classmethod
def from_hiveon_modern(cls, web_conf: dict):
if web_conf.get("bitmain-fan-ctrl") is not None:
fan_manual = web_conf["bitmain-fan-ctrl"]
if fan_manual:
speed = int(web_conf["bitmain-fan-pwm"])
if speed == 0:
return cls.immersion()
return cls.manual(speed=speed)
else:
return cls.normal()
else:
return cls.default()
@classmethod
def from_elphapex(cls, web_conf: dict):
if web_conf.get("fc-fan-ctrl") is not None:
fan_manual = web_conf["fc-fan-ctrl"]
if fan_manual:
speed = int(web_conf["fc-fan-pwm"])
if speed == 0:
return cls.immersion()
return cls.manual(speed=speed)
else:
return cls.normal()
else:
return cls.default()
@classmethod
def from_epic(cls, web_conf: dict):
try:
fan_mode = web_conf["Fans"]["Fan Mode"]
if fan_mode.get("Manual") is not None:
return cls.manual(speed=fan_mode.get("Manual"))
else:
return cls.normal()
except KeyError:
return cls.default()
@classmethod
def from_bosminer(cls, toml_conf: dict):
try:
mode = toml_conf["temp_control"]["mode"]
fan_config = toml_conf.get("fan_control", {})
if mode == "auto":
return cls.normal().from_bosminer(fan_config)
elif mode == "manual":
if toml_conf.get("fan_control"):
return cls.manual().from_bosminer(fan_config)
return cls.manual()
elif mode == "disabled":
return cls.immersion()
except KeyError:
pass
try:
min_fans = toml_conf["fan_control"]["min_fans"]
except KeyError:
return cls.default()
if min_fans == 0:
return cls.immersion()
return cls.normal(minimum_fans=min_fans)
@classmethod
def from_vnish(cls, web_settings: dict):
try:
mode = web_settings["miner"]["cooling"]["mode"]["name"]
except LookupError:
return cls.default()
if mode == "auto":
return cls.normal().from_vnish(web_settings["miner"]["cooling"])
elif mode == "manual":
return cls.manual().from_vnish(web_settings["miner"]["cooling"])
elif mode == "immers":
return cls.immersion()
@classmethod
def from_boser(cls, grpc_miner_conf: dict):
try:
temperature_conf = grpc_miner_conf["temperature"]
except LookupError:
return cls.default()
keys = temperature_conf.keys()
if "auto" in keys:
if "minimumRequiredFans" in keys:
return cls.normal(minimum_fans=temperature_conf["minimumRequiredFans"])
return cls.normal()
if "manual" in keys:
conf = {}
if "fanSpeedRatio" in temperature_conf["manual"].keys():
conf["speed"] = int(temperature_conf["manual"]["fanSpeedRatio"])
if "minimumRequiredFans" in keys:
conf["minimum_fans"] = int(temperature_conf["minimumRequiredFans"])
return cls.manual(**conf)
if "disabled" in keys:
conf = {}
if "fanSpeedRatio" in temperature_conf["disabled"].keys():
conf["speed"] = int(temperature_conf["disabled"]["fanSpeedRatio"])
return cls.manual(**conf)
return cls.default()
@classmethod
def from_auradine(cls, web_fan: dict):
try:
fan_data = web_fan["Fan"][0]
fan_1_max = fan_data["Max"]
fan_1_target = fan_data["Target"]
return cls.manual(speed=round((fan_1_target / fan_1_max) * 100))
except LookupError:
pass
return cls.default()
@classmethod
def from_mara(cls, web_config: dict):
try:
mode = web_config["general-config"]["environment-profile"]
if mode == "AirCooling":
if web_config["advance-config"]["override-fan-control"]:
return cls.manual(
speed=web_config["advance-config"]["fan-fixed-percent"]
)
return cls.normal()
return cls.immersion()
except LookupError:
pass
return cls.default()
@classmethod
def from_espminer(cls, web_system_info: dict):
if web_system_info["autofanspeed"] == 1:
return cls.normal()
else:
return cls.manual(speed=web_system_info["fanspeed"])
@classmethod
def from_luxos(cls, rpc_fans: dict, rpc_tempctrl: dict):
try:
mode = rpc_tempctrl["TEMPCTRL"][0]["Mode"]
if mode == "Manual":
speed = rpc_fans["FANS"][0]["Speed"]
min_fans = rpc_fans["FANCTRL"][0]["MinFans"]
if min_fans == 0 and speed == 0:
return cls.immersion()
return cls.manual(
speed=speed,
minimum_fans=min_fans,
)
return cls.normal(
minimum_fans=rpc_fans["FANCTRL"][0]["MinFans"],
)
except LookupError:
pass
return cls.default()
FanMode = TypeVar(
"FanMode",
bound=FanModeNormal | FanModeManual | FanModeImmersion,
)
| python | Apache-2.0 | 820d2aafdaa6bf2b046f94c017bf7ea58b7c50f3 | 2026-01-05T07:14:50.237218Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.