Repository navigation
feat(agent,gui): add headset automatic power-off timeout - #2632
tkroll-ionos wants to merge 28 commits into
Conversation
AdcMeasurementFeature gains get_power_off_timeout (function 1) and set_power_off_timeout (function 2), in minutes with 0 meaning never. A G933 answers both at feature version 0; the write's echo is the confirmation, as with the sidetone level.
PowerOffTimeout holds a headset's automatic power-off timeout in minutes, 0..=90 with 0 meaning never. HidppOperation gains ReadPowerOffTimeout and WritePowerOffTimeout after WriteSidetone, and Capabilities::power_off_timeout is appended after change_host, set when the feature table lists 0x1F20. The flag is not gated on DeviceKind::Headset: capability decisions come from the feature table, not the kind, as sidetone does. A device that lists 0x1F20 only for its battery refuses function 1, and that refusal reads as unsupported. The wire-format inventory pin carries the new field.
get_power_off_timeout/set_power_off_timeout and their _on variants talk to 0x1F20 functions 1 and 2. A write returns the headset's echo. A device that lists 0x1F20 for its battery but refuses function 1 reads as FeatureUnsupported; a Busy answer stays a retryable error.
Bump the probe-cache schema to v21 so a cached 0x1F20 headset gains Capabilities::power_off_timeout without waiting for a fresh probe.
SharedHandles gains read_power_off_timeout and set_power_off_timeout. Writes are ordered per headset like the sidetone writes: a write superseded before its turn reads the headset instead.
ProfileDeviceSettings::power_off_timeout defaults to unsupported so older profiles keep loading. Since 0x1F20 is also listed for the battery, a profile may hold the timeout unsupported while the inventory advertises it; only a timeout without the advertised feature is rejected.
Agent::{read_power_off_timeout, set_power_off_timeout} are appended
after action_ring_unhover, under protocol v47. The agent answers them
through SharedHandles; the mock agent answers from the profile's
power_off_timeout setting.
record-profile reads the timeout when the inventory advertises it, and records a refused read as unsupported.
Eight audio.* keys for the Audio tab row and the menu-bar submenu, English in every catalog until translated.
Read a headset's HID++ 0x1F20 automatic power-off timeout, or set it in minutes (0 is never) and fail when the headset's echo differs. The range comes from PowerOffTimeout, so an out-of-range value is rejected before any device is opened.
A headset that lists HID++ 0x1F20 gets a second Audio row: a slider in minutes from 0 (never) to 90. A release writes the headset through the agent and nothing is saved; a refusal reads the headset again. A headset that refuses the timeout read shows as unsupported.
A headset that lists 0x1F20 gets an automatic power-off submenu group with Never, 5, 15, 30, 60 and 90 minutes, read when the submenu opens and written on the device alone, as sidetone is. A headset that refuses the read hides the group.
The group offers its six timeouts only once the headset answered, shows a change the headset echoed, greys out after a failed read and disappears when the headset refuses the feature.
A headset can list 0x1F20 for its battery alone and refuse the timeout read, as the G535 may. Its Audio tab then showed a permanent "unsupported" line under the working sidetone slider, while the menu-bar menu hides the group. The row now disappears in that case and keeps the unsupported line only when the tab would otherwise be empty.
Only InvalidFunctionId, InvalidArgument and Unsupported on function 1 now mean the headset lacks the timeout. HwError, Unknown, LogitechInternal and the other HID++ errors stay retryable read errors, so one transient fault no longer hides the setting until the headset reconnects.
A headset that comes back online is read again. The unsupported test now advances the clock past any retry before it checks that a refusal is not read again.
[Medium impact] The PR changes a headset setting through several OpenLogi entry points. Do not merge until superseded writes report no change, async tests have deadlines, and the new timeout write state has one owner. Findings
|
| async fn a_write_returns_the_echo_and_reads_back() { | ||
| let headset = Arc::new(Mutex::new(Headset::g933(15))); | ||
| let shared = headset_channel(&headset).await; | ||
|
|
||
| assert_eq!( | ||
| set_power_off_timeout_on(&shared, minutes(30)) | ||
| .await | ||
| .unwrap(), |
There was a problem hiding this comment.
Blocking. The new tests await headset_channel and HID requests without a test deadline. A stuck setup or transport can leave the test run waiting instead of producing a clear failure.
The async-test rule requires every wait to race a timeout and panic with a useful message. Wrap each new async test body, including setup, in that guard. Apply it to the new ADC tests in adc_measurement.rs too.
Rule Used: Severity: medium. Every bug fix ships a regression test that fails without the fix, and the PR states the counter-proof (the reverted line or the killed mutant). A test that passes with the fix reverted is not a regression test: ask for inputs where ... (source)
There was a problem hiding this comment.
I don't think these can hang. Every request in them goes through HidppChannel::send, which bounds it by SEND_RESPONSE_TIMEOUT (5 s, a futures_timer::Delay, so also under block_on in the ADC tests). A stuck transport ends as ChannelError::Timeout and fails the test. The other write test modules (sidetone, report rate, force sensing, …) use the same plain #[tokio::test] shape.
There was a problem hiding this comment.
You're right; I withdraw the async-deadline finding. HidppChannel::send bounds the write and response wait with SEND_RESPONSE_TIMEOUT (5 seconds), and both the scripted and mock test transports declare report support directly, so channel setup does not introduce an unbounded descriptor read. The same reasoning applies to the ADC tests under futures::executor::block_on. The matching shape in sibling test modules is consistent, but the channel timeout is the decisive point.
|
A placement question before this gets reviewed in detail. Right now the power-off timeout sits in the Audio tab, below Sidetone, and in the tray next to the Sidetone submenu. That's where it was easiest to add, but it isn't really an audio setting: it's about the device's power. Which would you prefer?
I'm happy to change the GUI and the tray either way. |
| HidppOperation::WritePowerOffTimeout, | ||
| &ticket, | ||
| |c| async move { openlogi_hid::set_power_off_timeout_on(&c, timeout).await }, | ||
| |c| async move { openlogi_hid::get_power_off_timeout_on(&c).await }, |
There was a problem hiding this comment.
When a newer timeout request replaces a queued write, set_power_off_timeout runs a normal read and returns Ok(timeout) if it succeeds. The tray then records that answer as an applied change, even though the request wrote nothing.
This violates the repository’s write-order rule: superseded writes must return WriteSuperseded and update no cache. Return that error here and let the tray treat it as no change. Add a write-order test that queues two timeout changes behind a held turn and checks that the skipped request changes no cached reading.
Rule Used: Severity: high. Every HID++ write to one device takes a ticket from that device's WriteOrder and runs under WriteTicket::in_order (read-modify-write, strict request order) or WriteTicket::turn (idempotent set-value writes only, newest wins). Th... (source)
There was a problem hiding this comment.
Leaving this one as is. set_power_off_timeout follows set_sidetone, set_report_rate, set_pointer_speed and set_force_sensing on master: a superseded write reads the headset, so its answer is what the headset holds at that moment, never the skipped request. WriteSuperseded is used where the caller would otherwise save the request to config (DPI, Fn lock), and nothing saves the power-off timeout. The tray records that read and the newer write's answer follows it. On the GUI side the write number from the P0 above now drops the older answer. If you'd rather have WriteSuperseded for every device-kept setting, I'd do that in its own PR, sidetone included.
There was a problem hiding this comment.
You're right. I conflated “this request did not write” with “the returned value falsely claims it did.” The fallback is a read of the headset's current value, and for this device-owned setting that is a valid result; the GUI's write number also prevents an older answer from moving the slider after a newer request. Given the existing newest-wins pattern for these settings, I withdraw this finding for this PR. A broader change to return WriteSuperseded consistently can be considered separately, as you suggest.
fa034f8 to
8157f4e
Compare
The settings app sets any minute from 0 to 90, while the tray offers six steps. A timeout between them left the submenu without a checkmark. It now joins the steps in its place, checked and greyed out, so the tray always shows what the headset holds.
A confirmed write changes when the headset switches itself off, so it is a device change and belongs at info, not debug. The new test installs a subscriber at info and checks that the write is logged.
The agent answers a power-off write that a newer one superseded before its turn with a plain read, which still holds the old timeout. Two releases before the first answer moved the slider back to that old timeout until the second answer came. Each write now carries a number, as press-force writes do, and only the newest write's answer counts.
The agent writes the power-off timeout too, and diag power-off opened the headset without checking for it. It now takes the agent's instance lock for its whole run and refuses while an agent answers, as diag hidpp does. The check moves from diag hidpp into the diag module, so both commands share one copy.
The Audio tab tests only looked at the facts behind the rows, so they passed even if the tab stopped drawing the slider. The new test renders the main window at 125 % in its minimum size, scrolls the Audio tab to its end, checks that the power-off row sits inside the window beside the sidetone row, and drags the slider with the mouse: the drag writes nothing, the release writes the headset once.
| let write = self.pointer.next_power_off_timeout_write; | ||
| self.pointer.next_power_off_timeout_write = write.saturating_add(1); | ||
| self.pointer | ||
| .pending_power_off_timeout_writes | ||
| .insert(key.clone(), write); | ||
| self.send_ipc(crate::services::ipc::SetPowerOffTimeout { | ||
| route, | ||
| timeout, | ||
| key, | ||
| write, | ||
| }); |
There was a problem hiding this comment.
Failed sends leave writes pending
Blocking. commit_power_off_timeout updates PointerState::reads and inserts pending_power_off_timeout_writes before calling send_ipc, but ignores its return value. If the IPC channel is closed, the page keeps an unconfirmed timeout and a pending write that can never receive an answer.
This violates the repository directive against tracking a lifecycle through separate fields. Replace the split state with one per-headset enum, such as Confirmed, Pending { write, requested }, and Failed, whose transitions have one owner. Keep next_power_off_timeout_write as a separate ID allocator. Add tests for failed sends, answers without a matching request, and older answers.
Context Used: Implicit state machines Flag any change that introduces or extends an implicit state machine: a lifecycle, phase, or mode that the code tracks through a combination of independent fields instead of one enum with one transition function. Report it as... (source)
Summary
Read and set the automatic power-off timeout of Logitech headsets that expose it on HID++
0x1F20(function 1 reads, function 2 writes, minutes 0–90, 0 = never). Built like headset sidetone (#2146): a row in the Audio tab, a tray submenu andopenlogi diag power-off. The value lives on the headset, so nothing is saved toconfig.toml.Verified on a G933 (
0x1F20v0) with rawopenlogi diag hidppcalls: read 15 min, wrote 30 (echo 30), read back 30, restored 15.Changes
AdcMeasurementFeaturegetsget_power_off_timeout(fn 1) andset_power_off_timeout(fn 2); the fn 2 echo is the confirmation, as for sidetone.PowerOffTimeout(0..=90 minutes),HidppOperation::{ReadPowerOffTimeout, WritePowerOffTimeout}appended,Capabilities::power_off_timeout(appended,#[serde(default)]) from the feature table.FeatureUnsupported; other errors keep the normal classification. Probe-cache schema bumped so cached headsets pick up the capability.read_power_off_timeoutandset_power_off_timeoutappended to theAgenttrait;PROTOCOL_VERSION46 → 47 with wire-format goldens; mock agent defaults to unsupported.openlogi diag power-off [MINUTES].[audio]strings in all locales (English text, German translated); README anddocs/CONFIGURATION.mdnote the setting.Testing
cargo fmt --checkcargo clippy -p <crate> --all-targets -- -D warningsfor hidpp, core, device, hid, agent-core, ipc, agent, cli, fixture, ui, desktopcargo testfor those crates (4041 tests), including new tests for the hidpp functions, the device read/write mapping, the wire format, the CLI argument parsing, the desktop state machine and Audio tab, and the tray submenuReview follow-ups (each fails with its fix reverted):
state::tests::power_off_timeout::an_answer_to_a_superseded_write_does_not_move_the_sliderapply_power_off_timeout_writtencmd::diag::power_off::tests::a_running_agent_keeps_the_diagnostic_off_the_headsetexclude_agent()fromdiag power-offwrite::power_off_timeout::tests::a_confirmed_write_is_logged_at_infodebug!againtray_model::tests::controls::a_headset_offers_six_power_off_timeouts_while_it_answerspower_off_groupto the six steps onlyapp::tests::the_power_off_slider_is_reachable_and_writes_only_on_releaserenders the Audio tab at 125 % in the minimum window. It fails when
CommitSlidercommits on every drag step. The row already fits that windowwithout scrolling, so its reachability check guards against future growth.
Local gate (full tier,
Cargo.toml/Cargo.lockchanged):cargo fmt --check,workspace clippy,
cargo test --workspace, non-GUI rustdoc,ast-grep scan(0.45.1) and
typos(1.49.0) on Linux. Not run: macOS and Windows test legs,MSRV check, cargo-deny, shell job.
Fixes #2631