4444 EVENT_ENTITY_REGISTRY_UPDATED ,
4545 EventEntityRegistryUpdatedData ,
4646)
47+ from homeassistant .helpers .entity_registry import (
48+ async_get as er_async_get ,
49+ )
4750from homeassistant .helpers .event import (
4851 async_track_state_change_event ,
4952)
@@ -198,11 +201,15 @@ def __init__(
198201 self ._plant = plantdevice
199202 self ._tracker = []
200203 self ._follow_external = True
201- self .entity_id = async_generate_entity_id (
202- f"{ DOMAIN } .{{}}" ,
203- f"{ self ._plant .name } { self ._entity_id_key } " ,
204- current_ids = {},
205- )
204+ # Only force entity_id for existing entities (backwards compat).
205+ # New entities let has_entity_name derive the entity_id automatically.
206+ ent_reg = er_async_get (hass )
207+ if ent_reg .async_get_entity_id (DOMAIN_SENSOR , DOMAIN , self ._attr_unique_id ):
208+ self .entity_id = async_generate_entity_id (
209+ f"{ DOMAIN } .{{}}" ,
210+ f"{ self ._plant .name } { self ._entity_id_key } " ,
211+ current_ids = {},
212+ )
206213 if (
207214 not self ._attr_native_value
208215 or self ._attr_native_value == STATE_UNKNOWN
@@ -220,6 +227,7 @@ def device_info(self) -> DeviceInfo:
220227 """Device info for devices"""
221228 return DeviceInfo (
222229 identifiers = {(DOMAIN , self ._plant .unique_id )},
230+ name = self ._plant .name ,
223231 )
224232
225233 @property
@@ -622,11 +630,13 @@ def __init__(
622630 self ._source_is_ppfd = False # Track if source already provides PPFD
623631 super ().__init__ (hass , config , plantdevice )
624632 self ._follow_unit = False
625- self .entity_id = async_generate_entity_id (
626- f"{ DOMAIN_SENSOR } .{{}}" ,
627- f"{ self ._plant .name } { self ._entity_id_key } " ,
628- current_ids = {},
629- )
633+ ent_reg = er_async_get (hass )
634+ if ent_reg .async_get_entity_id (DOMAIN_SENSOR , DOMAIN , self ._attr_unique_id ):
635+ self .entity_id = async_generate_entity_id (
636+ f"{ DOMAIN_SENSOR } .{{}}" ,
637+ f"{ self ._plant .name } { self ._entity_id_key } " ,
638+ current_ids = {},
639+ )
630640
631641 def _is_ppfd_source (self ) -> bool :
632642 """Check if the external sensor provides PPFD directly (not lux).
@@ -765,17 +775,22 @@ def __init__(
765775 unit_time = UnitOfTime .SECONDS ,
766776 max_sub_interval = None ,
767777 )
768- self .entity_id = async_generate_entity_id (
769- f"{ DOMAIN_SENSOR } .{{}}" ,
770- f"{ self ._plant .name } Total { READING_PPFD } Integral" ,
771- current_ids = {},
772- )
778+ ent_reg = er_async_get (hass )
779+ if ent_reg .async_get_entity_id (
780+ DOMAIN_SENSOR , DOMAIN , f"{ config .entry_id } -ppfd-integral"
781+ ):
782+ self .entity_id = async_generate_entity_id (
783+ f"{ DOMAIN_SENSOR } .{{}}" ,
784+ f"{ self ._plant .name } Total { READING_PPFD } Integral" ,
785+ current_ids = {},
786+ )
773787
774788 @property
775789 def device_info (self ) -> DeviceInfo :
776790 """Device info for devices"""
777791 return DeviceInfo (
778792 identifiers = {(DOMAIN , self ._plant .unique_id )},
793+ name = self ._plant .name ,
779794 )
780795
781796 def _calculate_unit (self , source_unit : str ) -> str :
@@ -874,11 +889,13 @@ def __init__(
874889 suggested_entity_id = None ,
875890 periodically_resetting = True ,
876891 )
877- self .entity_id = async_generate_entity_id (
878- f"{ DOMAIN_SENSOR } .{{}}" ,
879- f"{ self ._plant .name } { READING_DLI } " ,
880- current_ids = {},
881- )
892+ ent_reg = er_async_get (hass )
893+ if ent_reg .async_get_entity_id (DOMAIN_SENSOR , DOMAIN , f"{ config .entry_id } -dli" ):
894+ self .entity_id = async_generate_entity_id (
895+ f"{ DOMAIN_SENSOR } .{{}}" ,
896+ f"{ self ._plant .name } { READING_DLI } " ,
897+ current_ids = {},
898+ )
882899
883900 @property
884901 def native_unit_of_measurement (self ) -> str :
@@ -896,6 +913,7 @@ def device_info(self) -> DeviceInfo:
896913 """Device info for devices"""
897914 return DeviceInfo (
898915 identifiers = {(DOMAIN , self ._plant .unique_id )},
916+ name = self ._plant .name ,
899917 )
900918
901919 async def async_added_to_hass (self ) -> None :
@@ -983,11 +1001,15 @@ def __init__(
9831001 precision = 2 ,
9841002 percentile = 50 , # Not used for "change" characteristic
9851003 )
986- self .entity_id = async_generate_entity_id (
987- f"{ DOMAIN_SENSOR } .{{}}" ,
988- f"{ self ._plant .name } { READING_DLI } _24h" ,
989- current_ids = {},
990- )
1004+ ent_reg = er_async_get (hass )
1005+ if ent_reg .async_get_entity_id (
1006+ DOMAIN_SENSOR , DOMAIN , f"{ config .entry_id } -dli-24h"
1007+ ):
1008+ self .entity_id = async_generate_entity_id (
1009+ f"{ DOMAIN_SENSOR } .{{}}" ,
1010+ f"{ self ._plant .name } { READING_DLI } _24h" ,
1011+ current_ids = {},
1012+ )
9911013
9921014 @property
9931015 def native_unit_of_measurement (self ) -> str :
@@ -1002,6 +1024,7 @@ def device_info(self) -> DeviceInfo:
10021024 """Device info for devices."""
10031025 return DeviceInfo (
10041026 identifiers = {(DOMAIN , self ._plant .unique_id )},
1027+ name = self ._plant .name ,
10051028 )
10061029
10071030
0 commit comments