Skip to content

feat(agent,gui): add headset automatic power-off timeout - #2632

Open
tkroll-ionos wants to merge 28 commits into
AprilNEA:masterfrom
tkroll-ionos:feat/headset-power-off
Open

tkroll-ionos wants to merge 28 commits into
AprilNEA:masterfrom
tkroll-ionos:feat/headset-power-off

Conversation

@tkroll-ionos

@tkroll-ionos tkroll-ionos commented Nov 23, 2026 •

Copy link
Copy Markdown

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 and openlogi diag power-off. The value lives on the headset, so nothing is saved to config.toml.

Verified on a G933 (0x1F20 v0) with raw openlogi diag hidpp calls: read 15 min, wrote 30 (echo 30), read back 30, restored 15.

Changes

  • hidpp: AdcMeasurementFeature gets get_power_off_timeout (fn 1) and set_power_off_timeout (fn 2); the fn 2 echo is the confirmation, as for sidetone.
  • core: PowerOffTimeout (0..=90 minutes), HidppOperation::{ReadPowerOffTimeout, WritePowerOffTimeout} appended, Capabilities::power_off_timeout (appended, #[serde(default)]) from the feature table.
  • device / hid: read and write paths. Only a refusal of the function (invalid function, invalid argument, unsupported) maps to FeatureUnsupported; other errors keep the normal classification. Probe-cache schema bumped so cached headsets pick up the capability.
  • agent-core / agent / ipc: orchestrator read and ordered write; read_power_off_timeout and set_power_off_timeout appended to the Agent trait; PROTOCOL_VERSION 46 → 47 with wire-format goldens; mock agent defaults to unsupported.
  • fixture / cli: the timeout is recorded in device profiles; new openlogi diag power-off [MINUTES].
  • gui: automatic power-off row in the Audio tab (0 shown as "Never"); the tab now also appears for a headset with only this capability; a headset that refuses function 1 shows no row, so a working sidetone slider stays alone, like in the tray.
  • tray: power-off submenu with Never/5/15/30/60/90 minutes on the headset row.
  • i18n / docs: new [audio] strings in all locales (English text, German translated); README and docs/CONFIGURATION.md note the setting.

Testing

  • cargo fmt --check
  • cargo clippy -p <crate> --all-targets -- -D warnings for hidpp, core, device, hid, agent-core, ipc, agent, cli, fixture, ui, desktop
  • cargo test for 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 submenu
  • Hardware: the HID++ calls were verified on a G933 as above. The full GUI/tray path was not run against hardware, and the macOS tray code was only reviewed, not compiled (Linux host).

Review follow-ups (each fails with its fix reverted):

Test Counter-proof
state::tests::power_off_timeout::an_answer_to_a_superseded_write_does_not_move_the_slider drop the pending-write check in apply_power_off_timeout_written
cmd::diag::power_off::tests::a_running_agent_keeps_the_diagnostic_off_the_headset drop exclude_agent() from diag power-off
write::power_off_timeout::tests::a_confirmed_write_is_logged_at_info log the confirmed write at debug! again
tray_model::tests::controls::a_headset_offers_six_power_off_timeouts_while_it_answers revert power_off_group to the six steps only

app::tests::the_power_off_slider_is_reachable_and_writes_only_on_release
renders the Audio tab at 125 % in the minimum window. It fails when
CommitSlider commits on every drag step. The row already fits that window
without scrolling, so its reachability check guards against future growth.

Local gate (full tier, Cargo.toml/Cargo.lock changed): 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

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.
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Confidence Score: 0/5 · Do not merge until superseded writes report no change, async tests have deadlines, and the new timeout write state has one owner.RetriggerView in GreptileConfidence Score: 0/5

[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

  1. P0 Skipped writes report success ▶
  2. P1 Failed sends leave writes pending ▶
  3. P1 Async tests lack deadlines ▶

Summary

Adds headset automatic power-off controls through HID++ 0x1F20, the agent, the Audio tab, the tray, and diag power-off.

  • Supported headsets let OpenLogi read and change their automatic power-off timeout.
  • The Audio tab gives supported headsets a slider for their automatic power-off timeout.
  • The device tray adds timeout choices to supported headset rows.
  • The diagnostic command reads or sets a headset's automatic power-off timeout.

Diagram

sequenceDiagram
    participant GUI as Audio tab
    participant State as AppState
    participant Agent
    participant Headset
    GUI->>State: Release timeout slider
    State->>State: Show timeout and record write ID
    State->>Agent: Set timeout
    Agent->>Headset: HID++ function 2
    Headset-->>Agent: Echo timeout
    Agent-->>State: Timeout and write ID
    State->>State: Accept only the newest write ID
Loading

Reviews (4) · Last reviewed commit: "test(gui): drag the power-off slider in ..." · Reviewed by Greptile

Comment on lines +109 to +116
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(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Async tests lack deadlines

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tkroll-ionos

Copy link
Copy Markdown
Author

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?

  1. Keep it in Audio (headsets are the only devices with it today).
  2. Move it to the Device tab.
  3. Add a new Power section or tab, which other power settings could join later.

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 },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Skipped writes report success

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.
Comment on lines +75 to +85
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,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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)

This branch has not been deployed

No deployments
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.

[Feature]: Automatic power-off timeout for headsets (HID++ 0x1F20)

1 participant