Add Sleep Timer support (set_sleep_timer endpoint)#1718
Open
spacenono wants to merge 3 commits into
Open
Conversation
Add a `SetSleepTimer` variant to the dealer `Command` enum together with the `SetSleepTimerCommand` and `SleepTimer` types, so that the `set_sleep_timer` endpoint sent by Spotify clients is deserialized instead of falling through to the `Unknown` catch-all. The inner `timer_type` object keeps its `type` discriminator as a raw string so that unsupported or future timer types (e.g. `end_of_track`) are reported by name rather than silently dropped. Only `duration` is fully modelled; `timestamp` is parsed defensively as its exact shape has not been confirmed against a real client yet. BREAKING CHANGE: a new variant is added to the public, non-exhaustive `Command` enum; downstream exhaustive matches on it must be updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Arm a one-shot timer from the `set_sleep_timer` command and pause playback when it expires. The deadline is stored as a single absolute `Instant` and awaited with `sleep_until` inside the main `select!` loop, so re-arming or recreating the future never drifts the deadline. A zero duration disarms the timer; unsupported types (such as `end_of_track`) are logged and ignored. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
clippy 1.96 introduced the `unnecessary_sort_by` lint, which fails the `-D warnings` CI on the pre-existing `get_covers` sort. Apply the suggested `sort_by_key` + `Reverse` rewrite. No behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
Note on the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #1659.
The Spotify mobile app's Sleep timer (Now Playing → ⋯ → Sleep timer) sends a
set_sleep_timercommand that librespot currently rejects with"Not implemented { unknown endpoint: set_sleep_timer }". This PR handles it.
Behaviour
durationtimer arms a one-shot countdown; playback is paused when itexpires, and the paused state is propagated back to the controlling client.
matching the official client.
Design
Option<tokio::time::Instant>) is stored on thetask and awaited with
sleep_untilinside the existingselect!loop, sorecreating the future every iteration never drifts the deadline (same spirit
as the keep-alive timer in Rework session keep-alive logic v2 #1359, without pinning a
Sleep).timer_typediscriminator is kept as a raw string so unsupported orfuture types are logged by name.
Scope / future work
durationis fully implemented and tested end-to-end on an iPhone against amacOS build (timer armed, fired, paused, state propagated).
timestampis parsed defensively (no real-world sample captured yet).type: "end_of_track"; it is a different,event-driven mechanism and is logged + ignored for now.
Known limitation — open question for maintainers
With this change the device honours the command and pauses correctly, but the
mobile app still briefly shows a "you can't use the sleep timer on this device"
popup. This appears to be client-side capability gating for the (recently
added, Aug 2025) cross-device sleep timer: the device never advertises the
corresponding capability. The most likely place is the empty
Capabilities.connect_capabilities(tag 27) string field, but I couldn't findthe expected token/format in any public source. Do you know how this
capability should be advertised? Happy to add it if so.
Breaking change
Adds a
SetSleepTimervariant to the public, non-exhaustivecore::dealer::protocol::Commandenum — downstream exhaustive matches must beupdated.