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

Add support for renaming entities dynamically #877

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

Conversation

sibest19
Copy link

@sibest19 sibest19 commented Jan 1, 2025

Description

This PR introduces a new action to the Spook integration, allowing users to rename entities dynamically. It updates the services.yaml file and associated documentation to include the new homeassistant.rename_entity action.

Motivation and Context

This new action allows users to rename an entity without needing to go through the UI process, enabling more efficient workflows. It also provides the ability to dynamically rename entities within automations and scripts, or perform bulk renaming of multiple entities at once, helping users maintain better naming conventions in their smart homes. Additionally, this action aligns with other entity management functionalities already provided, such as changing entity IDs, ensuring consistency and enhancing the flexibility of entity customization.

How has this been tested?

  • Testing was conducted using the provided devcontainer on Home Assistant 2024.4.0, which significantly streamlined onboarding and development. Kudos for making the process so seamless! ❤️
  • The homeassistant.rename_entity action was manually tested to ensure it successfully renames single and multiple entities.
  • Verified that new names persist between restarts and are updated dynamically across all dashboards.

Screenshots (if appropriate):

rename_entity

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link

coderabbitai bot commented Jan 1, 2025

📝 Walkthrough

Walkthrough

A new service for renaming entities has been introduced in the Spook integration for Home Assistant. This feature allows users to dynamically change the names of entities through a new service called homeassistant_rename_entity. The implementation includes a new service class in the rename_entity.py file, an update to the services.yaml configuration, and corresponding documentation updates across multiple markdown files to explain the new functionality.

Changes

File Change Summary
custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py Added SpookService class for renaming entities
custom_components/spook/services.yaml Added homeassistant_rename_entity action
documentation/actions.md Added documentation for the new "Rename" entity action
documentation/core_extensions.md Updated entity management section description
documentation/entities.md Added details for the new homeassistant.rename_entity action

Sequence Diagram

sequenceDiagram
    participant User
    participant HomeAssistant
    participant EntityRegistry
    User->>HomeAssistant: Call rename_entity service
    HomeAssistant->>EntityRegistry: Update entity name
    EntityRegistry-->>HomeAssistant: Confirm name change
    HomeAssistant-->>User: Service completed
Loading

Poem

🐰 A rabbit's ode to entity rename,
Hop, skip, and change that name with fame!
No more static labels, we're breaking free,
Renaming entities with magical glee!
Watch Home Assistant dance and prance! 🏠✨


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

sonarqubecloud bot commented Jan 1, 2025

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

🧹 Nitpick comments (5)
custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py (2)

1-2: Consider expanding docstring for clarity.
The current docstring, "Spook - Your homie.", is not very descriptive of the file’s purpose. A short summary of the service’s functionality (e.g., “Service for renaming entities in Home Assistant”) might be more helpful.


23-26: Consider validating non-empty name field.
While cv.string enforces a string type, consider prohibiting empty strings to ensure the entity’s display name is always meaningful. You might want to add a custom validator or incorporate a minimal length check.

documentation/entities.md (1)

439-442: Clarify “friendly_name” vs. “entity_id.”
These lines describe updating the “friendly_name” (through name) rather than the entity ID. It might help users if you explicitly note that changing the friendly_name doesn’t alter the entity’s underlying ID.

documentation/actions.md (1)

127-131: Minor punctuation/language refinement.
Around line 131, consider rephrasing to avoid the extra underscore near “#LookMaNewName_”. For instance, “#LookMaNewName” might be changed to “#LookMaNewName!” or simply “#LookMaNewName.”

-This action can be used to rename an entity on the fly. _#LookMaNewName_
+This action can be used to rename an entity on the fly. #LookMaNewName
🧰 Tools
🪛 LanguageTool

[uncategorized] ~131-~131: Loose punctuation mark.
Context: ...aNewName_ homeassistant.rename_entity, [Try this action](https://my.home-assis...

(UNLIKELY_OPENING_PUNCTUATION)

custom_components/spook/services.yaml (1)

293-311: LGTM! Consider enhancing the documentation.

The service definition follows the established patterns and integrates well with existing entity management services. However, the description could be more detailed about:

  • Whether the rename persists across restarts
  • Impact on entity history/statistics
  • Behavior when renaming multiple entities with a single name

Apply this diff to enhance the documentation:

   description: >-
-    Renames an entity (or entities) on the fly.
+    Renames an entity (or entities) on the fly. The new name persists across 
+    Home Assistant restarts and is reflected in the UI, history, and statistics. 
+    When renaming multiple entities, the same name will be applied to all 
+    selected entities.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between af46304 and 3ca0e35.

⛔ Files ignored due to path filters (1)
  • documentation/images/entities/rename_entity.png is excluded by !**/*.png
📒 Files selected for processing (5)
  • custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py (1 hunks)
  • custom_components/spook/services.yaml (1 hunks)
  • documentation/actions.md (1 hunks)
  • documentation/core_extensions.md (1 hunks)
  • documentation/entities.md (2 hunks)
🧰 Additional context used
🪛 LanguageTool
documentation/actions.md

[uncategorized] ~131-~131: Loose punctuation mark.
Context: ...aNewName_ homeassistant.rename_entity, [Try this action](https://my.home-assis...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (4)
custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py (1)

28-35: Handle potential non-existent entities gracefully.
Currently, the loop updates any entity in call.data["entity_id"] without verifying existence. Consider logging a warning or skipping if an entity ID is not found in the registry.

documentation/core_extensions.md (1)

29-29: Documentation updated successfully.
The addition of “rename” to the set of entity management actions aligns perfectly with the new functionality.

documentation/entities.md (2)

449-481: Schema layout looks consistent.
The action parameters (entity_id and name) are clear, and the documentation follows the same style as existing actions. Excellent coherence!


483-494: Great example usage.
Providing a YAML snippet makes it straightforward for users to integrate the rename action into their automations. This lowers the barrier to adoption.

@sibest19
Copy link
Author

Hello! 🙂 Is there a chance someone could help with the PR labels and review? 🙏🏼

@frenck frenck added the new-feature New features or options. label Feb 20, 2025
Copy link

sonarqubecloud bot commented Mar 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature New features or options.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants