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

20240627.0 #21192

Merged
merged 7 commits into from
Jun 27, 2024
Merged

20240627.0 #21192

merged 7 commits into from
Jun 27, 2024

Conversation

bramkragten
Copy link
Member

@bramkragten bramkragten commented Jun 27, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced QR scanning functionality with improved error handling and external barcode scanner integration.
    • Introduced configuration entries handling in device and area selectors.
    • Added last-updated option for state content in tile cards.
    • Improved dynamic loading for various Lovelace card elements.
  • Bug Fixes

    • Fixed QR code error handling in Z-Wave JS add node dialog.
  • Style

    • Updated CSS styling for grid, horizontal stack, and tile cards for better layout and display.
  • Chores

    • Updated @types/chromecast-caf-receiver to version 6.0.16.
    • Updated project version to "20240627.0".

renovate bot and others added 7 commits June 27, 2024 06:34
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Fix device integration filter for entityless devices

* code review
* Wait for hass and config before building the card

* Don't use setter

* Improve code readability

* Use hasupdated

* Rename build to load
* Fix size of cards inside stack cards

* Apply style everywhere

* Fix stack

* Fix grid stack

* Set block only for square
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

Walkthrough

The updates enhance QR and barcode scanning functionality, improve error handling, and integrate more configuration data into selectors in Home Assistant's frontend. New class attributes, methods, and state properties were introduced to support these changes. Additionally, several Lovelace dashboard cards and components now support loading elements dynamically and include new content options.

Changes

File(s) Change Summary
package.json Updated @types/chromecast-caf-receiver version from 6.0.15 to 6.0.16.
pyproject.toml Updated the project version from 20240626.2 to 20240627.0.
src/components/ha-qr-scanner.ts Enhanced QR scanning, error handling, and added external barcode scanner support.
src/components/ha-selector/... Added _configEntries state property and async fetching logic in selector components.
src/data/device_registry.ts Updated getDeviceIntegrationLookup to handle devices and config entries with Set<string>.
src/data/selector.ts Changed filterSelectorDevices to use Set for deviceIntegrationLookup.
src/panels/config/.../dialog-zwave_js-add-node.ts Enhanced QR code error handling and rendering logic.
src/panels/lovelace/cards/... Added element.load() in various Lovelace card classes.
src/translations/en.json Added new translation for "last-updated" under "state_content_options".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HaQrScanner
    participant ExternalScanner
    participant HaComponent

    User->>+HaQrScanner: Start scanning
    HaQrScanner->>ExternalScanner: _openExternalScanner()
    ExternalScanner-->>HaQrScanner: Scanner ready
    
    HaQrScanner->>ExternalScanner: _notifyExternalScanner("start")
    ExternalScanner->>HaQrScanner: _qrCodeScanned(qrCodeString)
    HaQrScanner->>HaQrScanner: Process QR code

    HaQrScanner->>ExternalScanner: _closeExternalScanner()
    HaQrScanner-->>User: Display scanned code
    User->>+HaComponent: Integrate scanned data
    HaComponent-->>User: Data integrated successfully
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 5bc3ad4 and da2865d.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (21)
  • package.json (1 hunks)
  • pyproject.toml (1 hunks)
  • src/components/ha-qr-scanner.ts (5 hunks)
  • src/components/ha-selector/ha-selector-area.ts (4 hunks)
  • src/components/ha-selector/ha-selector-device.ts (4 hunks)
  • src/components/ha-selector/ha-selector-floor.ts (4 hunks)
  • src/data/device_registry.ts (2 hunks)
  • src/data/selector.ts (2 hunks)
  • src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts (4 hunks)
  • src/panels/lovelace/cards/hui-card.ts (4 hunks)
  • src/panels/lovelace/cards/hui-conditional-card.ts (1 hunks)
  • src/panels/lovelace/cards/hui-entity-filter-card.ts (1 hunks)
  • src/panels/lovelace/cards/hui-grid-card.ts (1 hunks)
  • src/panels/lovelace/cards/hui-horizontal-stack-card.ts (1 hunks)
  • src/panels/lovelace/cards/hui-stack-card.ts (2 hunks)
  • src/panels/lovelace/cards/hui-tile-card.ts (1 hunks)
  • src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts (1 hunks)
  • src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts (1 hunks)
  • src/panels/lovelace/sections/hui-section.ts (1 hunks)
  • src/panels/lovelace/views/hui-view.ts (1 hunks)
  • src/translations/en.json (1 hunks)
