Skip to content

Separate names into fallback_name and forced_name (for DIY Zigbee devices) #527

@TheJulianJES

Description

@TheJulianJES

Background

Due to custom quirks, fallback_name was introduced in quirks. It provides the default English name we use to generate strings.json for translated entity names in HA and allows users of custom quirks to name their entities, without modifying and generating Core translation files.

Home Assistant will only use this name if (1) no translation value(!) is provided and (2) if no device class (which have a name) is set.
Home Assistant does both of those actions via its internal name resolving method. However, this also means that device class names take priority over fallback names (if no translation value was found for the given key).

(Copied parts below from a related issue: zigpy/zigpy#1523)

More explanation

This is an issue in the ZHA integration in HA we can't really fix (easily). The following priority of names occurs:

  1. Translation key (handled by HA)
  2. Device class name (handled by HA)
  3. Fallback name (handled by ZHA integration)

When a quirk is officially added, zha-quirks is bumped in the ZHA lib, and the ZHA lib bump eventually makes it way to HA.
We automatically update strings.json in HA with the new translation keys and the fallback_name for (US) English.
So, this is only really an issue with custom quirks, as translation keys/values (or the device class name) will always exist upstream.

Normally, HA fully deals with the name (as entities are generally added via HA only). ZHA is a bit special, as there a lot of devices (Tuya) and even custom devices, so it makes sense to provide some (basic) entity support/metadata from the quirks lib. But to even allow the entities to have a name during development at all, we had to introduce fallback_name and it'll only fall back to that if HA wasn't able to find a name before (translation key value or device class name).
We can't really change HA without re-implementing what HA internals normally deal with.

Our issue (most important part of this issue)

But there's one issue that not only custom quirks have, but we have as well:
AnalogInput, AnalogOutput, BinaryInput, BinaryOutput, and so on, all have a description attribute that manufacturers can use to name the resulting entity (in Home Assistant). Matter has a similar concept with its label attribute.

But we currently set the fallback_name to the value of the description attribute if it's supported and not empty. This won't force the name to display if a device class is set. With our current implementation, this likely can't happen, as we never set the device class (IIRC) for these kinds of entities, but:

We should still provide a separate "forced_name" (or just "name") attribute in the BaseEntityInfo that will take priority over translation key, device class name, and fallback name.

ESPHome / DIY Zigbee devices

Most manufacturers don't actually use the description attribute, or just misuse these clusters in general.
However, multiple (still custom) components and ESPHome PRs exist that allow to expose custom Zigbee entities. These generally need to be named in a similar way to how is allowed by using the ESPHome integration in HA. To allow this, the description attribute is set.

We should make sure all these clusters/entities always show their name set in ESPHome. Like mentioned above, for those names, we should set a "forced name" attribute, not just fallback_name.

Future

In the future, we may wanna see if we can improve the situation with the fallback_name even further, especially regarding the situation described at the top of this issue. The code in HA for the fallback name is also a bit "hacky".

Metadata

Metadata

Assignees

No one assigned

    Labels

    code qualityImprovement to code qualityenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions