fix: replace deprecated device_registry.async_get_device (removed in HA 2027.8.0) - #90
Merged
Conversation
cleanup_old_device() used device_registry.async_get_device(identifiers=...), which HA deprecated because identifiers/connections are no longer unique across config entries and which stops working in HA Core 2027.8.0. Replace it with an iteration over the device registry that matches the same malformed legacy (DOMAIN,) identifier the cleanup was intended to remove. async_get_device_by_identifier is unsuitable here because it requires a well-formed (domain, id) pair and cannot express the malformed single-element identifier. All 271 existing tests pass.
Owner
|
Thanks @mwstowe ! All looks good. I'll merge and introduce a new release soon with this in place. |
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
cleanup_old_device()callsdevice_registry.async_get_device(identifiers={(DOMAIN,)}). Home Assistant deprecatedasync_get_device()for identifier/connection lookups because device identifiers and connections are no longer unique across config entries. HA logs a warning on startup and this call stops working in HA Core 2027.8.0.This PR replaces the deprecated lookup with an iteration over the device registry, matching the same malformed legacy identifier the original code was cleaning up.
Why iterate instead of
async_get_device_by_identifier?The HA warning suggests
async_get_device_by_identifier, but that helper takes a well-formed(domain, id)pair. The device this cleanup targets was registered with a malformed single-element identifier(DOMAIN,), which cannot be expressed viaasync_get_device_by_identifier. Iterating the registry and matching the improper 1-tuple identifier preserves the original intent while removing the deprecated API usage.(Note: the original
identifiers={(DOMAIN,)}lookup was effectively a no-op, since a set containing a bare 1-tuple never matches a normally-registered device. The new code matches devices that actually carry that malformed identifier.)Testing
python -m pytest-> 271 passed (1 pre-existing unrelated tz warning).python -m py_compilepasses.Deprecation reference