Files not reviewed due to errors (2)
  • src/components/ha-qr-scanner.ts (no review received)
  • package.json (no review received)
Additional context used
Biome
src/panels/lovelace/cards/hui-horizontal-stack-card.ts

[error] 26-26: Using super in a static context can be confusing.

super refers to a parent class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

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

[error] 73-73: Using super in a static context can be confusing.

super refers to a parent class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/components/ha-selector/ha-selector-device.ts

[error] 33-33: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 147-147: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)

src/components/ha-selector/ha-selector-area.ts

[error] 29-29: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)

src/components/ha-selector/ha-selector-floor.ts

[error] 29-29: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)

src/data/device_registry.ts

[error] 158-158: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 159-159: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 160-160: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 149-149: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

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

[error] 94-94: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 105-105: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 155-155: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 163-163: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 164-164: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 134-134: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

src/panels/lovelace/cards/hui-entity-filter-card.ts

[error] 147-147: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 150-150: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 155-155: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 158-158: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 177-177: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 185-185: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 190-190: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 208-208: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts

[error] 185-185: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 203-203: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 204-204: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 204-204: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 206-206: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 207-207: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 207-207: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 209-209: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 210-210: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

src/panels/lovelace/sections/hui-section.ts

[error] 172-172: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 193-193: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 194-194: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 195-195: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 196-196: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 197-197: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 198-198: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 261-261: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 261-261: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 263-263: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)

src/components/ha-qr-scanner.ts

[error] 101-101: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 156-156: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 162-162: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 166-166: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 175-175: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 207-207: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 211-211: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 234-234: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 248-248: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)

src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts

[error] 215-215: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 270-270: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 306-306: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 327-327: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 332-332: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 354-354: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 368-368: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 369-369: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 373-373: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 373-373: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 376-376: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 376-376: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 379-379: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 382-382: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 407-407: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 412-412: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)

src/panels/lovelace/views/hui-view.ts

[error] 93-93: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 118-118: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 174-174: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 186-186: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 215-215: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 262-262: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 284-284: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 285-285: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 286-286: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 287-287: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 288-288: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 289-289: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 290-290: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 291-291: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 300-300: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 326-326: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 326-326: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 328-328: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 340-340: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 345-345: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)

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

[error] 139-139: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 139-139: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 139-139: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 145-145: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 146-146: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 148-148: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 158-158: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 231-231: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 260-260: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 265-265: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 310-311: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 388-388: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 389-389: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 332-332: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

src/data/selector.ts

[error] 340-340: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 364-364: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 689-689: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 727-727: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)


[error] 784-786: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 812-814: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 92-92: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 104-104: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 109-109: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 155-155: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 160-160: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 296-296: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 314-314: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 329-329: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 359-359: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 372-372: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 421-421: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 429-429: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts

[error] 267-267: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)


[error] 111-111: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)


[error] 572-572: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 611-611: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 636-636: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 639-639: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 653-653: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 660-660: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 685-685: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 686-686: Forbidden non-null assertion.

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

(lint/style/noNonNullAssertion)


[error] 688-688: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 702-702: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 705-705: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)


[error] 722-722: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 743-743: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 775-775: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 744-744: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

Gitleaks
src/translations/en.json

6536-6537: Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches.

(hashicorp-tf-password)

Additional comments not posted (26)
pyproject.toml (1)

7-7: Version update approved.

The version update from 20240626.2 to 20240627.0 is consistent with the project's versioning strategy.

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

44-44: Ensure proper loading of elements.

The addition of element.load() within _createCardElement ensures that the card element is fully loaded before use. This is a good practice to prevent runtime errors in dynamically loaded components.

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

95-95: CSS modification for grid layout approved.

The CSS changes ensure that the first non-hidden element in a grid layout is displayed correctly, which is crucial for visual consistency.

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

59-59: Review property updates and element loading logic.

The changes ensure that the preview property is updated for each card and that elements are loaded correctly. This improves the responsiveness of the UI components.

Also applies to: 72-72

src/components/ha-selector/ha-selector-device.ts (3)

14-14: Addition of ConfigEntry and getConfigEntries imports.

The added imports are necessary for handling configuration entries which enhances the functionality of device selectors.


31-31: Addition of _configEntries state property.

This change supports the new functionality to manage configuration entries within the device selector, aligning with the overall enhancements to selector components.


