2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mqtt.homeassistant.internal.component;
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.assertThrows;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.mqtt.generic.values.TextValue;
24 import org.openhab.core.library.types.StringType;
27 * Tests for {@link Button}
29 * @author Cody Cutrer - Initial contribution
32 public class ButtonTests extends AbstractComponentTests {
33 public static final String CONFIG_TOPIC = "button/0x847127fffe11dd6a_auto_lock_zigbee2mqtt";
35 @SuppressWarnings("null")
37 public void testButton() {
38 var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
42 "entity_category":"config",
43 "cmd_t":"esphome/single-car-gdo/button/restart/command",
44 "avty_t":"esphome/single-car-gdo/status",
45 "uniq_id":"78e36d645710-button-ba0e8e32",
48 "name":"Single Car Garage Door Opener",
49 "sw":"esphome v2023.10.4 Nov 1 2023, 09:27:02",
55 assertThat(component.channels.size(), is(1));
56 assertThat(component.getName(), is("Restart"));
58 assertChannel(component, Button.BUTTON_CHANNEL_ID, "", "esphome/single-car-gdo/button/restart/command",
59 "Restart", TextValue.class);
61 assertThrows(IllegalArgumentException.class,
62 () -> component.getChannel(Button.BUTTON_CHANNEL_ID).getState().publishValue(new StringType("ON")));
63 assertNothingPublished("esphome/single-car-gdo/button/restart/command");
64 component.getChannel(Button.BUTTON_CHANNEL_ID).getState().publishValue(new StringType("PRESS"));
65 assertPublished("esphome/single-car-gdo/button/restart/command", "PRESS");
69 protected Set<String> getConfigTopics() {
70 return Set.of(CONFIG_TOPIC);