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

[EN] Explicit and friendly domain name for HassTurnOn/HassTurnOff #2418

Merged

Conversation

tetele
Copy link
Contributor

@tetele tetele commented Oct 16, 2024

"Turn on the TV" would hare produced the response "Turned on the media_player", read as "Turned on media underscore player"

We've patched this by adding a map of how each domain should be handled in the response text.

Other approaches would have been to:

  • use the name slot instead of domain (such as in RO)
  • add the domain without underscore in the response for the media_player domain, which is what I wanted to do with metadata
  • programatically convert underscores to spaces in all domains - it could encounter edge cases

Summary by CodeRabbit

  • New Features
    • Enhanced responses for the HassTurnOn and HassTurnOff intents with dynamic feedback based on device types.
    • Introduced a translation system for clearer and more specific messages related to various devices.

These updates improve user interaction by providing contextually relevant responses when controlling devices.

Copy link

coderabbitai bot commented Oct 16, 2024

📝 Walkthrough

Walkthrough

The pull request introduces dynamic responses for the HassTurnOn and HassTurnOff intents in their respective YAML files. The previous static responses have been replaced with Jinja2 templates that utilize a dictionary of translations for various device types. This change allows the responses to provide more contextually relevant feedback based on the specific device being controlled, enhancing user interaction.

Changes

File Path Change Summary
responses/en/HassTurnOn.yaml Updated response from static "Turned on the {{ state.domain }}" to dynamic using Jinja2 template with translations.
responses/en/HassTurnOff.yaml Updated response from static "Turned off the {{ state.domain }}" to dynamic using Jinja2 template with translations.

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>, 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 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 or @coderabbitai title 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

@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

🧹 Outside diff range and nitpick comments (8)
tests/en/media_player_HassTurnOn.yaml (1)

3-9: Consider adding a generic media player test case.

The current test cases cover various ways to turn on a TV, which is great. To improve test coverage, consider adding a test case for a generic media player. This would ensure the intent works correctly for other types of media players as well.

Here's a suggested addition:

  - sentences:
      - "turn on the media player"
      - "activate the media player"
    intent:
      name: HassTurnOn
      slots:
        domain: media_player
        name: media player
    response: "Turned on"
tests/en/media_player_HassTurnOff.yaml (3)

4-9: LGTM: Comprehensive set of test sentences.

The test sentences cover a wide range of variations for the "turn off TV" command, including different word orders and phrasings. This comprehensive set will help ensure robust intent recognition.

Consider adding a sentence with a more specific TV name, e.g., "turn off the living room TV", to test handling of multi-word device names.


10-14: LGTM: Intent and slots are correctly defined.

The intent name and slots are properly set up for the "turn off TV" use case.

Consider parameterizing the "name" slot in the test case to allow for testing with different device names. This could help ensure the intent works correctly for various media player names beyond just "TV".


1-15: Great job! This test file effectively addresses the PR objectives.

The media_player_HassTurnOff.yaml test file is well-structured and comprehensive. It successfully implements the proposed solution of removing the domain from the response for the media_player domain. The test cases cover various phrasings for turning off a TV, and the expected response is clear and concise.

This implementation effectively resolves the issue of incorrect pronunciation in voice responses without compromising the functionality of the intent recognition system.

As the project evolves, consider creating a centralized configuration for common device types and their aliases. This could make it easier to maintain consistency across different intents and languages.

sentences/en/media_player_HassTurnOn.yaml (1)

5-8: LGTM: Sentence patterns are comprehensive and flexible.

The defined sentence patterns cover various ways a user might phrase the command to turn on a media player, which aligns well with the PR objectives.

Consider adding a pattern for "power on" as an alternative to "turn on", e.g., " on ( | [in ])". This might capture additional user phrasings.

sentences/en/media_player_HassTurnOff.yaml (1)

5-8: LGTM: Sentence structures are comprehensive.

The defined sentence structures provide good flexibility for users to turn off media players. They cover various phrasings and include options for specifying areas.

Consider adding a structure for plural forms, such as:

- "<turn> off (<area> <name>|<name> [in <area>]){s}"