135-137: Usage of getDeviceIntegrationLookup with new parameters.

The integration of this._configEntries into the lookup function is correctly implemented and enhances the device filter capabilities based on the configuration entries.

src/components/ha-selector/ha-selector-area.ts (3)

14-14: Addition of ConfigEntry and getConfigEntries imports.

The added imports are necessary for handling configuration entries which enhances the functionality of area selectors.


41-41: Addition of _configEntries state property.

This change supports the new functionality to manage configuration entries within the area selector, aligning with the overall enhancements to selector components.


148-150: Usage of getDeviceIntegrationLookup with new parameters.

The integration of this._configEntries into the lookup function is correctly implemented and enhances the area filter capabilities based on the configuration entries.

src/components/ha-selector/ha-selector-floor.ts (3)

14-14: Addition of ConfigEntry and getConfigEntries imports.

The added imports are necessary for handling configuration entries which enhances the functionality of floor selectors.


41-41: Addition of _configEntries state property.

This change supports the new functionality to manage configuration entries within the floor selector, aligning with the overall enhancements to selector components.


148-150: Usage of getDeviceIntegrationLookup with new parameters.

The integration of this._configEntries into the lookup function is correctly implemented and enhances the floor filter capabilities based on the configuration entries.

src/data/device_registry.ts (1)

146-171: Updated getDeviceIntegrationLookup function to handle device integrations.

The function now effectively utilizes configuration entries to build a lookup for device integrations, enhancing the capability to filter devices based on their integrations.

Tools
Biome

[error] 158-158: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 159-159: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 160-160: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 149-149: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

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

1-1: Updated imports for HuiCard.

The updated imports are appropriate for the functionalities being used in the card, such as event handling and dynamic UI updates.


30-32: Updated property declarations for config and hass.

The updates to the property declarations ensure that they are not reflected as attributes, which is suitable for these types of properties that do not need to be reflected in the DOM.


34-39: Implementation of load method.

The load method is well-implemented to ensure that the card is correctly built from its configuration. It includes proper error handling which is crucial for debugging and user feedback.


87-91: Enhanced handling of card element with dynamic properties.

The method correctly handles the assignment of properties to the card element and ensures that changes are propagated. This is vital for maintaining the state consistency of the UI components.

Also applies to: 104-106

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

252-252: Ensure proper loading of card elements with load() method.

Adding the load() method within _createCardElement ensures that card elements are properly initialized before usage. This is a good practice for dynamic content loading.

src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts (1)

149-149: Ensure card components are fully initialized with load() method.

The addition of the load() method after creating a new card element ensures that it is fully initialized before being used. This is crucial for maintaining robustness in dynamic UI components.

src/panels/lovelace/sections/hui-section.ts (1)

67-67: Proper initialization of card elements with load() method.

Introducing the load() method in _createCardElement ensures that the card elements are properly initialized before they are used. This aligns with best practices for dynamic content management.

src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts (1)

204-209: Addition of "last-updated" option in state content selector is well-implemented.

The new option for displaying the last updated time of an entity has been added correctly. It follows the existing pattern and correctly uses localization for the label.

src/panels/lovelace/views/hui-view.ts (1)

85-85: Proper use of element.load() to ensure components are correctly loaded.

Adding element.load() in the card creation method is a good practice to ensure that all components are fully loaded before they are used, especially in dynamic UI environments like Lovelace.

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

241-248: Addition of "last-updated" state content option is correctly implemented.

The implementation for showing the last updated time on the tile card is correct and follows the established patterns used for other state contents like "last-changed".

src/data/selector.ts (1)

Line range hint 699-716: Refactoring of filterSelectorDevices to use Set for integration lookups enhances performance.

The use of a Set for checking device integrations is a performance optimization, as lookups in a set are generally faster than in an array, especially for larger data sets.

src/translations/en.json (1)

5991-5991: Translation key addition is consistent and correct.

The addition of "last-updated": "Last updated" is consistent with the existing structure and naming conventions of the translation keys. The JSON syntax is correct, and the key is properly nested within "state_content_options".


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

Outside diff range comments (10)
src/panels/lovelace/cards/hui-horizontal-stack-card.ts (1)

Line range hint 26-26: Address the use of super in a static context.

Using super in static methods can lead to confusion and potential errors. Consider using the class name instead.

