@@ -207,9 +207,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
207207 component = EntityComponent (_LOGGER , DOMAIN , hass )
208208 await component .async_add_entities (plant_entities )
209209
210- # Add the entities to device registry together with plant
210+ # Add the entities to device registry and tie to config entry
211211 device_id = plant .device_id
212- await _plant_add_to_device_registry (hass , plant_entities , device_id )
212+ await _plant_add_to_device_registry (hass , plant_entities , device_id , entry )
213213
214214 # Set up utility sensor
215215 hass .data .setdefault (DATA_UTILITY , {})
@@ -317,9 +317,12 @@ async def replace_sensor(call: ServiceCall) -> None:
317317
318318
319319async def _plant_add_to_device_registry (
320- hass : HomeAssistant , plant_entities : list [Entity ], device_id : str
320+ hass : HomeAssistant ,
321+ plant_entities : list [Entity ],
322+ device_id : str ,
323+ entry : ConfigEntry ,
321324) -> None :
322- """Add all related entities to the correct device_id """
325+ """Add all related entities to the correct device and config entry. """
323326
324327 # There must be a better way to do this, but I just can't find a way to set the
325328 # device_id when adding the entities.
@@ -329,7 +332,11 @@ async def _plant_add_to_device_registry(
329332 raise ConfigEntryNotReady (
330333 f"Entity { entity .entity_id } not yet registered, retrying setup"
331334 )
332- erreg .async_update_entity (entity .registry_entry .entity_id , device_id = device_id )
335+ erreg .async_update_entity (
336+ entity .registry_entry .entity_id ,
337+ device_id = device_id ,
338+ config_entry_id = entry .entry_id ,
339+ )
333340
334341
335342async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
0 commit comments