Conversation
PR #90 replaced the deprecated `async_get_device(identifiers=...)` lookup in cleanup_old_device() with an iteration over `device_reg.devices.values()`. That swapped one deprecation for another: HA 2026.9 wraps `DeviceRegistry.devices` in a compatibility view that reports any mapping-style use and stops working in HA Core 2027.9.0, so the integration logs a warning on every startup. Walk this integration's own config entries and use the supported `dr.async_entries_for_config_entry()` helper instead, which reads the registry's internal container directly and is not deprecated. Iterating every config entry of the domain (rather than just the one being set up) keeps the previous behaviour of finding the legacy device regardless of which entry owns it. Also adds a regression test for cleanup_old_device(), which had no coverage despite being rewritten twice, and syncs the manifest version with tag v1.8.3.
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.
Fixes #91.
Problem
PR #90 fixed the deprecated
async_get_device(identifiers=...)lookup incleanup_old_device()by replacing it with an iteration overdevice_reg.devices.values(). That swapped one deprecation for another.In HA 2026.9,
DeviceRegistry.devicesreturns a_DeprecatedDeviceRegistryItemsView. Iterating it is the supported use, but any mapping-style access —.values(),.get(), subscription — callsreport_usage()and breaks in HA Core 2027.9.0. Hence the startup warning users see on 2026.9.*:Fix
Walk this integration's own config entries and use
dr.async_entries_for_config_entry(). Verified against the 2026.9.1 source that this helper readsregistry._devicesdirectly, bypassing the deprecated view, so it emits no warning:Two notes on the implementation:
cleanup_old_device()runs once globally (guarded by theprocessed_cleanupflag), and the legacy device may belong to an entry that isn't the first to set up.removedset guards against callingasync_remove_device()twice on a device shared by two entries, which would raiseKeyError. Defensive — the malformed device predates multi-hub support, so in practice it only ever belonged to one entry.Testing
Adds a regression test for
cleanup_old_device(), which had no coverage despite being rewritten twice. 272 tests pass.Worth flagging: the test does not catch this specific deprecation. The pinned
pytest-homeassistant-custom-componentresolves to HA 2026.3.1, which predates the compatibility view entirely, so the test passes against the old code too. It pins the behavioural contract — bare(DOMAIN,)is removed,(DOMAIN, entry_id)is kept — not the API choice.Also syncs
manifest.jsonto1.8.3, matching the existing tag. The release workflow patches this from the tag at publish time, so shipped artifacts were already correct; this is repo bookkeeping only.