autoSteve / acMqtt

CBus Automation Controller: Home Assistant, MQTT, Philips Hue and more (for the SHAC/NAC/AC2/NAC2)
GNU General Public License v3.0
15 stars 6 forks source link

HA friendly_name problem #45

Closed sgraystar closed 5 months ago

sgraystar commented 5 months ago

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.

friendly_name: "ext blind 6 "

Lighting GA, add keywords: MQTT, cover, noleveltranslate, pn='ext blind 6', sa=ZZZ, img=mdi:roller-shade, HA friendly name includes the quotation marks.

friendly_name: "'ext blind 06'"

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.

friendly_name: "extblind6 "
autoSteve commented 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.

autoSteve commented 5 months ago

Give f579905 a go, or change line 787 to payload.name = nil.

autoSteve commented 5 months ago

Something is weird with this change. "MQTT blah" is being appended to preferred names...

image
sgraystar commented 5 months ago

and I think it may be a HA bug, MQTT Explorer looks fine

autoSteve commented 5 months ago

Indeed.

What does friendly_name look like now? (I couldn't work out how to display that for MQTT discovery.)

sgraystar commented 5 months ago

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'"
autoSteve commented 5 months ago

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.

sgraystar commented 5 months ago

OK, that makes sense

autoSteve commented 5 months ago

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.

image
sgraystar commented 5 months ago

leave as-is and cover on readme ...

autoSteve commented 5 months ago

Nah. It's annoying me.

autoSteve commented 5 months ago

This commit pleases me greatly, @sgraystar. Should do the trick.

sgraystar commented 5 months ago

all fixed