Skip to content

Add set_profile method to LuxOS#409

Open
wilfredallyn wants to merge 6 commits intoUpstreamData:masterfrom
wilfredallyn:feat/set-preset
Open

Add set_profile method to LuxOS#409
wilfredallyn wants to merge 6 commits intoUpstreamData:masterfrom
wilfredallyn:feat/set-preset

Conversation

@wilfredallyn
Copy link
Contributor

@wilfredallyn wilfredallyn commented Feb 10, 2026

Summary

Adds set_profile(name: str) -> bool method to the LuxOS backend for programmatic switching between profiles (e.g., 190MHz, 415MHz, 565MHz).

Calls rpc.profileset() directly — since LuxOS Feb 2025, profileset with update_atm=true (the default) atomically updates ATM MaxProfile and ramps immediately. No need to manually disable/re-enable ATM.

Also simplifies set_power_limit() to use rpc.profileset() directly for the same reason.

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_profile is necessary for hass-miner to be able to select a profile.

Changes

pyasic/miners/backends/luxminer.py

  • Added set_profile(name: str) -> bool method to LUXMiner
  • Validates profile name against available profiles with fuzzy matching: "190", "190mhz", and "190MHz" all resolve correctly
  • Calls rpc.profileset() directly (LuxOS handles ATM natively)
  • Simplified set_power_limit() to also call rpc.profileset() directly (removed ATM disable/re-enable logic)
  • Returns False on invalid profile name or RPC failure
  • Re-raises APIError for callers to handle

pyasic/miners/base.py

  • Added set_profile(name: str) -> bool stub to MinerProtocol base class (returns False)
  • Follows the existing convention for set_power_limit() and other control methods

Tests

  • Added 5 tests in tests/miners_tests/backends_tests/luxminer_tests/test_set_preset.py:
    a. Switches profile (calls profileset directly)
    b. Returns False for invalid profile name (no RPC call made)
    c. Fuzzy matches case-insensitive input ("190mhz" → "190MHz")
    d. Fuzzy matches number-only input ("190" → "190MHz")
    e. Returns False when rpc.profileset() raises an exception

Usage

from pyasic import get_miner

miner = await get_miner("192.168.1.237")
success = await miner.set_profile("190")

Testing

python -m unittest tests.miners_tests.backends_tests.luxminer_tests.test_set_preset -v

wilfredallyn and others added 5 commits February 8, 2026 19:02
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.
Copy link
Contributor Author

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:
Copy link
Contributor Author

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

Copy link
Contributor Author

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

@wilfredallyn
Copy link
Contributor Author

I went back and forth between naming it set_profile vs set_preset. Do you have a preference?

@b-rowan
Copy link
Collaborator

b-rowan commented Feb 10, 2026

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.

Since LuxOS Feb 2025, profileset with update_atm=true (default)
atomically updates ATM MaxProfile and ramps immediately. No need
to manually disable/re-enable ATM.

Ref: https://docs.luxor.tech/firmware/api/luxminer/profileset#using-with-atm

Changes:
- Remove _switch_profile() helper (ATM dance no longer needed)
- set_profile() and set_power_limit() call rpc.profileset() directly
- Remove ATM-related tests (disable/re-enable, re-enable failure)
- Simplify test fixtures (no atm_enabled mock needed)
@wilfredallyn
Copy link
Contributor Author

I saw in the docs that we no longer have to disable ATM before changing profile:

In previous luxminer versions, it wasn't possible to change profiles while ATM was running. Since Feb/2025, this behavior is controlled by the update_atm flag (which defaults to true). Please see [Using with ATM](https://docs.luxor.tech/firmware/api/luxminer/profileset#using-with-atm) for more details.

I simplified the code in 456101c by deleting logic for disabling ATM since LuxOS handles it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments