Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

media_player_all_features #1092

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

rwrozelle
Copy link

Extends the media_player to additional features. supports_turn_off_on, supports_grouping, supports_next_prevous_track, State extended to include song attributes.

Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Walkthrough

This pull request introduces enhancements to the media player functionality within the API by adding new states, commands, and detailed attributes. The changes include updates to the protobuf definitions, the API client method, and internal models, allowing for additional capabilities such as enqueueing media, grouping, and advanced playback controls. New optional parameters in the API client facilitate these enhanced command requests, while updated enums and message fields provide richer representations of media player states and commands.

Changes

File(s) Change Summary
aioesphomeapi/api.proto, aioesphomeapi/model.py Extended media player support by adding new enum values (e.g., MEDIA_PLAYER_STATE_ANNOUNCING, MEDIA_PLAYER_STATE_OFF, MEDIA_PLAYER_STATE_ON for state; additional commands like MEDIA_PLAYER_COMMAND_TOGGLE, MEDIA_PLAYER_COMMAND_VOLUME_UP, MEDIA_PLAYER_COMMAND_ENQUEUE, etc.) and new fields/attributes in messages and models to capture extra media info and capabilities (repeat, shuffle, artist, album, etc.).
aioesphomeapi/client.py Updated the APIClient.media_player_command method by introducing new optional parameters (enqueue, group_members) and setting corresponding flags within the MediaPlayerCommandRequest.
tests/test_client.py Added new test cases for handling media commands with enqueue and group member options, enhancing test coverage for the media player command functionalities.

Possibly related PRs

  • Support asking device to check for updates #914: The changes in the main PR are related to the modifications in the MediaPlayerCommand and MediaPlayerState enums, which are also reflected in the retrieved PR's updates to the UpdateCommand enum, indicating a broader enhancement of command handling within the same API structure.
  • Add MediaPlayerSupportedFormat #925: The changes in the main PR are related to the modifications in the ListEntitiesMediaPlayerResponse message, as both PRs update this message to include new fields, enhancing the media player functionality.

Suggested labels

new-feature

Suggested reviewers

  • jesserockz
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codspeed-hq bot commented Feb 28, 2025

CodSpeed Performance Report

Merging #1092 will not alter performance

Comparing rwrozelle:media_player_all_features (35316b7) with main (84d49b8)

Summary

✅ 9 untouched benchmarks

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (84d49b8) to head (35316b7).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1092   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         2742      2778   +36     
=========================================
+ Hits          2742      2778   +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d803269 and b8abce2.

