fix: also rename entity_id when migrating p_grid_out → grid_power#124
Conversation
_migrate_unique_ids updated the unique_id but not the entity_id. On installs that registered the sensor under its original 'Grid Export Power' name, the entity_id remained …_grid_export_power while the dashboard generator constructed …_grid_power references — causing widespread 'Entity not available' errors on v1.1.3rc1+. Widen _RENAMED_UNIQUE_ID_SUFFIXES values to (new_suffix, old_entity_slug) tuples. When old_entity_slug is set and the entity_id ends with that slug, pass new_entity_id to async_update_entity alongside new_unique_id. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR enhances the GivEnergy integration's entity migration system to coordinately rename both ChangesEntity Migration Enhancements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| Python | Jun 4, 2026 7:57a.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.
There was a problem hiding this comment.
Code Review
This pull request modifies the entity migration logic to rename the entity_id in addition to the unique_id when migrating specific sensors, such as renaming grid_export_power to grid_power. However, the reviewer points out that renaming the entity_id during migration can break user automations, scripts, and templates. They recommend preserving the existing entity_id and only updating the unique_id.
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.
| new_entity_id = ( | ||
| ent.entity_id[: -len(old_slug)] + new | ||
| if old_slug and ent.entity_id.endswith(f"_{old_slug}") | ||
| else None | ||
| ) | ||
| _LOGGER.info( | ||
| "Migrating unique_id %s -> %s%s", | ||
| ent.unique_id, | ||
| new_uid, | ||
| f" (entity_id: {ent.entity_id} -> {new_entity_id})" if new_entity_id else "", | ||
| ) | ||
| registry.async_update_entity( | ||
| ent.entity_id, | ||
| new_unique_id=new_uid, | ||
| **({"new_entity_id": new_entity_id} if new_entity_id else {}), | ||
| ) |
There was a problem hiding this comment.
When performing entity migrations in Home Assistant, we must preserve the existing entity_id and only update the unique_id. Renaming the entity_id can break user automations, scripts, and templates that reference the old entity ID. Please update the migration logic to only modify the unique_id and leave the entity_id unchanged.
_LOGGER.info(
"Migrating unique_id %s -> %s",
ent.unique_id,
new_uid,
)
registry.async_update_entity(
ent.entity_id,
new_unique_id=new_uid,
)References
- When performing entity migrations in Home Assistant, preserve the existing
entity_idand only update theunique_idto prevent breaking user automations and templates that reference the old entity ID.
Problem
_migrate_unique_idsupdated theunique_id(e.g.{serial}_p_grid_out→{serial}_grid_power) but not theentity_id. On installs where the sensor was first registered under its original "Grid Export Power" name, the entity_id remainedsensor.givenergy_inverter_{serial}_grid_export_power. The dashboard generator constructssensor.givenergy_inverter_{serial}_grid_power— that entity_id doesn't exist, producing widespread "Entity not available" errors on v1.1.3rc1+. Grid power appears in the power-flow overview, 24-hour chart, and today chart, so most of the dashboard fails.Fix
Widen
_RENAMED_UNIQUE_ID_SUFFIXESvalues from plain strings to(new_suffix, old_entity_slug | None)tuples. Whenold_entity_slugis set and the existingentity_idends with that slug, passnew_entity_idtoasync_update_entityalongsidenew_unique_id. The other three renames (e_load_day,e_inverter_out_day,e_inverter_out_total) carryNonefor the slug — no behaviour change for them.A regression test verifies that after setup an entity registered under the old unique_id and the old
_grid_export_powerentity_id is found at_grid_powerwith the updated unique_id.Test plan
uv run pytest— 242 passedsensor.givenergy_inverter_{serial}_grid_powerappears carrying old history; dashboard power-flow, 24h chart and today chart all renderSummary by CodeRabbit