- super.sharedStyles,
+ HuiStackCard.sharedStyles,
src/panels/lovelace/cards/hui-grid-card.ts (1)

Line range hint 73-73: Address the use of super in a static context.

Similar to the previous file, using super in static methods can lead to confusion. Consider using the class name instead.

- super.sharedStyles,
+ HuiStackCard.sharedStyles,
src/components/ha-selector/ha-selector-device.ts (1)

Line range hint 147-147: Avoid non-null assertion.

Using non-null assertions can lead to runtime errors if assumptions about non-nullability prove incorrect.

- this._element!.hass = this.hass;
+ if (this._element) this._element.hass = this.hass;
src/components/ha-selector/ha-selector-area.ts (1)

Line range hint 29-29: Address the use of any type for value property.

Using any type can lead to potential bugs and maintenance issues. Specifying a more precise type would improve type safety.

- @property() public value?: any;
+ @property() public value?: AreaRegistryEntry[] | AreaRegistryEntry;
src/components/ha-selector/ha-selector-floor.ts (1)

Line range hint 29-29: Address the use of any type for value property.

Using any type can lead to potential bugs and maintenance issues. Specifying a more precise type would improve type safety.

- @property() public value?: any;
+ @property() public value?: FloorRegistryEntry[] | FloorRegistryEntry;
src/panels/lovelace/cards/hui-entity-filter-card.ts (2)

Line range hint 147-147: Replace non-null assertions with optional chaining.

Several lines in this file use non-null assertions (!), which can lead to runtime errors if the objects are actually null. It's safer to replace these with optional chaining (?.).

- this.hass!.states[entityConf.entity]
+ this.hass?.states[entityConf.entity]

- this._element!.config
+ this._element?.config

- this._oldEntities![idx]
+ this._oldEntities?[idx]

- this._layoutElement!.hass
+ this._layoutElement?.hass

Also applies to: 150-150, 155-155, 158-158, 177-177, 185-185, 190-190


Line range hint 208-208: Refactor function to reduce complexity.

The update function has a complexity score of 22, which exceeds the maximum allowed of 15. Consider refactoring this function to simplify its logic, possibly by breaking it down into smaller, more manageable functions.

src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts (2)

Line range hint 185-185: Avoid using the delete operator for better performance.

Using the delete operator can lead to performance issues due to deoptimizations in JavaScript engines. Consider setting properties to undefined instead.

- delete newConfig.layout_options!.grid_columns;
+ newConfig.layout_options!.grid_columns = undefined;

- delete newConfig.layout_options!.grid_rows;
+ newConfig.layout_options!.grid_rows = undefined;

- delete newConfig.layout_options;
+ newConfig.layout_options = undefined;

Also applies to: 204-204, 207-207, 210-210


Line range hint 203-203: Replace non-null assertions with optional chaining for safety.

Using non-null assertions can lead to runtime errors if the object is null. It's safer to use optional chaining.

- this._yamlEditor!.setValue({});
+ this._yamlEditor?.setValue({});

- this._cardElement!.config
+ this._cardElement?.config

Also applies to: 206-206, 209-209

src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts (1)

Line range hint 685-686: Avoid non-null assertions and enhance error handling in _validateDskAndEnterPin.

Using non-null assertions can lead to runtime errors if assumptions about non-nullability fail. Consider using optional chaining or conditional checks instead.

- await zwaveValidateDskAndEnterPin(
-   this.hass,
-   this._entryId!,
-   this._pinInput!.value as string
- );
+ if (this._pinInput && this._entryId) {
+   await zwaveValidateDskAndEnterPin(
+     this.hass,
+     this._entryId,
+     this._pinInput.value as string
+   );
+ } else {
+   // Handle error or invalid state
+ }