📒 Files selected for processing (3)
  • aioesphomeapi/api.proto (4 hunks)
  • aioesphomeapi/client.py (2 hunks)
  • aioesphomeapi/model.py (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**`: - Do not generate or add any sequence diagrams

**: - Do not generate or add any sequence diagrams

  • aioesphomeapi/client.py
  • aioesphomeapi/api.proto
  • aioesphomeapi/model.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: py 3.12 on windows-latest (skip_cython)
🔇 Additional comments (8)
aioesphomeapi/client.py (1)

1232-1260: New media player command parameters look good.

The additions of enqueue and group_members parameters to the media_player_command method are well-implemented, with proper optional typing and conditional flag setting. The implementation follows the same pattern as the existing parameters.

aioesphomeapi/api.proto (4)

1127-1159: Media player state and command enums expanded appropriately.

The new states and commands enhance the media player functionality as described in the PR objectives, adding support for announcements, power control, track navigation and playback controls.


1190-1193: Support flags for new media player capabilities.

The new boolean capability flags correctly implement the planned functionality additions: turning media players on/off, grouping players together, and navigating between tracks.


1203-1210: Enhanced media player state attributes.

The additional fields for song metadata and playback state provide much more detailed information about currently playing media, which will greatly improve the user experience.


1231-1236: Command request fields for new functionality.

The enqueue and group_members fields enable the new features and follow the same pattern as existing command parameters with appropriate has_* flags.

aioesphomeapi/model.py (3)

813-816: Media player state enum values correctly added.

The new state enum values match the protocol definitions and enable the new functionality.


872-875: Media player info capability flags properly added.

These flags correctly correspond to the new fields in the ListEntitiesMediaPlayerResponse message.


891-899: Media player state information significantly enhanced.

The new attributes in MediaPlayerEntityState provide rich metadata about media playback, matching the protocol definition.

Comment on lines 825 to 840
TOGGLE = 5
VOLUME_UP = 6
VOLUME_DOWN = 7
ENQUEUE = (8,)
REPEAT_ONE = (9,)
REPEAT_OFF = (10,)
CLEAR_PLAYLIST = (11,)
NEXT_TRACK = (12,)
PREVIOUS_TRACK = (13,)
TURN_ON = (14,)
TURN_OFF = (15,)
SHUFFLE = (16,)
UNSHUFFLE = (17,)
REPEAT_ALL = (18,)
JOIN = (19,)
UNJOIN = (20,)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix tuple syntax in MediaPlayerCommand enum values.

There's a syntax error in how the new commands are defined - they're incorrectly using tuple syntax with trailing commas instead of simple integer values.

Apply this diff to fix the syntax:

    TOGGLE = 5
    VOLUME_UP = 6
    VOLUME_DOWN = 7
-   ENQUEUE = (8,)
-   REPEAT_ONE = (9,)
-   REPEAT_OFF = (10,)
-   CLEAR_PLAYLIST = (11,)
-   NEXT_TRACK = (12,)
-   PREVIOUS_TRACK = (13,)
-   TURN_ON = (14,)
-   TURN_OFF = (15,)
-   SHUFFLE = (16,)
-   UNSHUFFLE = (17,)
-   REPEAT_ALL = (18,)
-   JOIN = (19,)
-   UNJOIN = (20,)
+   ENQUEUE = 8
+   REPEAT_ONE = 9
+   REPEAT_OFF = 10
+   CLEAR_PLAYLIST = 11
+   NEXT_TRACK = 12
+   PREVIOUS_TRACK = 13
+   TURN_ON = 14
+   TURN_OFF = 15
+   SHUFFLE = 16
+   UNSHUFFLE = 17
+   REPEAT_ALL = 18
+   JOIN = 19
+   UNJOIN = 20

The current implementation with tuple values would cause runtime errors when converting between Python enums and protocol enum values.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
TOGGLE = 5
VOLUME_UP = 6
VOLUME_DOWN = 7
ENQUEUE = (8,)
REPEAT_ONE = (9,)
REPEAT_OFF = (10,)
CLEAR_PLAYLIST = (11,)
NEXT_TRACK = (12,)
PREVIOUS_TRACK = (13,)
TURN_ON = (14,)
TURN_OFF = (15,)
SHUFFLE = (16,)
UNSHUFFLE = (17,)
REPEAT_ALL = (18,)
JOIN = (19,)
UNJOIN = (20,)
TOGGLE = 5
VOLUME_UP = 6
VOLUME_DOWN = 7
ENQUEUE = 8
REPEAT_ONE = 9
REPEAT_OFF = 10
CLEAR_PLAYLIST = 11
NEXT_TRACK = 12
PREVIOUS_TRACK = 13
TURN_ON = 14
TURN_OFF = 15
SHUFFLE = 16
UNSHUFFLE = 17
REPEAT_ALL = 18
JOIN = 19
UNJOIN = 20

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
aioesphomeapi/model.py (2)

873-875: Consider renaming for clarity.

supports_turn_off_on might be more consistent if named supports_turn_on_off or supports_power_toggle to match reading order and be more descriptive. This is a minor naming nitpick but can improve clarity.


891-899: Consider using strong types for repeat/shuffle/timing fields.

Storing repeat as a string and duration/position as integers can work, but using dedicated enums (for repeat/shuffle) or floats (for more precise timing) can improve type safety and clarity. Otherwise, please ensure robust validation for string-based repeat values.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8abce2 and 18436fa.

📒 Files selected for processing (1)
  • aioesphomeapi/model.py (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**`: - Do not generate or add any sequence diagrams

**: - Do not generate or add any sequence diagrams

  • aioesphomeapi/model.py
🔇 Additional comments (2)
aioesphomeapi/model.py (2)

814-816: Check for feature usage of newly introduced states.

These new states (OFF, ON, and ANNOUNCING) appear valid. Please ensure they are handled throughout the codebase wherever a media player state might be set or interpreted, so that existing code that expects only IDLE, PLAYING, or PAUSED does not encounter unexpected behavior.


825-840: All new commands are well-structured and consistent.

Thank you for fixing the previous tuple-related syntax. These commands integrate well with the existing MediaPlayerCommand pattern.

@bdraco bdraco added the waiting-for-esphome Indicates the PR is waiting for the esphome main repo code approval label Feb 28, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
aioesphomeapi/client.py (1)

1231-1262: Consider adding documentation for the new parameters

The method lacks docstring documentation explaining what the new parameters do. Adding documentation would improve developer experience and code maintenance.

 def media_player_command(
     self,
     key: int,
     *,
     command: MediaPlayerCommand | None = None,
     volume: float | None = None,
     media_url: str | None = None,
     announcement: bool | None = None,
     enqueue: str | None = None,
     group_members: str | None = None,
 ) -> None:
+    """Send a command to a media player.
+
+    Args:
+        key: The key identifying the media player.
+        command: The command to send to the media player.
+        volume: The volume to set on the media player.
+        media_url: The URL of media to play.
+        announcement: Whether this is an announcement.
+        enqueue: The enqueue option for the media player.
+        group_members: The group members for the media player when operating in group mode.
+    """
     req = MediaPlayerCommandRequest(key=key)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15b2705 and 35316b7.

📒 Files selected for processing (1)
  • aioesphomeapi/client.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**`: - Do not generate or add any sequence diagrams

**: - Do not generate or add any sequence diagrams

  • aioesphomeapi/client.py
🔇 Additional comments (2)
aioesphomeapi/client.py (2)

1239-1240: Method signature enhancement for extended media player functionality

The addition of enqueue and group_members parameters aligns well with the PR objectives, enabling support for the media player enqueueing functionality and grouping capabilities.


1255-1260: Implementation follows consistent parameter handling pattern

The implementation for the new parameters follows the established pattern in the codebase, properly checking for None values before setting the request attributes and their corresponding flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-esphome Indicates the PR is waiting for the esphome main repo code approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants