]> git.basschouten.com Git - openhab-addons.git/blob
baa476704eb949e050db8efd207c064cd7b136df
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mqtt.homeassistant.internal.component;
14
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.mqtt.generic.values.TextValue;
23
24 /**
25  * Tests for {@link DeviceTrigger}
26  *
27  * @author Cody Cutrer - Initial contribution
28  */
29 @NonNullByDefault
30 public class DeviceTriggerTests extends AbstractComponentTests {
31     public static final String CONFIG_TOPIC = "device_automation/0x8cf681fffe2fd2a6";
32
33     @SuppressWarnings("null")
34     @Test
35     public void test() throws InterruptedException {
36         var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
37                 {
38                     "automation_type": "trigger",
39                     "device": {
40                         "configuration_url": "#/device/0x8cf681fffe2fd2a6/info",
41                         "identifiers": [
42                             "zigbee2mqtt_0x8cf681fffe2fd2a6"
43                         ],
44                         "manufacturer": "IKEA",
45                         "model": "TRADFRI shortcut button (E1812)",
46                         "name": "Charge Now Button",
47                         "sw_version": "2.3.015"
48                     },
49                     "payload": "on",
50                     "subtype": "on",
51                     "topic": "zigbee2mqtt/Charge Now Button/action",
52                     "type": "action"
53                 }
54                     """);
55
56         assertThat(component.channels.size(), is(1));
57         assertThat(component.getName(), is("MQTT Device Trigger"));
58
59         assertChannel(component, "action", "zigbee2mqtt/Charge Now Button/action", "", "MQTT Device Trigger",
60                 TextValue.class);
61
62         spyOnChannelUpdates(component, "action");
63         publishMessage("zigbee2mqtt/Charge Now Button/action", "on");
64         assertTriggered(component, "action", "on");
65
66         publishMessage("zigbee2mqtt/Charge Now Button/action", "off");
67         assertNotTriggered(component, "action", "off");
68     }
69
70     @Override
71     protected Set<String> getConfigTopics() {
72         return Set.of(CONFIG_TOPIC);
73     }
74 }