Skip to content

Send media playback position from Home Assistant to NSPanels - #409

Merged
tpanajott merged 1 commit into
NSPManager:develfrom
jamesmulcahy:feat/media-player-position
Oct 25, 2026
Merged

tpanajott merged 1 commit into
NSPManager:develfrom
jamesmulcahy:feat/media-player-position

Conversation

@jamesmulcahy

@jamesmulcahy jamesmulcahy commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Home Assistant media players report media_position, media_duration and media_position_updated_at. The manager ignored these until now. This PR sends them to the NSPanels so the media player page can show its progress bar (p_pos).

Builds on #410 (protobuf fields 20–23 of NSPanelEntityState.MediaPlayer), which has merged.

Protobuf (merged in #410)

  • has_media_position, media_position (seconds), media_position_updated_at (Unix seconds) and media_duration (seconds; 0 when unknown, for example on a live stream).
  • Home Assistant only reports the position when playback starts, stops or seeks, along with the time it was taken. With that time, a panel can advance the position on its own while playing, so the manager doesn't need to publish a state every second. The state is retained, so a panel can receive it long after it was sent. For that reason the time is absolute and must not be counted from when the state arrived. So panels need a wall clock, which MQTTManager: send NSPanels the current time #404 and Send NSPanels the POSIX TZ rule for the manager's timezone #405 provide.

Manager

  • HomeAssistantMediaPlayer reads the three attributes on every state change. A position is only sent along with a timestamp that parses, because a position can't be advanced without knowing when it was taken. The position and duration are cleared when Home Assistant stops reporting them, for example when the player stops or turns off.
  • Timestamps (2026-10-17T01:59:45.666287+00:00) are parsed with Howard Hinnant's date library, added as the header-only Conan package date/3.0.5. Fractional seconds are truncated.

Not in this PR

  • Panel side: drawing p_pos and advancing it while playing is in a separate firmware PR, stacked on the panel wall clock work.

Testing

  • New tests in tests/media_player_test.cpp: the position and duration are sent; seeking sends the new position; a live stream has a position but no duration; a position without a valid timestamp isn't sent; the position is cleared when playback stops; timestamp parsing, including offsets, fractional seconds and malformed input.
  • tests/media_player_recorded_states_test.cpp checks the position fields against states recorded from Home Assistant.
  • The branch rebases cleanly onto current devel.

🤖 Generated with Claude Code

@tpanajott

Copy link
Copy Markdown
Collaborator

I'll wait to review this one until #396 is merged as to now review many thousands of line twice. Fixing #396 should be quite quick as it's just one tiny nitpick thing.

Home Assistant media players report media_position, media_duration and
media_position_updated_at, which were ignored. They are now sent to the
panels with the rest of the media player state.

A position without a time it was taken at can not be advanced, so it is
only sent together with a valid media_position_updated_at. The position
and duration are cleared when Home Assistant stops reporting them, for
example when playback stops or the player turns off.

media_position_updated_at is parsed with date::parse from Howard
Hinnant's date library, added as a header-only Conan dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamesmulcahy
jamesmulcahy force-pushed the feat/media-player-position branch from 950085d to a90e7a9 Compare October 25, 2026 14:52
@jamesmulcahy

Copy link
Copy Markdown
Contributor Author

@tpanajott Thanks for merging the sources change; I've re-based this now and it's just a single commit

@tpanajott
tpanajott merged commit a4a2dac into NSPManager:devel Oct 25, 2026
1 check passed
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