GUI: per-miner capabilities + live config write path (right-click actions)
Completes the right-click config menu (round-2 item 11): the menu now offers real actions computed from the intersection of what every selected miner supports, and applies them to the fleet over the network. - Capability detection: to_row probes each miner's asic-rs supports_* methods (fault light, restart, pause, resume, power limit, tuning) at scan time and stores them in MinerRow.caps -- no extra network round-trip. - Intersection: MinerCaps::intersect_all yields the actions common to the whole selection; the context menu offers only those (a mixed mining + idle selection shows just fault light + restart; an all-mining selection shows everything). - Write path: scan::start_config_action runs on a background thread -- it re-discovers each selected miner with asic-rs scan_miner(ip), applies the setter, and reports per-IP results that drain into the status bar (running progress while applying, a pass/fail summary when done). Cancellable, and a new action cancels any in-flight one so two never overlap. In fake-scan mode it simulates success so the flow is exercisable offline. - Actions: fault light on/off, pause, resume, restart apply immediately; set power limit and set tuning % open a small value-prompt dialog first. Factory reset, change password, and firmware upgrade are deliberately not exposed in a casual right-click. Adds the `measurements` dependency (already in the lock, transitive via asic-rs) for Power::from_watts. Review fixes (one review pass): - Restart / pause / resume now require a confirmation dialog (naming the count) so a misclick can't stop a producing fleet; fault light stays instant, and power/tuning are confirmed by their value entry. - The action result is held on the status bar for a few ticks so a fleet action's outcome (including failures) isn't clobbered by the next timer tick. - The action loop uses a current-thread tokio runtime (it applies to one miner at a time; a worker pool was wasted). - The value prompt validates before closing: a bad value keeps the dialog and the captured selection so it can be corrected. - The menu's "(N)" counts use the rows-backed selection, matching what is actually acted on. Verified off-screen: capability intersection (mixed vs all-mining selections), the value-prompt and confirmation nested modals (menu -> dialog) with no crash, the end-to-end apply flow, 46 unit tests (incl. a caps-intersection test), and the headless self-test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
@@ -78,6 +78,48 @@ fn ip_to_u32(s: &str) -> u32 {
|
||||
acc
|
||||
}
|
||||
|
||||
/// What a miner supports being told to do, probed from asic-rs' `supports_*`
|
||||
/// capability methods at scan time. The right-click menu offers an action only
|
||||
/// when every selected miner supports it (the intersection of capabilities).
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub struct MinerCaps {
|
||||
pub fault_light: bool,
|
||||
pub restart: bool,
|
||||
pub pause: bool,
|
||||
pub resume: bool,
|
||||
pub power_limit: bool,
|
||||
pub tuning: bool,
|
||||
}
|
||||
|
||||
impl MinerCaps {
|
||||
/// The capabilities common to `self` and `other` (logical AND per action).
|
||||
pub fn intersect(self, other: MinerCaps) -> MinerCaps {
|
||||
MinerCaps {
|
||||
fault_light: self.fault_light && other.fault_light,
|
||||
restart: self.restart && other.restart,
|
||||
pause: self.pause && other.pause,
|
||||
resume: self.resume && other.resume,
|
||||
power_limit: self.power_limit && other.power_limit,
|
||||
tuning: self.tuning && other.tuning,
|
||||
}
|
||||
}
|
||||
|
||||
/// The capabilities common to every miner in `caps` (all-true identity when
|
||||
/// empty is intentionally avoided: an empty selection has no common caps).
|
||||
pub fn intersect_all(caps: impl IntoIterator<Item = MinerCaps>) -> MinerCaps {
|
||||
let mut it = caps.into_iter();
|
||||
match it.next() {
|
||||
Some(first) => it.fold(first, MinerCaps::intersect),
|
||||
None => MinerCaps::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// True when no action is supported (nothing to offer in the menu).
|
||||
pub fn is_empty(self) -> bool {
|
||||
self == MinerCaps::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
||||
/// scalar fields the table can display. Absent metrics are `None` / empty /
|
||||
/// 0.0 and render as a blank cell.
|
||||
@@ -85,6 +127,8 @@ fn ip_to_u32(s: &str) -> u32 {
|
||||
pub struct MinerRow {
|
||||
pub ip: String,
|
||||
pub selected: bool,
|
||||
/// What this miner supports being told to do (for the right-click menu).
|
||||
pub caps: MinerCaps,
|
||||
// identity
|
||||
pub model: String,
|
||||
pub mac: String,
|
||||
@@ -1181,6 +1225,22 @@ mod tests {
|
||||
assert_eq!(Column::Hashrate.num_value(&r2), Some(42.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn caps_intersection_is_the_common_actions() {
|
||||
let full = MinerCaps { fault_light: true, restart: true, pause: true, resume: true, power_limit: true, tuning: true };
|
||||
let idle = MinerCaps { fault_light: true, restart: true, ..Default::default() };
|
||||
// Two full miners keep every action.
|
||||
assert_eq!(MinerCaps::intersect_all([full, full]), full);
|
||||
// A full + idle mix keeps only what both support.
|
||||
assert_eq!(MinerCaps::intersect_all([full, idle]), idle);
|
||||
// A single miner's caps are its own.
|
||||
assert_eq!(MinerCaps::intersect_all([full]), full);
|
||||
// Empty selection -> nothing common.
|
||||
assert_eq!(MinerCaps::intersect_all([]), MinerCaps::default());
|
||||
assert!(MinerCaps::default().is_empty());
|
||||
assert!(!full.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numeric_filter_excludes_blank_cells() {
|
||||
// A blank-displaying value-type cell (absent reading stored as 0.0) must
|
||||
|
||||
Reference in New Issue
Block a user