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

Split out service entities #21076

Merged
merged 5 commits into from
Jun 18, 2024
Merged

Split out service entities #21076

merged 5 commits into from
Jun 18, 2024

Conversation

balloob
Copy link
Member

@balloob balloob commented Jun 13, 2024

Breaking change

Proposed change

While ensuring that notify entities are not shown on the generated dashboard, I realized that they are also grouped under "control" on device info page. This PR splits out notify and Assist-related domains to their own cards on the device info page.

CleanShot 2024-06-16 at 13 32 57@2x

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

    • Added categorization for new service-related entities, including "conversation," "notify," "stt," and "tts."
    • Updated device configuration page to include "service" category.
  • Improvements

    • Enhanced hidden domain list to dynamically include service-related entities.
    • Added new translation for "service" in the English language file.

Copy link
Contributor

coderabbitai bot commented Jun 13, 2024

Walkthrough

Walkthrough

The updates primarily address the inclusion and categorization of new entities related to conversation, speech-to-text (stt), and text-to-speech (tts) functionalities. This involves altering icon references, enhancing the categorization logic for devices and entities in the device configuration page, and updating the Lovelace configuration generation process to handle these new entity types. Additionally, new translations for 'assist' and 'notify' have been incorporated to ensure clear labeling in the UI.

Changes

Files Change Summary
src/common/const.ts Updated icons, added new ASSIST_ENTITIES array, and defined services "conversation", "stt", "tts".
src/panels/config/.../ha-config-device-page.ts Updated entity categorization to include new categories "assist" and "notify" and imported ASSIST_ENTITIES.
src/panels/.../generate-lovelace-config.ts Added ASSIST_ENTITIES import, modified the list of hidden domains to include entities from ASSIST_ENTITIES.
src/translations/en.json Added new translations: "notify": "Notifiers", and "assist": "[%key:ui::panel::lovelace::menu::assist%]".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DeviceConfigPage
    participant LovelaceConfig
    participant Icons
    participant Translations

    User ->> DeviceConfigPage: Access Device Config Page
    DeviceConfigPage ->> Icons: Use new 'mdiFormTextbox' and 'mdiForumOutline' icons
    DeviceConfigPage ->> DeviceConfigPage: Categorize new "assist" and "notify" entities
    User ->> LovelaceConfig: Access Lovelace Config
    LovelaceConfig ->> DeviceConfigPage: Obtain `ASSIST_ENTITIES`
    LovelaceConfig ->> LovelaceConfig: Adjust hidden domains with `ASSIST_ENTITIES`
    LovelaceConfig ->> Translations: Fetch new "notify" and "assist" translations
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 0f6892b and 86cf31b.

Files selected for processing (4)
  • src/common/const.ts (3 hunks)
  • src/panels/config/devices/ha-config-device-page.ts (3 hunks)
  • src/panels/lovelace/common/generate-lovelace-config.ts (2 hunks)
  • src/translations/en.json (1 hunks)
Additional context used
Biome
src/panels/lovelace/common/generate-lovelace-config.ts

[error] 63-63: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 18 to the max allowed complexity 15.


[error] 221-224: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 235-238: The assignment should not be in an expression. (lint/suspicious/noAssignInExpressions)

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.


[error] 249-249: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 25 to the max allowed complexity 15.


[error] 128-128: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 42 to the max allowed complexity 15.


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

Unsafe fix: Use an undefined assignment instead.


[error] 347-347: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 27 to the max allowed complexity 15.


[error] 618-618: 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] 624-624: 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] 489-489: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 18 to the max allowed complexity 15.

src/panels/config/devices/ha-config-device-page.ts

[error] 97-97: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 701-701: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 767-767: 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] 769-769: 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] 773-773: 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] 776-776: 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] 777-777: 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] 781-781: 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] 782-782: 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] 786-786: 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] 788-788: 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] 793-793: 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] 796-796: 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] 815-815: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 17 to the max allowed complexity 15.


[error] 297-297: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 61 to the max allowed complexity 15.


[error] 953-953: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


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


[error] 1076-1076: 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] 1290-1290: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


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

Unsafe fix: Use an undefined assignment instead.

Gitleaks
src/translations/en.json

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

Additional comments not posted (6)
src/common/const.ts (2)

102-102: Good update on the conversation icon to mdiForumOutline for consistency with other changes in the PR.


239-240: Ensure that ASSIST_ENTITIES is used consistently across all relevant parts of the application to maintain the integrity of the new entity categorization.

src/panels/lovelace/common/generate-lovelace-config.ts (2)

2-2: Proper import of ASSIST_ENTITIES from ../../../common/const sets a good foundation for its usage in this module.


47-47: Adding ASSIST_ENTITIES to HIDE_DOMAIN ensures that entities related to assistant features do not appear in certain UI elements, aligning with the PR's objectives.

src/panels/config/devices/ha-config-device-page.ts (1)

27-27: The addition of ASSIST_ENTITIES import is aligned with the PR's objective to categorize entities more effectively.

src/translations/en.json (1)

