Add Home summary models and entity-filter engine#5018
Open
bgoncal wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds shared “Home summary” domain models plus an entity-filter evaluator to compute dashboard-style summary states (lights/climate/security/media/maintenance/energy/people) from entity registry + state data, and introduces an Energy preferences request/model to support energy applicability checks.
Changes:
- Added
HomeSummary+HomeSummaryStatefor defining summary metadata (filters/icons/colors) and computing per-summary derived state. - Added
EntityFilter+EntityFilterEvaluatorto evaluate frontend-like entity-filter rules against registries/states. - Extended area registry decoding with
temperature_entity_id/humidity_entity_id, and addedenergy/get_prefsrequest +EnergyPreferencesmodel.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/Shared/Models/HomeSummaryState.swift | Defines HomeSummaryState and computes summary state values from an EntityFilterEvaluator and area registry data. |
| Sources/Shared/Models/HomeSummary.swift | Defines HomeSummary, summary filters, icons/colors/titles, and applicability logic. |
| Sources/Shared/Models/HAAreasRegistryResponse.swift | Adds decoding/storage for temperatureEntityId and humidityEntityId on areas. |
| Sources/Shared/Models/EntityFilterEvaluator.swift | Implements entity-filter matching and low-battery detection using states + registries. |
| Sources/Shared/Models/EnergyPreferences.swift | Adds EnergyPreferences + EnergySource to model energy preferences and detect grid availability. |
| Sources/Shared/HATypedRequest+App.swift | Adds a typed WebSocket request for energy/get_prefs. |
| HomeAssistant.xcodeproj/project.pbxproj | Registers new Swift source files in the Xcode project/targets. |
Comment on lines
+80
to
+84
| public var title: String { | ||
| switch self { | ||
| case .light: return "Lights" | ||
| case .climate: return "Climate" | ||
| case .security: return "Security" |
Comment on lines
+27
to
+31
| func state(using evaluator: EntityFilterEvaluator, areas: [HAAreasRegistryResponse]) -> HomeSummaryState { | ||
| switch self { | ||
| case .light: | ||
| let matched = evaluator.findEntities(matching: filters) | ||
| return .lights(onCount: matched.filter { evaluator.states[$0]?.state == "on" }.count) |
Contributor
|
Found 3 unused localization strings in the codebase. Click to see detailsTo remove them, run the |
Port the default-dashboard summary definitions (light, climate, security, media players, maintenance, energy, persons) from the frontend as reusable Swift models: EntityFilter plus a findEntities engine, the HomeSummary enum with per-domain filters/icons/colors, per-summary state calculation, and an energy/get_prefs request. Summaries are derived client-side from entity states and registries, matching the frontend.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the model and request layer for the default-dashboard summaries (light, climate, security, media players, maintenance, energy, people) so they can be reused natively. These are derived client-side from entity states and registries, matching the frontend's
homestrategy.EntityFilterplusEntityFilterEvaluator— a Swift port of the frontend entity-filter engine (generateEntityFilter/findEntities).HomeSummaryenum — each summary's entity filters, icon, colour, and applicability.HomeSummaryState— computes each summary's value (lights on, temperature range, lock/alarm status, media playing, low/unavailable batteries, people home).energy/get_prefsrequest +EnergyPreferencesmodel, andtemperature_entity_id/humidity_entity_idadded to the area registry model.No UI yet — this is groundwork for a native summaries view. Energy's live value is left for a follow-up (needs the energy statistics collection).
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes