Make use_device_name a cached_property in the base entity class (#119758)
There is a small risk that _attr_name or entity_description would not be set before state was first written, but that would likely be a bug.pull/118012/head^2
parent
6a3778c48e
commit
5ae13c2ae2
|
@ -581,7 +581,7 @@ class Entity(
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return self._attr_unique_id
|
return self._attr_unique_id
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def use_device_name(self) -> bool:
|
def use_device_name(self) -> bool:
|
||||||
"""Return if this entity does not have its own name.
|
"""Return if this entity does not have its own name.
|
||||||
|
|
||||||
|
@ -589,14 +589,12 @@ class Entity(
|
||||||
"""
|
"""
|
||||||
if hasattr(self, "_attr_name"):
|
if hasattr(self, "_attr_name"):
|
||||||
return not self._attr_name
|
return not self._attr_name
|
||||||
|
if (
|
||||||
if name_translation_key := self._name_translation_key:
|
name_translation_key := self._name_translation_key
|
||||||
if name_translation_key in self.platform.platform_translations:
|
) and name_translation_key in self.platform.platform_translations:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if hasattr(self, "entity_description"):
|
if hasattr(self, "entity_description"):
|
||||||
return not self.entity_description.name
|
return not self.entity_description.name
|
||||||
|
|
||||||
return not self.name
|
return not self.name
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|
Loading…
Reference in New Issue