Skip to content

Conversation

@bgoncal
Copy link
Member

@bgoncal bgoncal commented Jan 28, 2026

Eliminates the hiddenBy and disabledBy properties from HAAppEntity, related database tables, and query logic. Entity hidden/disabled state is now determined dynamically from AppEntityRegistry, simplifying entity state management and reducing data duplication.

Summary

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

Eliminates the hiddenBy and disabledBy properties from HAAppEntity, related database tables, and query logic. Entity hidden/disabled state is now determined dynamically from AppEntityRegistry, simplifying entity state management and reducing data duplication.
@bgoncal bgoncal self-assigned this Jan 28, 2026
Copilot AI review requested due to automatic review settings January 28, 2026 10:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes the hiddenBy and disabledBy fields from HAAppEntity and its backing database table, and shifts hidden/disabled resolution to AppEntityRegistry to avoid duplicated state.

Changes:

  • Deleted hiddenBy / disabledBy from HAAppEntity and removed the corresponding DB columns and enum cases.
  • Updated hidden/disabled evaluation to be derived from AppEntityRegistry and adjusted HAAppEntity.config(include:) filtering accordingly.
  • Removed the now-unneeded entity DB synchronization logic in AreasService and updated home entity observation to no longer filter on removed columns.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Sources/Shared/HAAppEntity.swift Removes persisted hidden/disabled fields; derives hidden/disabled dynamically and updates config filtering logic.
Sources/Shared/Database/Tables/HAppEntityTable.swift Drops hiddenBy/disabledBy columns from the HAAppEntity table schema.
Sources/Shared/Database/DatabaseTables.swift Removes hiddenBy/disabledBy enum cases for the AppEntity table.
Sources/Shared/AreasService.swift Removes logic that previously synced hidden/disabled state into HAAppEntity rows.
Sources/App/WebView/ExperimentalSpace/Home/HomeViewModel.swift Removes DB filters on removed columns when observing app entities.

Copy link
Contributor

Copilot AI commented Jan 28, 2026

@bgoncal I've opened a new pull request, #4266, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits January 28, 2026 11:55
## Summary
Addresses performance feedback on #4265. The `config(include:)` method
was using `first(where:)` to search the entire registry array for each
entity, resulting in O(n²) complexity. Replaced with dictionary-based
lookups for O(1) access.

**Changes:**
- Build registry dictionary keyed by `(serverId, entityId)` tuples
- Replace `first(where:)` array search with direct dictionary access
- Use `uniquingKeysWith` to handle potential duplicate keys gracefully

**Before:**
```swift
guard let registry = appEntityRegistry
    .first(where: { $0.entityId == entity.entityId && $0.serverId == entity.serverId }) else {
    return true
}
```

**After:**
```swift
let registryDict = Dictionary(
    appEntityRegistry.compactMap { registry -> ((String, String), AppEntityRegistry)? in
        guard let entityId = registry.entityId else { return nil }
        return ((registry.serverId, entityId), registry)
    },
    uniquingKeysWith: { first, _ in first }
)

guard let registry = registryDict[(entity.serverId, entity.entityId)] else {
    return true
}
```

## Screenshots
N/A - Backend performance optimization

## Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#

## Any other notes
This is a stacked PR merging into #4265.

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@f57b549). Learn more about missing BASE report.

Files with missing lines Patch % Lines
Sources/Shared/HAAppEntity.swift 0.00% 34 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4265   +/-   ##
=======================================
  Coverage        ?   43.08%           
=======================================
  Files           ?      261           
  Lines           ?    15106           
  Branches        ?        0           
=======================================
  Hits            ?     6508           
  Misses          ?     8598           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal bgoncal merged commit 2211129 into main Jan 28, 2026
14 of 15 checks passed
@bgoncal bgoncal deleted the fix-crash-3 branch January 28, 2026 11: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.

2 participants