[mqtt.homeassistant] Re-fix null component name (#18021)

Re-fixes #15427, regressed from #17933

Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
Cody Cutrer 2025-01-02 09:00:35 -07:00 committed by GitHub
parent d6476042ec
commit 22c7ca99ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 1 deletions

View File

@ -289,7 +289,7 @@ public abstract class AbstractComponent<C extends AbstractChannelConfiguration>
*/
public String getName() {
String result = channelConfiguration.getName();
if (result.isBlank()) {
if (result != null && result.isBlank()) {
result = null;
}

View File

@ -166,6 +166,54 @@ public class SwitchTests extends AbstractComponentTests {
assertPublished("zigbee2mqtt/th1/set/auto_lock", "AUTO");
}
@Test
public void testSwitchNoName() {
var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
{
"availability": [
{
"topic": "zigbee2mqtt/bridge/state",
"value_template": "{{ value_json.state }}"
},
{
"topic": "zigbee2mqtt/Master Bedroom Subwoofer/availability",
"value_template": "{{ value_json.state }}"
}
],
"availability_mode": "all",
"command_topic": "zigbee2mqtt/Master Bedroom Subwoofer/set",
"device": {
"configuration_url": "http://z2m:8084/#/device/0x00124b0029e7388c/info",
"identifiers": [
"zigbee2mqtt_0x00124b0029e7388c"
],
"manufacturer": "SONOFF",
"model": "15A Zigbee smart plug (S40ZBTPB)",
"name": "Master Bedroom Subwoofer",
"sw_version": "1.1.0",
"via_device": "zigbee2mqtt_bridge_0xe0798dfffe882ce4"
},
"name": null,
"object_id": "master_bedroom_subwoofer",
"origin": {
"name": "Zigbee2MQTT",
"sw": "1.42.0-dev",
"url": "https://www.zigbee2mqtt.io"
},
"payload_off": "OFF",
"payload_on": "ON",
"state_topic": "zigbee2mqtt/Master Bedroom Subwoofer",
"unique_id": "0x00124b0029e7388c_switch_zigbee2mqtt",
"value_template": "{{ value_json.state }}"
}
""");
assertThat(component.channels.size(), is(1));
assertThat(component.getName(), is("Master Bedroom Subwoofer"));
assertChannel(component, Switch.SWITCH_CHANNEL_ID, "zigbee2mqtt/Master Bedroom Subwoofer",
"zigbee2mqtt/Master Bedroom Subwoofer/set", "Master Bedroom Subwoofer", OnOffValue.class);
}
@Override
protected Set<String> getConfigTopics() {
return Set.of(CONFIG_TOPIC);