Fix not including device_name in friendly name if it is None#95485
Conversation
| ): | ||
| return name | ||
|
|
||
| device_name = device_entry.name_by_user or device_entry.name |
There was a problem hiding this comment.
This makes me wonder if we should even allow a device to have no name. Should we make up a random name in the device registry if name is empty?
There was a problem hiding this comment.
I am not sure about that, it is that with mqtt we have some tests and examples where no device name is set, when then a default entity name is assigned we get a None prefix to the friendly name, and none_ is added to the 2nd part of the entity id. @emontnemery thinks this is a bug. In this case I would just omit the device part as it does not make sense to add it.
There was a problem hiding this comment.
Shouldn't we reject the configuration instead? if you want to have your entity name be based on a device but there is no device name, it doesn't work ?
There was a problem hiding this comment.
It does work, you get an unnamed device. Now allowing this would be breaking, as a device name is optional.
There was a problem hiding this comment.
Right, but shouldn't we phase in that it's required if has_entity_name is set to True?
There was a problem hiding this comment.
That sounds reasonable to me. If if for MQTT items we do not want to bother the user, we could set has_entity_name to False when no device name is set and make a device_name required when has_entity_name is set to True.
There was a problem hiding this comment.
Setting has_entity_name to False if no device name is set would be a good alternative:
https://github.com/home-assistant/core/pull/95159/files#r1247719960
There was a problem hiding this comment.
A case where this will not work is when we want to follow the name of the device_class. In that case has_entity_name must be set to True.
|
Thnx @balloob ! |
|
Reopening since the default |
ebd9521 to
d5a5a1c
Compare
Breaking change
Not sure
Proposed change
If both
device_entry.name_by_userordevice_entry.nameareNone, then it should not be used to build the friendly name.Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: