forked from tbnobody/OpenDTU
-
-
Notifications
You must be signed in to change notification settings - Fork 102
BREAKING CHANGE: Fix: use uniqueId for battery HA auto-discovery #2442
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
Open
AndreasBoehm
wants to merge
1
commit into
development
Choose a base branch
from
andreasboehm/feature/ha-auto-discovery-multiple-batteries
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In Home Assistant MQTT discovery, what happens when an existing entity'suniq_idchanges after a firmware update? Are old entities/devices automatically migrated or left as stale registry entries?💡 Result:
Web search failed: Server error: no LLM provider could handle the message
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 517
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 4165
🌐 Web query:
Home Assistant MQTT discovery uniq_id change migration behavior💡 Result:
unique_idis the identity key. Home Assistant uses an entity’sunique_idto tie MQTT-discovered entities to the Entity Registry (so you can later rename theentity_idand keep that rename). (home-assistant.io)unique_id, Home Assistant will treat it as a different entity. Practically, that means you’ll get a new entity in HA, and the old one will remain as an orphan (often unavailable) until you remove it; HA will not automatically “migrate” the old entity’sentity_id, area, history settings, automations, etc., to the newunique_id. (This follows from how discovery creates/updates entities keyed byunique_id, and that removals are explicit.) (home-assistant.io)<object_id>is not the same as changingunique_id. The<object_id>segment in the discovery topic does not control the resultingentity_id; best practice is to set that<object_id>to theunique_id(so you don’t accidentally create parallel entities when you change topics). (home-assistant.io)unique_id) so the new entity appears..../configtopic to delete the old discovered entity and clear the retained config. (home-assistant.io){"migrate_discovery": true}is a special mechanism for migrating single-component discovery topics to device discovery while retaining settings; it’s not a general “unique_id change migration.” (home-assistant.io)Citations:
🌐 Web query:
Home Assistant MQTT entity unique ID change upgrade retained topics💡 Result:
Web search failed: Server error: no LLM provider could handle the message
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 182
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 271
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 51
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 125
🏁 Script executed:
# Get the full commit details to see what changed git show dcb983d8 --no-patchRepository: hoylabs/OpenDTU-OnBattery
Length of output: 413
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 2954
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 151
🏁 Script executed:
Repository: hoylabs/OpenDTU-OnBattery
Length of output: 495
Add migration documentation for Home Assistant discovery identity changes.
The battery discovery
uniq_id(lines 64, 118) and deviceids(line 146) now usecreateBatteryId()to fix multi-DTU collisions. However, on upgrades, Home Assistant will treat these as new entities and leave old ones orphaned—automations and dashboards bound to the old IDs will break, and HA does not auto-migrate them.To mitigate this for users, add release notes documenting:
homeassistant/sensor/0001/<sensorId>/config) to explicitly remove orphaned entities from the HA registryAlternatively, consider a one-time cleanup routine on first startup after the ID changes to publish empty payloads for any legacy discovery topics.
Also applies to: 54–55, 108–110
🤖 Prompt for AI Agents