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

Area Card Editor: show a list of relevant entities #21117

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

karwosts
Copy link
Contributor

@karwosts karwosts commented Jun 19, 2024

Proposed change

Display the list of entities used in the area card editor. Otherwise this information is quite difficult to find, and often cause unexpected result when there is an extra entity that user doesn't realize.

Perhaps as a further enhancement, the bullet-list could have added checkboxes, which can allow for deselecting/ignoring certain entities from the card.

Also this PR unifies the code for filtering entities in the area between area-card and area-card-editor. Previously they were both implementing the solution in different ways.

image

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Enhanced "Area" card to display observed and controlled entities in the UI.
  • Refactor

    • Refactored internal functions to public exports for better external access to domain-specific entity retrieval and filtering.
    • Improved data management and UI logic with new subscription methods for device and entity registries.
  • Localization

    • Added new translations for "observed_entities" and "controlled_entities" in the "Area" card.

Copy link
Contributor

coderabbitai bot commented Jun 19, 2024

Walkthrough

Walkthrough

The updates center on refactoring internal functions to be public for better modularity and usability in the hui-area-card.ts, enhancing the hui-area-card-editor.ts with improved subscription management for devices and entities, and revising the UI to reflect observed and controlled entities in an area. Additionally, new translation keys were added to support these UI updates.

Changes

File Change Summary
src/panels/lovelace/cards/hui-area-card.ts Refactored internal functions to public exports, enabling external access for domain-specific entity retrieval and filtering.
src/panels/lovelace/editor/config-elements/hui-area-card-editor.ts Introduced imports for new functionalities, enhanced subscription management by extending SubscribeMixin, and updated rendering logic to use entity data for displaying observed and controlled entities.
src/translations/en.json Added new translation keys "observed_entities" and "controlled_entities" for better UI descriptions in the "Area" card.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant LuiAreaCardEditor as HuiAreaCardEditor
    participant DeviceRegistry as DeviceRegistry
    participant EntityRegistry as EntityRegistry
    
    User->>LuiAreaCardEditor: Open Area Card Editor
    LuiAreaCardEditor->>DeviceRegistry: subscribeDeviceRegistry()
    DeviceRegistry-->>LuiAreaCardEditor: Device data
    LuiAreaCardEditor->>EntityRegistry: subscribeEntityRegistry()
    EntityRegistry-->>LuiAreaCardEditor: Entity data
    LuiAreaCardEditor->>LuiAreaCardEditor: Update state with observed and controlled entities
    LuiAreaCardEditor-->>User: Display updated UI with entities
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 8272bef and bcabe27.

Files selected for processing (3)
  • src/panels/lovelace/cards/hui-area-card.ts (8 hunks)
  • src/panels/lovelace/editor/config-elements/hui-area-card-editor.ts (8 hunks)
  • src/translations/en.json (1 hunks)
Additional context used
Biome
src/panels/lovelace/editor/config-elements/hui-area-card-editor.ts

[error] 131-131: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 134-134: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 174-174: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 180-180: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 205-205: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 206-206: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 206-206: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 207-207: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 250-250: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 268-268: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 287-287: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 323-323: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.


[error] 333-333: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 335-335: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 339-339: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 341-341: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 345-345: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 349-349: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 353-353: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

src/panels/lovelace/cards/hui-area-card.ts

[error] 188-188: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 189-189: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 189-189: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 190-190: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 211-211: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 212-212: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 212-212: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 213-213: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 222-222: This variable implicitly has the any type. (lint/suspicious/noImplicitAnyLet)

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.


[error] 240-240: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 242-242: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 252-252: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 255-255: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 258-258: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 305-305: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 306-306: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 329-329: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 415-415: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 415-415: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 476-476: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Gitleaks
src/translations/en.json

6505-6506: Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches. (hashicorp-tf-password)

Additional comments not posted (1)
src/translations/en.json (1)

5670-5671: The addition of "observed_entities" and "controlled_entities" enhances the descriptive capability of the Area card, aligning with the PR's goal to improve entity management visibility.


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.
    • @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 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 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.

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: 2

Outside diff range comments (2)
src/panels/lovelace/editor/config-elements/hui-area-card-editor.ts (1)

Line range hint 323-323: Avoid using the delete operator for performance reasons.

- delete config.camera_view;
+ config.camera_view = undefined;

Using undefined assignment instead of delete can help maintain performance, especially in environments where performance is critical.

src/panels/lovelace/cards/hui-area-card.ts (1)

Line range hint 222-222: Declare a type for the variable to avoid implicit 'any' type.

let uom: string | undefined;

Explicitly declaring the type for uom enhances code readability and maintainability by providing clear information about the expected type.

@piitaya
Copy link
Member

piitaya commented Jun 22, 2024

I wonder if this should be part of the area page instead of the card editor.

@karwosts
Copy link
Contributor Author

I wonder if this should be part of the area page instead of the card editor.

Perhaps, thought that might be a lot of information on one page, and it's somewhat disconnected from the area card where it would be relevant to see it. When people get results they don't expect, or see device_classes they didn't expect available in the selector, I'm not sure if they would know to navigate there to find the information. But perhaps more detail on the area page could be part of a solution to this problem, if there was a good way for it to be discoverable from here.

@SeanPM5
Copy link
Contributor

SeanPM5 commented Jun 23, 2024

I do think being able to see (and ideally manage) which entities are used would be helpful on the area card editor. The way it currently works can lead to unexpected and undesirable results. For example my kitchen area has temp sensors for fridge and freezer which I don't want factored into the temperature reading.


IMO something like Tile card "Features" is probably the best UI / UX for this if it could be repurposed? Did a quick mockup using browser inspector.

  • The current area card defaults (temp, humidity, motion) would remain the same
  • Instead of two different sections for sensor/alert classes, they all get merged into one "Add Feature" button/list. It makes the card editor a bit cleaner and more mobile-friendly, and consistent with some other cards that use features like Tile & Thermostat.
  • Not shown in mockup but if it could display info like "4 entities" in secondary text underneath, that'd be even better
Screen Shot 2024-06-22 at 9 10 23 PM

If user doesn't like what they see, they can either use trash icon to remove that feature from the area card or the pencil/edit icon to exclude the specific entities they don't want. And this subview could use ha-alert to explain how the data gets displayed on the area card so there's no confusion. Something along these lines is what could be displayed for when user clicks the edit icon next to "Temperature" feature.

Mockup

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.

None yet

4 participants