Skip to content

Commit

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

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer committed Jan 2, 2025
1 parent d647604 commit f95fb39
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

0 comments on commit f95fb39

Please sign in to comment.