Comment on lines +599 to +601
private _qrCodeError(ev: CustomEvent): void {
this._error = ev.detail.message;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify a more detailed type for event parameter in _qrCodeError.

Using any for the event type reduces type safety. Consider specifying a more detailed type, possibly a custom event type with a defined structure for detail.message.

- private _qrCodeError(ev: CustomEvent): void {
+ private _qrCodeError(ev: CustomEvent<{ message: string }>): void {
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
private _qrCodeError(ev: CustomEvent): void {
this._error = ev.detail.message;
}
private _qrCodeError(ev: CustomEvent<{ message: string }>): void {
this._error = ev.detail.message;
}

private _qrCodeError(ev: CustomEvent): void {
this._error = ev.detail.message;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to reduce complexity and improve maintainability in _handleQrCodeScanned.

This method's complexity is too high, which can lead to maintenance challenges and bugs. Consider breaking it down into smaller methods, each handling a part of the QR code processing logic.

- private async _handleQrCodeScanned(qrCodeString: string): Promise<void> {
+ private async _handleQrCodeScanned(qrCodeString: string): Promise<void> {
+   // Example refactoring: separate the validation and processing steps into their own methods
+   if (!this._validateQrCode(qrCodeString)) {
+     return;
+   }
+   await this._processQrCode(qrCodeString);
+ }
+
+ private _validateQrCode(qrCodeString: string): boolean {
+   // Add validation logic here
+   return true;
+ }
+
+ private async _processQrCode(qrCodeString: string): Promise<void> {
+   // Add processing logic here
+ }
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
private async _handleQrCodeScanned(qrCodeString: string): Promise<void> {
// Example refactoring: separate the validation and processing steps into their own methods
if (!this._validateQrCode(qrCodeString)) {
return;
}
await this._processQrCode(qrCodeString);
}
private _validateQrCode(qrCodeString: string): boolean {
// Add validation logic here
return true;
}
private async _processQrCode(qrCodeString: string): Promise<void> {
// Add processing logic here
}

@@ -30,7 +30,7 @@ export class HuiHorizontalStackCard extends HuiStackCard {
height: 100%;
gap: var(--horizontal-stack-card-gap, var(--stack-card-gap, 8px));
}
#root > * {
#root > hui-card > * {
Copy link
Contributor

Choose a reason for hiding this comment

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

CSS modification appears correct but consider simplifying the selector.

The CSS change aims to ensure flex properties are applied correctly. However, the selector might be more complex than necessary.

- #root > hui-card > * {
+ #root > * {
    flex: 1 1 0;
    min-width: 0;
  }
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
#root > hui-card > * {
#root > * {
flex: 1 1 0;
min-width: 0;
}

@@ -27,6 +28,8 @@ export class HaDeviceSelector extends LitElement {

@state() private _entitySources?: EntitySources;

@state() private _configEntries?: ConfigEntry[];

@property() public value?: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Address the use of any type for value property.

Using any type can lead to potential bugs and maintenance issues. Specifying a more precise type would improve type safety.

- @property() public value?: any;
+ @property() public value?: DeviceRegistryEntry[] | DeviceRegistryEntry;
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
@property() public value?: any;
@property() public value?: DeviceRegistryEntry[] | DeviceRegistryEntry;
Tools
Biome

[error] 33-33: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)

Comment on lines +81 to +86
if (!this._configEntries && this._hasIntegration(this.selector)) {
this._configEntries = [];
getConfigEntries(this.hass).then((entries) => {
this._configEntries = entries;
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper handling of asynchronous operations.

The method to fetch configuration entries is correctly implemented using promises. However, consider adding error handling for the promise to manage potential failures in fetching the configuration entries.

  getConfigEntries(this.hass).then((entries) => {
    this._configEntries = entries;
+ }).catch((error) => {
+   console.error("Failed to fetch configuration entries:", error);
+   this._configEntries = [];
+ });
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
if (!this._configEntries && this._hasIntegration(this.selector)) {
this._configEntries = [];
getConfigEntries(this.hass).then((entries) => {
this._configEntries = entries;
});
}
if (!this._configEntries && this._hasIntegration(this.selector)) {
this._configEntries = [];
getConfigEntries(this.hass).then((entries) => {
this._configEntries = entries;
}).catch((error) => {
console.error("Failed to fetch configuration entries:", error);
this._configEntries = [];
});
}

Comment on lines +158 to +160
deviceIntegrations[entity.device_id!] =
deviceIntegrations[entity.device_id!] || new Set<string>();
deviceIntegrations[entity.device_id!].add(source.domain);
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid non-null assertion.

Using non-null assertions can lead to runtime errors if assumptions about non-nullability prove incorrect.

- deviceIntegrations[entity.device_id!] = deviceIntegrations[entity.device_id!] || new Set<string>();
+ if (entity.device_id) {
+   deviceIntegrations[entity.device_id] = deviceIntegrations[entity.device_id] || new Set<string>();
+ }

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 158-158: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 159-159: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 160-160: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

entities: EntityRegistryDisplayEntry[] | EntityRegistryEntry[],
devices?: DeviceRegistryEntry[],
configEntries?: ConfigEntry[]
): Record<string, Set<string>> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reduce function complexity.

The function complexity is high, which can make maintenance difficult. Consider refactoring to simplify the logic, possibly by breaking down into smaller helper functions.

- export const getDeviceIntegrationLookup = (entitySources, entities, devices, configEntries) => {
+ // Refactor into smaller functions
+ function handleEntityIntegrations(entitySources, entities, deviceIntegrations) {
+   for (const entity of entities) {
+     const source = entitySources[entity.entity_id];
+     if (!source?.domain || entity.device_id === null) {
+       continue;
+     }
+     if (!deviceIntegrations[entity.device_id]) {
+       deviceIntegrations[entity.device_id] = new Set<string>();
+     }
+     deviceIntegrations[entity.device_id].add(source.domain);
+   }
+ }
+ function handleDeviceIntegrations(devices, configEntries, deviceIntegrations) {
+   if (devices && configEntries) {
+     for (const device of devices) {
+       for (const config_entry_id of device.config_entries) {
+         const entry = configEntries.find((e) => e.entry_id === config_entry_id);
+         if (entry?.domain) {
+           if (!deviceIntegrations[device.id]) {
+             deviceIntegrations[device.id] = new Set<string>();
+           }
+           deviceIntegrations[device.id].add(entry.domain);
+         }
+       }
+     }
+   }
+ }
+ export const getDeviceIntegrationLookup = (entitySources, entities, devices, configEntries) => {
+   const deviceIntegrations: Record<string, Set<string>> = {};
+   handleEntityIntegrations(entitySources, entities, deviceIntegrations);
+   handleDeviceIntegrations(devices, configEntries, deviceIntegrations);
+   return deviceIntegrations;
+ };
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
): Record<string, Set<string>> => {
// Refactor into smaller functions
function handleEntityIntegrations(entitySources, entities, deviceIntegrations) {
for (const entity of entities) {
const source = entitySources[entity.entity_id];
if (!source?.domain || entity.device_id === null) {
continue;
}
if (!deviceIntegrations[entity.device_id]) {
deviceIntegrations[entity.device_id] = new Set<string>();
}
deviceIntegrations[entity.device_id].add(source.domain);
}
}
function handleDeviceIntegrations(devices, configEntries, deviceIntegrations) {
if (devices && configEntries) {
for (const device of devices) {
for (const config_entry_id of device.config_entries) {
const entry = configEntries.find((e) => e.entry_id === config_entry_id);
if (entry?.domain) {
if (!deviceIntegrations[device.id]) {
deviceIntegrations[device.id] = new Set<string>();
}
deviceIntegrations[device.id].add(entry.domain);
}
}
}
}
}
export const getDeviceIntegrationLookup = (entitySources, entities, devices, configEntries) => {
const deviceIntegrations: Record<string, Set<string>> = {};
handleEntityIntegrations(entitySources, entities, deviceIntegrations);
handleDeviceIntegrations(devices, configEntries, deviceIntegrations);
return deviceIntegrations;
};
Tools
Biome

[error] 149-149: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

element.hass = this.hass;
element.preview = this.preview;
if (this.hass) {
this._element!.hass = this.hass;
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid non-null assertion.

Using non-null assertions can lead to runtime errors if assumptions about non-nullability prove incorrect.

- this._element!.hass = this.hass;
+ if (this._element) this._element.hass = this.hass;
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
this._element!.hass = this.hass;
if (this._element) this._element.hass = this.hass;
Tools
Biome

[error] 105-105: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

// For backwards compatibility
(element as any).editMode = this.preview;
(this._element as any).editMode = this.preview;
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using any type for editMode.

Using any type can lead to potential bugs and maintenance issues. It's better to define a more specific type or at least add type checks before assignment.

- (this._element as any).editMode = this.preview;
+ if (typeof this._element !== 'undefined') {
+   (this._element as LovelaceCard).editMode = this.preview;
+ }
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
(this._element as any).editMode = this.preview;
if (typeof this._element !== 'undefined') {
(this._element as LovelaceCard).editMode = this.preview;
}
Tools
Biome

[error] 94-94: Unexpected any. Specify a different type.

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

(lint/suspicious/noExplicitAny)

Comment on lines 134 to +149
protected update(changedProps: PropertyValues<typeof this>) {
super.update(changedProps);

if (this._element) {
if (changedProps.has("config") && this.hasUpdated) {
const oldConfig = changedProps.get("config");
if (this.config !== oldConfig && this.config) {
const typeChanged = this.config?.type !== oldConfig?.type;
if (typeChanged) {
this._loadElement(this.config);
} else {
this._element?.setConfig(this.config);
fireEvent(this, "card-updated");
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Reduce function complexity in update method.

The update method is complex and handles multiple conditions which can be simplified or broken down into smaller methods to improve readability and maintainability.

- protected update(changedProps: PropertyValues<typeof this>) {
+ // Simplify by breaking down into smaller methods
+ protected update(changedProps: PropertyValues<typeof this>) {
+   super.update(changedProps);
+   this._updateConfig(changedProps);
+   this._updateHass(changedProps);
+   this._updatePreview(changedProps);
+   this._updatePanel(changedProps);
+ }
+
+ private _updateConfig(changedProps: PropertyValues<typeof this>) {
+   if (changedProps.has("config") && this.hasUpdated) {
+     const oldConfig = changedProps.get("config");
+     if (this.config !== oldConfig && this.config) {
+       const typeChanged = this.config?.type !== oldConfig?.type;
+       if (typeChanged) {
+         this._loadElement(this.config);
+       } else {
+         this._element?.setConfig(this.config);
+         fireEvent(this, "card-updated");
+       }
+     }
+   }
+ }
+
+ private _updateHass(changedProps: PropertyValues<typeof this>) {
+   if (changedProps.has("hass")) {
+     try {
+       if (this.hass) {
+         this._element.hass = this.hass;
+       }
+     } catch (e: any) {
+       this._loadElement(createErrorCardConfig(e.message, null));
+     }
+   }
+ }
+
+ private _updatePreview(changedProps: PropertyValues<typeof this>) {
+   if (changedProps.has("preview")) {
+     try {
+       this._element.preview = this.preview;
+       // For backwards compatibility
+       (this._element as any).editMode = this.preview;
+     } catch (e: any) {
+       this._loadElement(createErrorCardConfig(e.message, null));
+     }
+   }
+ }
+
+ private _updatePanel(changedProps: PropertyValues<typeof this>) {
+   if (changedProps.has("isPanel")) {
+     this._element.isPanel = this.isPanel;
+   }
+ }
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
protected update(changedProps: PropertyValues<typeof this>) {
super.update(changedProps);
if (this._element) {
if (changedProps.has("config") && this.hasUpdated) {
const oldConfig = changedProps.get("config");
if (this.config !== oldConfig && this.config) {
const typeChanged = this.config?.type !== oldConfig?.type;
if (typeChanged) {
this._loadElement(this.config);
} else {
this._element?.setConfig(this.config);
fireEvent(this, "card-updated");
}
}
}
protected update(changedProps: PropertyValues<typeof this>) {
super.update(changedProps);
this._updateConfig(changedProps);
this._updateHass(changedProps);
this._updatePreview(changedProps);
this._updatePanel(changedProps);
}
private _updateConfig(changedProps: PropertyValues<typeof this>) {
if (changedProps.has("config") && this.hasUpdated) {
const oldConfig = changedProps.get("config");
if (this.config !== oldConfig && this.config) {
const typeChanged = this.config?.type !== oldConfig?.type;
if (typeChanged) {
this._loadElement(this.config);
} else {
this._element?.setConfig(this.config);
fireEvent(this, "card-updated");
}
}
}
}
private _updateHass(changedProps: PropertyValues<typeof this>) {
if (changedProps.has("hass")) {
try {
if (this.hass) {
this._element.hass = this.hass;
}
} catch (e: any) {
this._loadElement(createErrorCardConfig(e.message, null));
}
}
}
private _updatePreview(changedProps: PropertyValues<typeof this>) {
if (changedProps.has("preview")) {
try {
this._element.preview = this.preview;
// For backwards compatibility
(this._element as any).editMode = this.preview;
} catch (e: any) {
this._loadElement(createErrorCardConfig(e.message, null));
}
}
}
private _updatePanel(changedProps: PropertyValues<typeof this>) {
if (changedProps.has("isPanel")) {
this._element.isPanel = this.isPanel;
}
}
Tools
Biome

[error] 134-134: Excessive complexity detected.

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

(lint/complexity/noExcessiveCognitiveComplexity)

@bramkragten bramkragten merged commit d72e8c3 into master Jun 27, 2024
34 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.

4 participants