This would allow for commands like "Turn off the TVs in the living room".

responses/en/HassTurnOn.yaml (1)

16-16: LGTM! The change addresses the issue effectively.

The new entry for media_player successfully removes the domain from the response, addressing the mispronunciation issue described in the PR objectives. This change will improve the clarity of voice responses for media player commands.

Consider enhancing this further by utilizing the name slot if available, which could provide more specific feedback when multiple media players are present. For example:

media_player: >
  {% if slots.name %}Turned on {{ slots.name }}{% else %}Turned on{% endif %}

This would allow responses like "Turned on Living Room TV" when a name is available, while falling back to the generic "Turned on" when it's not.

responses/en/HassTurnOff.yaml (1)

Line range hint 1-15: Consider consistency and future improvements across domains

While the current change effectively solves the immediate issue, consider the following points for future improvements:

  1. The media_player response is notably shorter than others. For consistency, you might want to consider a slightly more verbose response, such as "Turned off the player" or "Turned off the device".

  2. This change might set a precedent for handling other domains with underscores or spaces. It might be worth considering a more general solution that could be applied consistently across all domains.

  3. As mentioned in the PR objectives, adding the domain without underscores could be a potential middle ground. For example: "Turned off the media player".

These suggestions aim to balance solving the current issue while maintaining consistency and planning for potential future challenges.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8a33a02 and 1465cb6.

📒 Files selected for processing (8)
  • responses/en/HassTurnOff.yaml (1 hunks)
  • responses/en/HassTurnOn.yaml (1 hunks)
  • sentences/en/homeassistant_HassTurnOff.yaml (1 hunks)
  • sentences/en/homeassistant_HassTurnOn.yaml (1 hunks)
  • sentences/en/media_player_HassTurnOff.yaml (1 hunks)
  • sentences/en/media_player_HassTurnOn.yaml (1 hunks)
  • tests/en/media_player_HassTurnOff.yaml (1 hunks)
  • tests/en/media_player_HassTurnOn.yaml (1 hunks)
🧰 Additional context used
🔇 Additional comments (18)
tests/en/media_player_HassTurnOn.yaml (2)

1-2: LGTM: File structure is correct.

The YAML file structure is appropriate for a test configuration, with the language specified and a tests array defined.


3-15: LGTM: Content aligns well with PR objectives.

The test case content effectively addresses the PR's main objective:

  1. Various sentence variations for turning on a TV are included (lines 3-9).
  2. The intent structure correctly defines 'HassTurnOn' with appropriate slots (lines 10-14).
  3. The response "Turned on" (line 15) resolves the issue by removing the domain from the response, avoiding the "media underscore player" pronunciation problem.

This implementation successfully achieves the goal of improving voice responses for media player commands.

tests/en/media_player_HassTurnOff.yaml (3)

1-1: LGTM: Language specification is correct.

The language specification aligns with the file location and the PR objectives.


2-3: LGTM: Test case structure is well-defined.

The YAML structure for the test case is correct and follows the expected format.


15-15: LGTM: Response aligns with PR objectives.

The expected response "Turned off" is concise and clear. It successfully addresses the PR's main objective by removing the domain from the response, which solves the issue of incorrect pronunciation of "media_player".

This implementation effectively resolves the problem described in the PR summary.

sentences/en/media_player_HassTurnOn.yaml (4)

1-3: LGTM: Language and intent declaration are correct.

The language is correctly set to English, and the intent name "HassTurnOn" is clear and follows the naming convention.


9-10: LGTM: Domain specification is correct.

The slot definition correctly specifies the domain as "media_player", which aligns with the PR objectives of addressing the issue specifically for the media_player domain.


11-12: LGTM: Context requirement is appropriate.

The context requirement ensures that this intent is only triggered in the context of a media player, which is appropriate for the intended functionality.


13-13: Verify if this response resolves the pronunciation issue.

The response is set to "media_player", which might not directly address the pronunciation issue mentioned in the PR objectives. The goal was to avoid the "media underscore player" pronunciation.

Consider modifying the response to remove the domain entirely, as suggested in the PR objectives. For example:

response: turn_on

