Skip to content

fix: replace deprecated device_registry.async_get_device (removed in HA 2027.8.0) - #90

Merged
jmdevita merged 1 commit into
jmdevita:mainfrom
mwstowe:fix-deprecated-async-get-device
Sep 10, 2026
Merged

jmdevita merged 1 commit into
jmdevita:mainfrom
mwstowe:fix-deprecated-async-get-device

Conversation

@mwstowe

@mwstowe mwstowe commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

cleanup_old_device() calls device_registry.async_get_device(identifiers={(DOMAIN,)}). Home Assistant deprecated async_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 via async_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_compile passes.

Deprecation reference

Detected that custom integration 'parcelapp' calls device_registry.async_get_device, which is deprecated ... This will stop working in Home Assistant 2027.8.0.

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.
@mwstowe mwstowe changed the title Fix deprecated device_registry.async_get_device (removed in HA 2027.8.0) fix: replace deprecated device_registry.async_get_device (removed in HA 2027.8.0) Sep 7, 2026
@jmdevita

Copy link
Copy Markdown
Owner

Thanks @mwstowe ! All looks good. I'll merge and introduce a new release soon with this in place.

@jmdevita
jmdevita merged commit 4542aa9 into jmdevita:main Sep 10, 2026
5 of 6 checks passed
@jmdevita jmdevita added the fix label Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants