Closed sgraystar closed 5 months ago
From the doco...
_The friendly_name
state attribute is generated by combining then entity name with the device name as follows:_
_The entity is not a member of a device: friendly_name = entity.name
_
_The entity is a member of a device and entity.name
is not None
: friendly_name = f"{device.name} {entity.name}"
_
_The entity is a member of a device and entity.name
is None
: friendly_name = f"{device.name}"
_
I am setting entity.name
to '', and not None
, and setting the entity to be a device member, so alternative two applies, and HA is inserting the space at the end. I changed that and nothing blew up, so I'll create a branched commit for you to test my thinking. Stand by.
Something is weird with this change. "MQTT blah" is being appended to preferred names...
and I think it may be a HA bug, MQTT Explorer looks fine
Indeed.
What does friendly_name
look like now? (I couldn't work out how to display that for MQTT discovery.)
Yeah, the line 787 did something else so I reverted.
I was looking at the dev.ids and dev.name parameters in MQTT explorer which look fine. And HA Developer Tools, States, Select a cover entity so you can set state. This shows a space at the end of friendly_name, which I hit when expecting to get a digit from an automation with {{ state_attr(trigger.entity_id, 'friendly_name')[-1] }}
Unless this is changed somehow when publishing new values I guess this is a HA bug?
But the the below is still a bug: Lighting GA, add keywords: MQTT, cover, noleveltranslate, pn='ext blind 6', sa=ZZZ, img=mdi:roller-shade, MQTT explorer and HA friendly name includes the quotation marks in the string.
friendly_name: "'ext blind 06'"
But the the below is still a bug: (the quotes)
Kind of. It's actually by design that any quotation marks are included. Example: Steve's bedside light
or "Bleep" of a device
I'm currently trawling through the HA source to see what is causing MQTT LightEntity
, etc. to be appended. This is not in the documentation.
OK, that makes sense
I have more than a theory.
Each MQTT thing has a 'default' name in the source code, and by setting payload.name to nil this is removing payload.name from the JSON. Contrast this with a discovery item from Zigbee2MQTT, where it features a specific "name": null
.
I am going to need to hack this, as LUA is to blame.
leave as-is and cover on readme ...
Nah. It's annoying me.
This commit pleases me greatly, @sgraystar. Should do the trick.
all fixed
Gday Steve, this definitely in the low priority list.
I was tinkering in HA and found the following with friendly name.
Device: 5500AC2 Version: 1.15.0, hw v1.1 Script version: https://github.com/autoSteve/acMqtt/commit/dd6c72ba16f04ea1e20eea3baff8e64511a56ee2
--[[ SET AS APPROPRIATE TO SUIT ENVIRONMENT --]] all false
Lighting GA, add keywords: MQTT, cover, noleveltranslate, sa=ZZZ, img=mdi:roller-shade, HA friendly_name has a space character appended to the tag name.
Lighting GA, add keywords: MQTT, cover, noleveltranslate, pn='ext blind 6', sa=ZZZ, img=mdi:roller-shade, HA friendly name includes the quotation marks.
Lighting GA, add keywords: MQTT, cover, noleveltranslate, pn=extblind6, sa=ZZZ, img=mdi:roller-shade, HA friendly_name has a space character appended to the end.