Skip to content

Commit

Permalink
[mqtt.homeassistant] Re-fix null component name (#18021)
Browse files Browse the repository at this point in the history
Re-fixes #15427, regressed from #17933

Signed-off-by: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer authored Jan 2, 2025
1 parent d647604 commit 22c7ca9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public String getUniqueId() {
*/
public String getName() {
String result = channelConfiguration.getName();
if (result.isBlank()) {
if (result != null && result.isBlank()) {
result = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,54 @@ public void testSwitchWithCommand() {
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);
Expand Down

1 comment on commit 22c7ca9

@openhab-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-4-3-zigbee2mqtt-color-temperature-in-mired-not-working/160911/15

Please sign in to comment.