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

Voice Assistant Timers #878

Merged
merged 4 commits into from
May 27, 2024
Merged

Voice Assistant Timers #878

merged 4 commits into from
May 27, 2024

Conversation

jesserockz
Copy link
Member

@jesserockz jesserockz commented May 27, 2024

A new one-way event type from HA to device to notify device of its own voice assistant timers.

Summary by CodeRabbit

  • New Features

    • Introduced support for voice assistant timer events, including start, update, cancel, and finish actions.
    • Added functionality to send and handle voice assistant timer events.
  • Tests

    • Added test coverage for the new voice assistant timer event functionality.

Copy link
Contributor

coderabbitai bot commented May 27, 2024

Walkthrough

The changes introduce a new feature for handling voice assistant timer events within the aioesphomeapi project. These updates include defining new enumerations and message structures in the protobuf file, adding methods to handle timer events in the client, and incorporating tests to ensure the functionality works as expected.

Changes

File Path Change Summary
aioesphomeapi/api.proto Added VoiceAssistantTimerEvent enum and VoiceAssistantTimerEventResponse message.
aioesphomeapi/client.py Introduced send_voice_assistant_timer_event method for sending timer events.
aioesphomeapi/core.py Exported VoiceAssistantTimerEventResponse entity.
aioesphomeapi/model.py Updated VoiceAssistantFeature enum with TIMERS and added VoiceAssistantTimerEventType.
tests/test_client.py Added tests for VoiceAssistantTimerEventResponse and VoiceAssistantTimerEventType.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant Server
    participant VoiceAssistant

    Client->>Server: send_voice_assistant_timer_event(event_type, timer_id, ...)
    Server-->>VoiceAssistant: Notify Timer Event
    VoiceAssistant-->>Server: Acknowledge Timer Event
    Server-->>Client: VoiceAssistantTimerEventResponse
Loading

🐰 "Timers tick and seconds flee,
New events for all to see.
Voice assists with perfect grace,
In your code, they find their place.
Tests ensure they work just right,
Making sure all runs so tight."
⏳✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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

Outside diff range and nitpick comments (1)
tests/test_client.py (1)

Line range hint 758-758: Remove duplicate test function definition.

- async def test_valve_command(auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]) -> None:
-     send = patch_send(auth_client)
-     auth_client.valve_command(**cmd)
-     send.assert_called_once_with(ValveCommandRequest(**req))

This function is defined twice in the file, which could lead to confusion and unexpected behavior during testing. Removing the duplicate will clean up the test suite.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3bae70e and fd43729.
Files selected for processing (5)
  • aioesphomeapi/api.proto (1 hunks)
  • aioesphomeapi/client.py (3 hunks)
  • aioesphomeapi/core.py (2 hunks)
  • aioesphomeapi/model.py (2 hunks)
  • tests/test_client.py (3 hunks)
Additional Context Used
Ruff (1)
tests/test_client.py (1)

758-758: Redefinition of unused test_valve_command from line 735

Additional comments not posted (7)
aioesphomeapi/core.py (2)

122-122: The import of VoiceAssistantTimerEventResponse is correctly added to support the new functionality.


388-388: The addition of VoiceAssistantTimerEventResponse to MESSAGE_TYPE_TO_PROTO is correctly implemented to handle the new event type.

aioesphomeapi/model.py (1)

1264-1269: The addition of the VoiceAssistantTimerEventType enum is correctly implemented and necessary for handling different states of voice assistant timers.

aioesphomeapi/api.proto (2)

1539-1544: The enum VoiceAssistantTimerEvent is well-defined and follows the established naming conventions.


1546-1557: The message VoiceAssistantTimerEventResponse is correctly structured and uses appropriate data types for its fields.

aioesphomeapi/client.py (1)

1391-1408: The implementation of send_voice_assistant_timer_event method looks correct and aligns with the new feature requirements.

Verification successful

The send_voice_assistant_timer_event method is correctly integrated and used within the codebase. The related enum VoiceAssistantTimerEventType and the class VoiceAssistantTimerEventResponse are also properly defined and utilized.

  • The method send_voice_assistant_timer_event is used in tests/test_client.py.
  • The enum VoiceAssistantTimerEventType is defined in aioesphomeapi/model.py.
  • The class VoiceAssistantTimerEventResponse is defined in aioesphomeapi/api_pb2.py.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `send_voice_assistant_timer_event` with the rest of the API.

# Test: Search for the method usage and related enum types. Expect: Proper usage and integration.
rg --type python $'send_voice_assistant_timer_event'

Length of output: 82



Script:

#!/bin/bash
# Description: Verify the integration of `send_voice_assistant_timer_event` with the rest of the API.

# Test: Search for the method usage and related enum types. Expect: Proper usage and integration.
rg 'send_voice_assistant_timer_event'

# Test: Search for the definition and usage of the enum `VoiceAssistantTimerEventType`.
rg 'VoiceAssistantTimerEventType'

# Test: Search for the definition and usage of the class `VoiceAssistantTimerEventResponse`.
rg 'VoiceAssistantTimerEventResponse'

Length of output: 48666

tests/test_client.py (1)

2492-2514: Ensure the new test for sending voice assistant timer events is comprehensive.

It's good to see that the new functionality for voice assistant timer events is being tested. Consider adding more scenarios to cover edge cases, such as invalid inputs or unexpected server responses.

@jesserockz
Copy link
Member Author

@coderabbitai The VoiceAssistantTimerEventResponse is the message sent from the client to the server when send_voice_assistant_timer_event is called. As per my pull request description, the communication is one-way

Copy link
Contributor

coderabbitai bot commented May 27, 2024

Tip

For best results, initiate chat on the files or code changes.

@jesserockz, thank you for the clarification. I understand that the VoiceAssistantTimerEventResponse is used to communicate from the client to the server when send_voice_assistant_timer_event is called, and that this communication is strictly one-way. This is a crucial detail for ensuring the correct implementation and usage of this functionality in the system. If there's anything more to add or adjust regarding this, please let me know!

@jesserockz jesserockz merged commit 0eede84 into main May 27, 2024
8 checks passed
@jesserockz jesserockz deleted the jesserockz-2024-197 branch May 27, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant