Skip to content

Commit 0f5f864

Browse files
authored
Add blog post about helper integrations linking to devices (#2727)
1 parent 4fd60d5 commit 0f5f864

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
author: Erik Montnemery
3+
authorURL: https://github.com/emontnemery
4+
title: "Updated guidelines for helper integrations linking to other integration's device"
5+
---
6+
7+
Helper integrations should not add their own config entries to the source entity's device or to a user selected device. Instead, they should just link their entities to the device of the source entity.
8+
9+
Adding the helper config entry to another integration's device is no longer supported and will stop working in Home Assistant Core 2026.8.
10+
11+
### Background
12+
13+
The architecture proposal [home-assistant/architecture#1226](https://github.com/home-assistant/architecture/discussions/1226) makes device connections and identifiers unique per integration domain instead of globally unique. This is not an issue for most integrations, but helper integrations with config flows are an exception.
14+
15+
### Suggested change
16+
17+
#### Link the helper entity directly to the source integration's device
18+
19+
In the helper entity's constructor, set `self.device_entry` to the source device
20+
```py
21+
class HelperEntity(Entity)
22+
23+
def __init__(hass: HomeAssistant, source_entity_id: str, ...) -> None:
24+
self.device_entry = async_entity_id_to_device(
25+
hass,
26+
source_entity_id,
27+
)
28+
```
29+
30+
#### Do not add the helper config entry to the source device directly
31+
32+
Do not add the config entry to the source device directly, meaning that this pattern is no longer allowed
33+
```py
34+
device_registry.async_update_device(
35+
source_device.id,
36+
add_config_entry_id=helper_config_entry.entry_id,
37+
)
38+
```
39+
40+
#### Do not add the helper config entry to the source device implicitly
41+
42+
Don’t set `self._attr_device_info` and don’t override `device_info` to return identifiers and connections for a device from another integration as that will mean the helper config entry is added to the source device. Instead, Set `self.device_entry` in the helper entity to link the helper entity to another integration's device as in the example above.
43+
44+
#### Cleaning up the device registry
45+
46+
A helper function, `homeassistant.helpers.helper_integration.async_remove_helper_config_entry_from_source_device` is available to aid the clean up. Core integrations have been modified to call this helper from a config entry migration step.
47+
48+
#### Handling removed devices
49+
50+
It is up to the helper integration to decide how to handle a removed device; most core helpers set `self.device_entry` to `None`. Note that `DeviceRegistry.async_get` returns `None` if passed a `device_id` which doesn't exist.
51+
52+
#### Sample implementations
53+
54+
The derivative core integration, which previously added its config entry to the source entity's device, has been updated to just link the helper entity to the source entity's device in core [PR #148674](https://github.com/home-assistant/core/pull/148674).
55+
56+
The template core integration, which previously added its config entry to a user selected device, has been updated to just link the helper entity to the user selected device in core [PR #148756](https://github.com/home-assistant/core/pull/148756).

0 commit comments

Comments
 (0)