Use has_entity_name
Bronze rule has-entity-name: entities set has_entity_name to True, and are named in context of their device.
This is a Bronze rule. In quality_scale.yaml, it is called has-entity-name.
Every entity of the integration must set has_entity_name to True. The name of the entity then only describes what it is, like "Temperature", and Home Assistant puts the name of the device in front of it where that is needed. The main feature of a device gets the name None, so it takes the name of the device itself.
With has_entity_name, Home Assistant knows which part of the name is the device and which part is the entity. It can show "Temperature" on the device page, where the device is obvious, and "Living room sensor Temperature" in a list of all entities. Naming works the same way in every integration, and users who rename a device see the new name on all its entities.
It is also the base for translated entity names, which are a Gold rule.
A sensor on a device named "My device", called "My device Temperature":
class MyTemperatureSensor(SensorEntity):
"""Temperature sensor of a device."""
_attr_has_entity_name = True
_attr_translation_key = "temperature"
def __init__(self, device: MyDevice) -> None:
"""Initialize the sensor."""
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, device.serial_number)},
name=device.name,
)The lock that is the main feature of a device, called "My device":
class MyLock(LockEntity):
"""The lock of the device."""
_attr_has_entity_name = True
_attr_name = NoneSet _attr_has_entity_name once, in the base entity in entity.py, and all your entities follow.
Pylint, when the rule is done: home-assistant-missing-has-entity-name warns when an entity class does not always set has_entity_name to True, either on the class, at the start of a method, or through an entity description. A value that depends on a condition does not count.
If the integration does not have any entities, this rule does not apply.
- entity-translations: translate entity names.
- entity-device-class: use device classes.
- devices: create devices.