4015-4016: Translations for "notify" and "assist" are correctly implemented.


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.

? "sensor"
: "control"
) as Record<
const result = groupBy(entities, (entry) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

rewrote this to avoid having to compute domain three times

@frenck
Copy link
Member

frenck commented Jun 13, 2024

I'm not sure if "Services" is the thing we should communicate in terms of UX. While this might hold true for a notification service, it becomes pretty confusing considering we have more things called services in our UI/ecosystem. For example, a switch/light has services too, why wouldn't these be marked as such?

Can we think of another grouping we could do? For example: "Notifications" or "Communications" or something like that?

@balloob
Copy link
Member Author

balloob commented Jun 13, 2024

APIs ?

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 comments (9)
src/panels/lovelace/common/generate-lovelace-config.ts (5)

Line range hint 62-62: The function splitByAreaDevice has a high cognitive complexity. Consider breaking down this function into smaller, more manageable functions to improve readability and maintainability.

- const splitByAreaDevice = (
+ const splitEntitiesByArea = (
...
+ const splitEntitiesByDevice = (

Line range hint 220-223: The assignments within these conditional expressions can lead to code that is harder to understand and maintain. Consider refactoring these to separate the assignment and the condition.

- if (titlePrefix && stateObj && (name = stripPrefixFromEntityName(computeStateName(stateObj), titlePrefix))) {
+ const name = titlePrefix && stateObj ? stripPrefixFromEntityName(computeState, titlePrefix) : undefined;
+ if (name) {

Also applies to: 234-237


Line range hint 127-127: Several functions in this file, including computeCards, computeDefaultViewStates, and generateDefaultViewConfig, have excessive complexity. Consider refactoring these functions to simplify logic and improve code clarity.

- const computeCards = (
+ function computeIndividualCards(...) {
...
+ function aggregateCards(...) {
...

Also applies to: 248-248, 346-346, 488-488


Line range hint 416-416: Consider avoiding the use of the delete operator for performance reasons. Instead, you could set the property to undefined or use a different method to manage the object properties.

- delete devicesWithEntities[deviceId];
+ devicesWithEntities[deviceId] = undefined;

Line range hint 617-617: The non-null assertion operator is used, which can be unsafe. Consider replacing it with optional chaining to ensure the code is more robust and less prone to runtime errors.

- grid.flow_from.length > 0
+ grid?.flow_from?.length > 0

Also applies to: 623-623

src/panels/config/devices/ha-config-device-page.ts (4)

Line range hint 97-97: Please specify more appropriate types instead of using any. Using any disables TypeScript's type checking, which can lead to potential runtime errors and maintenance challenges.

- action?: (ev: any) => void;
+ action?: (ev: Event) => void; // or a more specific event type if applicable

- action: (ev) => this._signUrl(ev),
+ action: (ev: MouseEvent) => this._signUrl(ev),

- action = (ev) => {
+ action = (ev: CustomEvent) => {

- action(ev) {
+ action(ev: KeyboardEvent) {

Also applies to: 698-698, 949-949, 1286-1286


Line range hint 764-764: Using non-null assertions can lead to runtime errors if not handled carefully. Consider using optional chaining (?.) to safely access properties and methods.

- this.hass.devices[this.deviceId]
+ this.hass.devices?.[this.deviceId]

- this.hass.localize("ui.common.enable")
+ this.hass.localize?.("ui.common.enable")

- device.configuration_url!.replace("homeassistant://", "/")
+ device.configuration_url?.replace("homeassistant://", "/")

Also applies to: 766-766, 770-770, 773-773, 774-774, 778-778, 779-779, 783-783, 785-785, 790-790, 793-793, 1034-1034, 1072-1072


Line range hint 294-294: The complexity of these functions exceeds the recommended limit. Refactoring them to reduce complexity will improve maintainability and readability. Consider breaking down complex logic into smaller, more manageable functions.

- private _getDeviceActions() {
+ private async _getDeviceActions(): Promise<void> {
+   // Refactor to reduce complexity
+ }
- private _renderIntegrationInfo(
+ private _renderIntegrationInfo(
+   device: DeviceRegistryEntry,
+   integrations: ConfigEntry[],
+   deviceInfo: TemplateResult[]
+ ): void {
+   // Simplify or split the function to reduce complexity
+ }

Also applies to: 812-812


Line range hint 1302-1302: Avoid using the delete operator for performance reasons. Consider setting the property to undefined instead.

- delete updates.disabled_by;
+ updates.disabled_by = undefined;

coderabbitai[bot]

This comment was marked as duplicate.

@frenck
Copy link
Member

frenck commented Jun 14, 2024

APIs ?

One of the approaches we quickly discussed during our frontend standup, was to maybe split it in two groups.

  1. Notification or Notifiers (notify entities)
  2. Assist (tts, sst, conversation)

As notify really doesn't match well with the rest.

@@ -98,7 +99,7 @@ export const FIXED_DOMAIN_ICONS = {
calendar: mdiCalendar,
climate: mdiThermostat,
configurator: mdiCog,
conversation: mdiMicrophoneMessage,
conversation: mdiForumOutline,
Copy link
Member Author

Choose a reason for hiding this comment

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

this one was duplicate with STT.

@balloob
Copy link
Member Author

balloob commented Jun 16, 2024

Updated per comments.

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 (10)
src/panels/lovelace/common/generate-lovelace-config.ts (5)

Line range hint 63-63: Refactor the splitByAreaDevice function to reduce complexity and improve maintainability.

Consider breaking down the function into smaller, more manageable parts. For example, handling areas and devices could be separated into different functions.


Line range hint 221-224: Avoid using assignments within expressions as they can lead to code that is difficult to read and maintain.

- name = stripPrefixFromEntityName(computeStateName(stateObj), titlePrefix)
+ const name = stripPrefixFromEntityName(computeStateName(stateObj), titlePrefix)

Also applies to: 235-238


Line range hint 249-249: The complexity of computeCards function is too high. Consider refactoring to simplify the logic.

Possible refactoring could involve splitting the function into smaller sub-functions that handle specific aspects of card computation.


Line range hint 417-417: Replace the use of the delete operator with setting the property to undefined to avoid potential performance issues.

- delete devicesWithEntities[deviceId];
+ devicesWithEntities[deviceId] = undefined;

Line range hint 618-618: Replace non-null assertions with optional chaining to ensure safer access to properties.

- grid.flow_from.length > 0
+ grid?.flow_from?.length > 0

Also applies to: 624-624

src/panels/config/devices/ha-config-device-page.ts (5)

Line range hint 815-815: Excessive complexity detected in this function. Refactoring is recommended to reduce complexity and enhance maintainability.

Consider breaking down the function into smaller, more manageable sub-functions or using more streamlined logic to simplify the code.


Line range hint 297-297: The complexity of this function exceeds the maximum allowed. Refactoring is necessary to simplify the logic and improve code readability.

Consider breaking down the complex conditionals and loops into smaller helper functions or using data-driven approaches to simplify the decision-making process.


Line range hint 97-97: Usage of any type should be avoided as it disables TypeScript's type checking. Specifying explicit types enhances type safety and code maintainability.

Consider replacing any with specific types or interfaces that accurately describe the expected data structures.

Also applies to: 701-701, 953-953, 1290-1290


Line range hint 767-767: Usage of non-null assertion operators is discouraged as they bypass TypeScript's strict null checks. This could lead to runtime errors if the assumptions about non-null values are incorrect.

Consider replacing non-null assertions with optional chaining or appropriate runtime checks to ensure safety.

Also applies to: 769-769, 773-773, 776-776, 777-777, 781-781, 782-782, 786-786, 788-788, 793-793, 796-796, 1038-1038, 1076-1076


Line range hint 1306-1306: The use of the delete operator can lead to performance issues due to deoptimizations in JavaScript engines.

Consider setting the property to undefined or restructuring the code to avoid the need for deletion.

- delete someProperty;
+ someProperty = undefined;

@@ -31,6 +31,7 @@ import {
mdiFormatListBulleted,
mdiFormatListCheckbox,
mdiFormTextbox,
mdiForumOutline,
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment explaining the use of mdiForumOutline for better code clarity.

Comment on lines +193 to +213
const result = groupBy(entities, (entry) => {
const domain = computeDomain(entry.entity_id);

if (entry.entity_category) {
return entry.entity_category;
}

if (domain === "event" || domain === "notify") {
return domain;
}

if (SENSOR_ENTITIES.includes(domain)) {
return "sensor";
}

if (ASSIST_ENTITIES.includes(domain)) {
return "assist";
}

return "control";
}) as Record<
Copy link
Contributor

Choose a reason for hiding this comment

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

Updated _entitiesByCategory method to categorize entities based on their domain and entity category. This aligns with the PR's objectives to handle "notify" and "assist" entities distinctly. However, consider adding a default case to handle any unforeseen categories.

+        default:
+          return "other"; // Handle any unforeseen categories
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
const result = groupBy(entities, (entry) => {
const domain = computeDomain(entry.entity_id);
if (entry.entity_category) {
return entry.entity_category;
}
if (domain === "event" || domain === "notify") {
return domain;
}
if (SENSOR_ENTITIES.includes(domain)) {
return "sensor";
}
if (ASSIST_ENTITIES.includes(domain)) {
return "assist";
}
return "control";
}) as Record<
const result = groupBy(entities, (entry) => {
const domain = computeDomain(entry.entity_id);
if (entry.entity_category) {
return entry.entity_category;
}
if (domain === "event" || domain === "notify") {
return domain;
}
if (SENSOR_ENTITIES.includes(domain)) {
return "sensor";
}
if (ASSIST_ENTITIES.includes(domain)) {
return "assist";
}
return "control";
+ default:
+ return "other"; // Handle any unforeseen categories
}) as Record<

@silamon silamon merged commit 9c153bb into dev Jun 18, 2024
13 checks passed
@silamon silamon deleted the split-out-service-entities branch June 18, 2024 06:58
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