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.
fix: replace non-existent DeviceRegistry.async_get_devices() #2124
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
base: main
Are you sure you want to change the base?
fix: replace non-existent DeviceRegistry.async_get_devices() #2124
Changes from all commits
8118864File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge lbbrhzn/ocpp /tmp/coderabbit-repo-knowledge/lbbrhzn-ocpp-bb9555ff/architectureLength of output: 31284
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 9902
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 50368
🌐 Web query:
Home Assistant Core 2026.6.0 DeviceRegistry async_get_device identifiers implementation💡 Result:
In Home Assistant Core 2026.6.0, the DeviceRegistry.async_get_device method is deprecated [1]. This method was used to look up a device based on a set of identifiers or connections [2]; however, as of the 2026.6.0 release cycle and associated architectural changes, identifiers and connections are no longer unique across all of Home Assistant—they are only unique within the scope of a specific config entry [1][3]. Because a lookup by identifiers or connections may now match multiple devices across different config entries, the return value of async_get_device is considered ambiguous [1]. Key implementation notes for developers: 1. Deprecation: Developers are instructed to stop using async_get_device [1]. 2. Replacement: When the owning config entry is known, you must use scope-aware methods: - DeviceRegistry.async_get_device_by_identifier(identifier, entry_id) [1] - DeviceRegistry.async_get_device_by_connection(connection, entry_id) [1] These methods accept a single identifier or connection tuple along with the specific config entry ID to ensure an unambiguous lookup [1]. 3. Ambiguous Handling: During the deprecation period, async_get_device attempts to resolve ambiguity by preferring devices owned by the calling integration or by applying specific fallbacks, such as preferring a device whose config entry domain matches the looked-up identifier [1]. However, this behavior should not be relied upon for new development [1]. 4. Entity Context: If you are working within an entity, you should prefer using self.device_entry rather than performing a registry lookup [1]. These changes were part of a broader transition to restrict devices to a single config entry to improve reliability and registry performance [1][3].
Citations:
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 17421
🌐 Web query:
site:github.com/home-assistant/core/blob/2026.6.0/homeassistant/helpers/device_registry.py "def async_get_device"💡 Result:
Found it in Home Assistant Core 2026.6.0:
It begins around line 3576. [1]
🌐 Web query:
Home Assistant device registry async_get_device_by_identifier config_entry_id 2026.6.0 source💡 Result:
In Home Assistant, async_get_device_by_identifier is a method introduced in the device registry to provide a non-ambiguous way to look up devices [1][2]. Because device identifiers and connections are unique only within the scope of a specific config entry, the older method, async_get_device, was deprecated [1][3]. Using async_get_device_by_identifier (and the related async_get_device_by_connection) requires passing both the identifier tuple and the config_entry_id to ensure the registry returns the specific, correctly-scoped device [1][2]. This change is part of a broader architectural shift to enforce that devices belong to a single config entry [1][4]. While Home Assistant 2026.6.0 included various internal registry updates, the formal deprecation and the introduction of these scoped lookup methods were emphasized in developer communications following the 2026.6 release cycle [1][5][6]. Integrators are advised to replace calls to async_get_device with these scoped methods to avoid ambiguity and prepare for future breaking changes [1][3].
Citations:
🌐 Web query:
Home Assistant Core 2026.6.0 device registry DeviceRegistryDevices get_entry identifiers set implementation💡 Result:
In Home Assistant Core, the DeviceRegistry.get_entry method is designed to retrieve a specific device entry based on provided identifiers or connections [1][2]. As of the current implementation, the method accepts an optional config_entry_id parameter to filter the results, allowing for precise lookups when multiple devices might share similar identifiers across different config entries [1][2]. The method is defined to accept optional sets of tuples for identifiers and connections: identifiers: set[tuple[str, str]] | None = None connections: set[tuple[str, str]] | None = None *, config_entry_id: str | UndefinedType | None = UNDEFINED When identifiers are provided, the implementation iterates through them and performs a lookup against the registry's internal mapping (_identifiers). If a match is found and a specific config_entry_id is provided, it returns the device entry associated with that config entry; otherwise, it returns the first matching entry found [1][2]. A similar lookup logic is applied to connections using the _connections mapping [1]. Key implementation details include: 1. Lookup Logic: The method prioritizes returning an entry that matches both the identifier/connection and the specified config_entry_id (if provided). If no config_entry_id is provided, it returns the first available entry from the set of matches [1][2]. 2. Return Type: It returns a DeviceEntry (or appropriate internal entry type) if a match is found, or None if no match exists [1][2]. 3. Integration: This method is used by higher-level methods like async_get_device, which serves as the public-facing API for retrieving devices by their unique identifiers or connections [3][4]. The identifiers parameter expects a set of tuples, where each tuple is structured as (DOMAIN, identifier), such as (serial_number_domain, serial_number_value) [5]. These identifiers are critical for ensuring that devices are correctly associated with their respective integrations and config entries within the registry [5][6].
Citations:
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 2436
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 6886
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 22841
🏁 Script executed:
Repository: lbbrhzn/ocpp
Length of output: 16091
Select a device after applying the config-entry filter.
When the two identifiers resolve to different devices,
async_get_device()returns the first indexed match. The config-entry check then discards that device andupdate()returns without refreshing entities. Resolve each identifier separately, keep only candidates containingself.entry.entry_id, and add a regression test for this case.🤖 Prompt for AI Agents
Source: MCP tools