fix: resolve dashboard entity_ids from the registry (HA 2026.6 area naming)#125
Conversation
…aming) HA 2026.6 folds a device's area into generated entity_ids (`sensor.loft_givenergy_inverter_…`), and users may rename entities — so the dashboard generator's predicted `givenergy_<kind>_<serial>_<slug>` ids no longer match what HA registers, leaving every tile "Entity not available". generate_dashboard now takes a resolve_entity_id callback and rewrites each reference to the actual registry id in a final pass; the generate_dashboard service builds the resolver from the entity+device registries (canonical id -> real id, keyed on the stable device name + original entity name). Bump DASHBOARD_VERSION to 11 so existing installs are prompted to regenerate. Also make _migrate_unique_ids idempotent: the p_grid_out -> grid_power entity_id rename now fires whenever the old name-slug is still present, including installs where an earlier release already migrated the unique_id. That rename was gated on the now-new unique_id and silently no-op'd for anyone who had installed a prior rc (the rc1->rc2 breakage). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR introduces entity ID resolution for dashboard generation to handle Home Assistant 2026.6+ area-prefixed entity IDs and user renames. The integration now builds a canonical-to-actual entity ID mapping and applies it when generating Lovelace YAML, while simultaneously reworking entity migrations to be idempotent and collision-safe. ChangesEntity ID Resolution System
Sequence DiagramsequenceDiagram
participant User
participant Service as SERVICE_GENERATE_DASHBOARD
participant Resolver as _build_entity_id_resolver
participant Registry as Entity Registry
participant Dashboard as generate_dashboard
participant YAML as Lovelace YAML
User->>Service: Request dashboard generation
Service->>Registry: Get config-entry entity registry
Service->>Resolver: Build resolver mapping (canonical → actual)
Resolver->>Registry: Read device names, entity IDs, unique IDs
Resolver-->>Service: Return resolver function
Service->>Dashboard: Call with resolve_entity_id=resolver
Dashboard->>YAML: Generate YAML with canonical IDs
Dashboard->>Dashboard: Rewrite canonical IDs via regex
Dashboard->>YAML: Apply resolver mapping to references
Dashboard-->>Service: Return YAML with actual registered IDs
Service-->>User: Deliver dashboard YAML
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the dashboard generation to support Home Assistant 2026.6 area-prefixed entity IDs and user renames by resolving canonical entity IDs to actual registry IDs. It also refactors unique ID and entity ID migrations to be independent and idempotent. A review comment suggests using device.original_name instead of device.name in the entity ID resolver to avoid breaking dashboard cards when a user renames their device.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Python | Jun 5, 2026 10:18a.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
What
The
generate_dashboardservice predicted entity IDs as{domain}.givenergy_<kind>_<serial>_<slug>. That stopped matching reality, so generated dashboards point at non-existent entities and every tile shows "Entity not available".Why
Home Assistant 2026.6 changed entity-id generation to fold in the device's area — upstream home-assistant/core#170560 "Prefix area to entity ID" (merge commit
f823ef6, 2026-05-19). Comparing core_async_get_full_entity_name:f"{device_name} {name}"" ".join(p for p in (area_name, device_name, entity_name) if p), and_async_generate_entity_idgained anarea_idarg defaulting todevice.area_id.So a device in area "Loft" gets
sensor.loft_givenergy_inverter_<serial>_…. entity IDs are sticky once generated, so only entities created/recreated under 2026.6 (or after Recreate entity IDs) pick up the prefix — which is why a single plant can show mixed prefixes. The generator can't predict any of this (area varies per device, and users can rename entities), so it has to read the real IDs from the registry.How
generate_dashboard(…, resolve_entity_id=…)rewrites every entity reference to its actual registry ID in a final pass; output is unchanged when no resolver is passed (keeps the standalone CLI / tests working).slugify(device.name)+slugify(original_name)) to its realentity_id. Robust to area prefixes, per-device area differences, device renames, and user entity renames.DASHBOARD_VERSION→ 11 so installs with an already-generated (broken) dashboard get the existing "outdated → regenerate" Repairs prompt._migrate_unique_idsmade idempotent: thep_grid_out → grid_powerentity_id rename now fires whenever the old name-slug is still present — including installs where an earlier release already moved the unique_id (it was gated on the now-new unique_id and silently no-op'd; this was the rc1→rc2 regression). The dashboard resolves correctly regardless, but it keeps entity IDs tidy.Tests
New coverage for the resolver rewrite (incl. the greedy-sibling case), a registry-rename regression that simulates the area prefix, and the rc1→rc2 migration path. Full suite green.
Caveats
generate_dashboardend-to-end on live EMS/inverter hardware with this build installed — that's the real ground-truth and worth a check once it's on a test instance.v1.1.3rc1/v1.1.3rc2pre-releases. A fresh pre-release should follow once this merges.🤖 Generated with Claude Code