This would allow for a generic "Turned on" response without mentioning the media player, potentially resolving the pronunciation issue.

To verify the current implementation, please run the following script:

This will help us ensure that the response is consistent and doesn't include the problematic "media_player" phrase in other files.

sentences/en/media_player_HassTurnOff.yaml (6)

1-1: LGTM: Language declaration is correct.

The language is correctly set to "en" for English, which aligns with the PR objectives.


2-3: LGTM: Intent declaration is correct.

The intent HassTurnOff is correctly declared and matches the file name and PR objectives.


9-10: LGTM: Slot definition is correct.

The slot domain is correctly set to "media_player", which aligns with the PR objectives to handle media player responses specifically.


11-12: LGTM: Context requirement is appropriate.

The context requirement ensures that this intent is only triggered for media players, which is in line with the PR objectives.


13-13: LGTM: Response category is set correctly.

The response category is set to "media_player", which aligns with the PR objectives to address the issue with media player responses.

To ensure this change resolves the pronunciation issue mentioned in the PR objectives, please verify that the response generated does not include "media_player" in the output. You can do this by testing the intent with various inputs and checking the responses.

#!/bin/bash
# Description: Search for response templates that might still include "media_player"

# Test: Search for response templates containing "media_player"
rg --type yaml 'response:.*media_player' sentences/en/

1-13: Overall, the changes in this file effectively address the PR objectives.

The new HassTurnOff intent for media players is well-structured and should resolve the issue with incorrect pronunciation of "media_player" in responses. The sentence structures, slots, context requirements, and response category are all aligned with the goal of improving voice responses for media player commands.

To ensure full compatibility with the existing system:

  1. Verify that this new intent doesn't conflict with any existing intents for turning off devices.
  2. Test the intent with various phrasings to ensure it covers all expected use cases.
  3. Confirm that the response generated doesn't include "media_player" in the output.
sentences/en/homeassistant_HassTurnOff.yaml (1)

17-17: Approved: Addition of media_player to excluded contexts.

The change correctly addresses the PR objective by excluding the media_player domain from the HassTurnOff intent. This should prevent the incorrect "Turned off the media_player" response.

However, could you please clarify how media players will be turned off after this modification? Will there be a separate intent or handling mechanism for media players?

To ensure this change doesn't break existing functionality, please run the following verification:

responses/en/HassTurnOff.yaml (2)

15-15: LGTM! This change effectively addresses the PR objective.

The addition of media_player: "Turned off" successfully resolves the issue of mispronouncing "media_player" in voice responses. This concise response aligns perfectly with the PR's goal of improving clarity for media player commands.


Line range hint 1-15: Verify consistency across languages and usage

To ensure this change doesn't introduce inconsistencies or break existing functionality, please run the following verification steps:

Please review the results of these checks to ensure that:

  1. The media_player entry is consistently handled across all language files.
  2. There are no hardcoded expectations of the response format that might break due to this change.
  3. All relevant tests are updated to reflect this change.

@@ -15,3 +15,4 @@ intents:
- script
- sensor
- valve
- media_player
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent Exclusion of 'media_player' Across Intent Files

The addition of 'media_player' to the excluded domains in sentences/en/homeassistant_HassTurnOn.yaml is approved. However, media_player is still included in multiple other intent files across various languages. To maintain consistency and prevent unintended behavior, please verify and apply similar exclusions where necessary.

🔗 Analysis chain

Approved: Addition of 'media_player' to excluded domains.

This change aligns with the PR objective to address the issue with media player responses. It's a minimal and focused modification that should resolve the problem of incorrect pronunciation in voice responses.

To ensure this change doesn't have unintended consequences, please verify:

  1. That turning on media players still works correctly through other means.
  2. That this change is consistent with any related files or intents.

Run the following script to check for any other occurrences of 'media_player' in intent files that might need similar modifications:

This will help ensure consistency across the intent system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for 'media_player' occurrences in other intent files

# Test: Look for 'media_player' in other YAML files
rg --type yaml 'media_player' sentences/

Length of output: 9382


Script:

#!/bin/bash
# Description: Verify if 'media_player' exclusions are present in other HassTurnOn intent files

