-
Notifications
You must be signed in to change notification settings - Fork 86
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
base: master
Are you sure you want to change the base?
Conversation
Add set_preset(name) method to LUXMiner for switching mining presets by name. Validates preset against available presets before making RPC calls. Refactored the ATM disable/re-enable logic shared by set_preset() and set_power_limit() into a private _switch_profile() helper. This fixes a bug in set_power_limit() where ATM could stay disabled if the profile switch failed (the re-enable was inside the same try block as the switch). The new _switch_profile() uses a finally block to ensure ATM is always re-enabled if it was disabled, regardless of whether the profile switch succeeds or fails.
Rename public API to match LuxOS terminology. Accept flexible input: "190", "190mhz", or "190MHz" all resolve to the correct firmware profile name.
for more information, see https://pre-commit.ci
| pass | ||
| return None | ||
|
|
||
| async def _switch_profile(self, profile_name: str) -> dict: |
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.
Created helper method that disables and re-enables ATM so don’t duplicate logic in methods that need to do this
| ) | ||
|
|
||
| @staticmethod | ||
| def _match_profile_name(name: str, profile_names: list[str]) -> str | None: |
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 accept 190MHz, 190mhz, or 190
| result = await self.rpc.profileset(new_preset) | ||
| if re_enable_atm: | ||
| await self.rpc.atmset(enabled=True) | ||
| result = await self._switch_profile(new_preset) |
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.
Updated set_power_limit to use helper method _switch_profile
|
I went back and forth between naming it |
|
Set profile is fine, I don't think it matters. In theory you could add them both and have one point to the other if you want. |
Summary
Adds
set_profile(name: str) -> boolmethod to the LuxOS backend for programmatic switching between profiles (e.g.,190MHz,415MHz,565MHz).Follows same pattern as
set_power_limit()method, including ATM (Advanced Thermal Management) handling.Motivation
I want to be able to select a profile in Home Assistant using hass-miner. Currently, it only allows choosing a wattage. Adding
set_profileis necessary for hass-miner to be able to select a profile.Changes
pyasic/miners/backends/luxminer.py
pyasic/miners/base.py
Tests
a. Switches profile with ATM enabled (disable → switch → re-enable)
b. Switches profile with ATM disabled (no ATM toggling)
c. Returns False for invalid profile name (no RPC call made)
d. Returns True + logs warning when ATM re-enable fails
e. Fuzzy matches case-insensitive input ("190mhz" → "190MHz")
f. Fuzzy matches number-only input ("190" → "190MHz")
g. Returns False when rpc.profileset() raises an exception
Usage
Testing