Fix DG-Home1 Elphapex detection and harden hashboard parsing#429
Open
purcell-lab wants to merge 4 commits into
Open
Fix DG-Home1 Elphapex detection and harden hashboard parsing#429purcell-lab wants to merge 4 commits into
purcell-lab wants to merge 4 commits into
Conversation
- factory.py: uppercase ELPHAPEX lookup keys (case-insensitive lookup); add DG-HOME1 alias; get_miner_model_elphapex falls back to type/model/hostname from get_system_info.cgi and to INFO.type/INFO.model/INFO.miner_version from stats.cgi; new _normalize_elphapex_model helper maps 'DG-Home1' / 'DG-Home1_V1.0.5' to 'DG1-Home'. - backends/elphapex.py _get_hashboards: derive expected_hashboards from STATS[0].chain_num when None (prevents range(None) TypeError); skip out-of-range board indices; guard chip_temp averaging against empty/non-numeric temp_chip entries; use .get() throughout; set hb.missing=True when asic_num == 0. Closes UpstreamData#428. Refs UpstreamData#311.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 37 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
CodeFactor flagged the previous implementation as a Complex Method (cyclomatic complexity 23). Split into small focused helpers: - _resolve_expected_hashboards: derive slot count from stats.cgi when expected_hashboards is None on partially-supported devices. - _iter_stats_chains: safe access to STATS[0].chain. - _apply_chain_to_board: populate one HashBoard from a chain dict. - _set_board_hashrate / _average_pcb_temp / _average_chip_temp: isolated, individually testable building blocks. _get_hashboards itself drops from cyclomatic complexity 23 (radon: D 30) to 6 (radon: B 6); no method in the file exceeds 9. Behaviour is preserved: same outputs on the DG-Home1 stats payload, same fallback to chain_num for partial-support, same APIError-safe path when stats are unavailable. Added defensive isinstance/type guards so malformed payloads (missing STATS, non-list 'chain', non-int 'index', non-list temp arrays) no longer raise.
Codacy flagged 3 multi-line docstrings (D213: 'Multi-line docstring summary should start at the second line'). Move the summary line below the opening triple-quote on: - ElphapexMiner._get_hashboards - ElphapexMiner._resolve_expected_hashboards - ElphapexMiner._average_chip_temp - MinerFactory._normalize_elphapex_model Also adds short single-line docstrings to _set_board_hashrate and _average_pcb_temp for consistency with the surrounding helpers.
Codacy enforces both pydocstyle D212 ('summary on first line') and D213
('summary on second line'), which are mutually exclusive for any
multi-line docstring. Collapse the four affected docstrings to single
lines and move the elaboration into adjacent comments. No behaviour
change; ruff format and ruff check both clean; existing tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the "partially supported" warning and
TypeErroron Elphapex DG-Home1 miners (firmware DG-Home1_V1.0.5).Closes #428. Refs #311.
Problem
On pyasic 0.79.0, scanning a DG-Home1 emits:
…and any code path that touches hashboards raises
APIErrorwrapping aTypeError: 'NoneType' object cannot be interpreted as an integerfromrange(self.expected_hashboards)inElphapexMiner._get_hashboards.Two underlying issues:
get_miner_model_elphapexonly readsweb_json_data["minertype"]from/cgi-bin/get_system_info.cgi. DG-Home1 firmware V1.0.5 doesn't expose that key. The device'sINFO.typefrom/cgi-bin/stats.cgiis"DG-Home1", but the lookup table key is"DG1-Home"— and_select_miner_from_classesuppercases the model before lookup, so even the existing"DG1-Home"key would never match ("DG1-Home".upper() == "DG1-HOME").expected_hashboardsisNone, andrange(None)raisesTypeError. Even with the correct model resolved, DG-Home1 returns 3 empty chains and 1 populated one; the existing parser also divides bylen(chip_temp_data)without guarding the empty case.Fix
pyasic/miners/factory.pyMinerTypes.ELPHAPEXare now uppercase ("DG1-HOME") to match the case-insensitive lookup in_select_miner_from_classes."DG-HOME1"is added as an alias so the raw firmware string also resolves directly.get_miner_model_elphapexnow:minertype, then falls back totype,model,hostnamefrom/cgi-bin/get_system_info.cgi./cgi-bin/stats.cgiand readsINFO.type/INFO.model/INFO.miner_version._normalize_elphapex_model(strips firmware-version suffix like_V1.0.5, remaps"DG-Home1"→"DG1-Home").pyasic/miners/backends/elphapex.py_get_hashboardsis hardened:web_statsfirst, then derivesexpected_hashboardsfromSTATS[0].chain_num(orlen(chain)) when the device is partially supported. PreventsTypeErrorfromrange(None).chip_tempaverage against emptytemp_chiplists (the original divide-by-zero) and against non-numeric entries..get()forsn,asic_num,temp_pcb,temp_chipso a missing key on partial firmware no longer aborts the whole loop.hb.missing = Truewhenasic_num == 0, so the 3 unpopulated chains on DG-Home1 are reported as missing rather than as healthy zero-chip boards.Verification
Inline checks against the captured DG-Home1
stats.cgipayload (from #311) — 1 populated chain at index 3, 3 empty chains:Normaliser table:
DG-Home1DG1-HomeDG-HOME1DG1-HomeDG-Home1_V1.0.5DG1-HomeDG1-HomeDG1-HomeDG1+DG1+DG1DG1All map to
ElphapexDG1Homevia the lookup table after upper-casing.Existing test suite passes (
25 passed, network/local/rpc test groups skipped per their usual harness).ruff checkandruff format --checkboth clean on the touched files.Notes / out of scope
miner.rpcisNone, so RPC-based methods (devdetails,version) remain unavailable. Documented in the API reference comment on Update request: DG-Home1 still partially supported in pyasic 0.79.0 #428.expected_chips=120already matches the live device (asic_num=120on chain 3), so no model-class changes were needed once detection works.setworkmode.cgi/getworkmode.cgiintegration is intentionally not included here — happy to follow up in a separate PR if desired.