# Search for 'HassTurnOn' intent files across all languages
fd --type f 'HassTurnOn.yaml' sentences/ --exec grep -H 'media_player' {}

Length of output: 364

@tetele tetele marked this pull request as draft October 16, 2024 13:01
Copy link
Contributor

@TheFes TheFes left a comment

Choose a reason for hiding this comment

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

Looks good to me

@tetele tetele changed the title [EN] Fix response when turning media player on/off [EN] Explicit and friendly domain name for HassTurnOn/HassTurnOff Oct 22, 2024
@tetele tetele marked this pull request as ready for review October 22, 2024 07:14
@tetele tetele requested a review from TheFes October 22, 2024 07:14
Copy link

@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 (3)
responses/en/HassTurnOn.yaml (2)

5-25: Approve with suggestions: Dynamic response improves clarity, but consider refinements.

The introduction of a dynamic response using a Jinja2 template is a significant improvement. It addresses the PR objective of providing more accurate and user-friendly responses for different device types. However, I have a few suggestions to enhance this implementation:

  1. Add a fallback for unknown device types to ensure clear responses in all scenarios. For example:

    Turned on {{ translations.get(state.domain, "the " + state.domain.replace('_', ' ')) }}
  2. Consider moving the translations dictionary to a separate file (e.g., device_translations.yaml) and importing it. This would improve maintainability and allow reuse across multiple intents.

  3. Be cautious with the current indentation of the Jinja2 template. YAML is sensitive to indentation, and the current structure might lead to parsing issues. Ensure that the YAML structure is preserved when the template is processed.

Would you like assistance in implementing these suggestions?


Line range hint 26-38: Consider reviewing specific responses for consistency.

While the new default response provides improved clarity for various device types, there are some potential inconsistencies with the specific responses that remain unchanged. For example:

  • Default: "Turned on the media player"
  • Lights: "Turned on the lights"
  • Cover: "Opened"

To maintain a consistent user experience across all device types, consider reviewing and potentially updating these specific responses to align with the new default response style.

Would you like assistance in drafting consistent responses for these specific device types?

responses/en/HassTurnOff.yaml (1)

5-25: Improved response specificity, but consider further enhancements

The changes effectively address the PR objective by providing more specific and user-friendly responses for different device types. This solution resolves the issue with incorrect pronunciation of "media_player" and offers flexibility for future extensions.

However, there are a few considerations and potential improvements:

  1. The translations dictionary is quite long. Consider moving it to a separate file for better maintainability and potential reuse across other intent files (e.g., HassTurnOn.yaml).

  2. Ensure consistency with other response files, particularly HassTurnOn.yaml, to maintain a uniform user experience.

  3. Add a fallback for unknown domains to prevent potential errors. For example:

Turned off {{ translations.get(state.domain, "the " + state.domain.replace("_", " ")) }}

This fallback would replace underscores with spaces for unknown domains, providing a reasonable default response.

Would you like assistance in implementing these suggestions?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1465cb6 and 355d954.

📒 Files selected for processing (2)
  • responses/en/HassTurnOff.yaml (1 hunks)
  • responses/en/HassTurnOn.yaml (1 hunks)
🧰 Additional context used

@tetele
Copy link
Contributor Author

tetele commented Oct 22, 2024

@coderabbitai

Add a fallback for unknown domains to prevent potential errors. For example:

The point of these files are to be easily interpreted and translated by the language leaders, so adding extra code complexity will harm legibility. A response such as "Turned on" is perfectly fine (i.e. without domain name) in case an unknown domain happens to be assigned to an entity.

Copy link

coderabbitai bot commented Oct 22, 2024

Tip

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

@tetele: Understood, thank you for explaining your reasoning. Keeping the responses simple for better legibility by the language leaders makes sense.

(_/)
(._.)
/ \

Copy link
Contributor

@jlpouffier jlpouffier left a comment

Choose a reason for hiding this comment

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

Thx very much! This will greatly help other language leaders

@tetele tetele merged commit b4e77bb into home-assistant:main Oct 22, 2024
3 checks passed
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.

3 participants