-
Notifications
You must be signed in to change notification settings - Fork 90
Add set_profile method to LuxOS
#409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wilfredallyn
wants to merge
6
commits into
UpstreamData:master
Choose a base branch
from
wilfredallyn:feat/set-preset
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
65c78ea
feat: add set_preset() and refactor ATM toggle into _switch_profile()
wilfredallyn cbfa008
feat: add set_preset() stub and tests (RED)
wilfredallyn 3c9cf37
feat: implement set_preset() for LuxOS backend (GREEN)
wilfredallyn f1271b6
feat: rename set_preset() to set_profile() with fuzzy matching
wilfredallyn 4e9fa59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 456101c
refactor: remove ATM disable/re-enable from profile switching
wilfredallyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Empty file.
99 changes: 99 additions & 0 deletions
99
tests/miners_tests/backends_tests/luxminer_tests/test_set_preset.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """Tests for LuxOS set_profile() method.""" | ||
|
|
||
| import unittest | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| from pyasic.config.mining.presets import MiningPreset | ||
|
|
||
|
|
||
| def _make_preset(name, power=1000, frequency=400, voltage=8.9): | ||
| """Helper to create a MiningPreset.""" | ||
| return MiningPreset( | ||
| name=name, | ||
| power=power, | ||
| hashrate=80.0, | ||
| tuned=True, | ||
| modded_psu=False, | ||
| frequency=frequency, | ||
| voltage=voltage, | ||
| ) | ||
|
|
||
|
|
||
| def _make_config( | ||
| active_preset_name="415MHz", available_preset_names=("190MHz", "415MHz", "565MHz") | ||
| ): | ||
| """Helper to create a mock config with presets.""" | ||
| presets = [_make_preset(n) for n in available_preset_names] | ||
| active = next((p for p in presets if p.name == active_preset_name), presets[0]) | ||
| config = MagicMock() | ||
| config.mining_mode.available_presets = presets | ||
| config.mining_mode.active_preset = active | ||
| return config | ||
|
|
||
|
|
||
| class TestSetProfile(unittest.IsolatedAsyncioTestCase): | ||
| """Test LuxOS set_profile() behavior.""" | ||
|
|
||
| def _make_miner(self, config=None, profileset_result=None): | ||
| """Create a mock LuxOS miner with controllable behavior.""" | ||
| from pyasic.miners.backends.luxminer import LUXMiner | ||
|
|
||
| miner = LUXMiner.__new__(LUXMiner) | ||
| miner.rpc = MagicMock() | ||
| miner.rpc.profileset = AsyncMock( | ||
| return_value=profileset_result or {"PROFILE": [{"Profile": "415MHz"}]} | ||
| ) | ||
| miner.get_config = AsyncMock(return_value=config or _make_config()) | ||
| miner.ip = "192.168.1.237" | ||
| return miner | ||
|
|
||
| async def test_switches_profile(self): | ||
| """Should call profileset directly (ATM handled natively by LuxOS).""" | ||
| miner = self._make_miner( | ||
| profileset_result={"PROFILE": [{"Profile": "190MHz"}]}, | ||
| ) | ||
|
|
||
| result = await miner.set_profile("190MHz") | ||
|
|
||
| self.assertTrue(result) | ||
| miner.rpc.profileset.assert_called_once_with("190MHz") | ||
|
|
||
| async def test_invalid_preset_name_returns_false(self): | ||
| """Should return False when preset name doesn't exist.""" | ||
| miner = self._make_miner() | ||
|
|
||
| result = await miner.set_profile("nonexistent_profile") | ||
|
|
||
| self.assertFalse(result) | ||
| miner.rpc.profileset.assert_not_called() | ||
|
|
||
| async def test_fuzzy_match_case_insensitive(self): | ||
| """Should match preset name case-insensitively.""" | ||
| miner = self._make_miner( | ||
| profileset_result={"PROFILE": [{"Profile": "190MHz"}]}, | ||
| ) | ||
|
|
||
| result = await miner.set_profile("190mhz") | ||
|
|
||
| self.assertTrue(result) | ||
| miner.rpc.profileset.assert_called_once_with("190MHz") | ||
|
|
||
| async def test_fuzzy_match_number_only(self): | ||
| """Should match '190' to '190MHz'.""" | ||
| miner = self._make_miner( | ||
| profileset_result={"PROFILE": [{"Profile": "190MHz"}]}, | ||
| ) | ||
|
|
||
| result = await miner.set_profile("190") | ||
|
|
||
| self.assertTrue(result) | ||
| miner.rpc.profileset.assert_called_once_with("190MHz") | ||
|
|
||
| async def test_profileset_failure_returns_false(self): | ||
| """If RPC profileset fails, should return False.""" | ||
| miner = self._make_miner() | ||
| miner.rpc.profileset.side_effect = Exception("RPC error") | ||
|
|
||
| result = await miner.set_profile("190MHz") | ||
|
|
||
| self.assertFalse(result) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When calling
set_profile, will accept190MHz,190mhz, or190