]> git.basschouten.com Git - openhab-addons.git/blob
3a365424741b9773b82572ef9b2e6863567b02ac
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 import org.openhab.core.library.types.StringType;
24
25 /**
26  * Tests for {@link AlarmControlPanel}
27  *
28  * @author Anton Kharuzhy - Initial contribution
29  */
30 @NonNullByDefault
31 public class AlarmControlPanelTests extends AbstractComponentTests {
32     public static final String CONFIG_TOPIC = "alarm_control_panel/0x0000000000000000_alarm_control_panel_zigbee2mqtt";
33
34     @SuppressWarnings("null")
35     @Test
36     public void testAlarmControlPanel() {
37         // @formatter:off
38         var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
39                 """
40                 { \
41                   "availability": [ \
42                     { \
43                       "topic": "zigbee2mqtt/bridge/state" \
44                     } \
45                   ], \
46                   "code": "12345", \
47                   "command_topic": "zigbee2mqtt/alarm/set/state", \
48                   "device": { \
49                     "identifiers": [ \
50                       "zigbee2mqtt_0x0000000000000000" \
51                     ], \
52                     "manufacturer": "BestAlarmEver", \
53                     "model": "Heavy duty super duper alarm", \
54                     "name": "Alarm", \
55                     "sw_version": "Zigbee2MQTT 1.18.2" \
56                   }, \
57                   "name": "alarm", \
58                   "payload_arm_away": "ARM_AWAY_", \
59                   "payload_arm_home": "ARM_HOME_", \
60                   "payload_arm_night": "ARM_NIGHT_", \
61                   "payload_arm_custom_bypass": "ARM_CUSTOM_BYPASS_", \
62                   "payload_disarm": "DISARM_", \
63                   "state_topic": "zigbee2mqtt/alarm/state" \
64                 } \
65                 """);
66         // @formatter:on
67
68         assertThat(component.channels.size(), is(4));
69         assertThat(component.getName(), is("alarm"));
70
71         assertChannel(component, AlarmControlPanel.STATE_CHANNEL_ID, "zigbee2mqtt/alarm/state", "", "alarm",
72                 TextValue.class);
73         assertChannel(component, AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", "alarm",
74                 TextValue.class);
75         assertChannel(component, AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state",
76                 "alarm", TextValue.class);
77         assertChannel(component, AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state",
78                 "alarm", TextValue.class);
79
80         publishMessage("zigbee2mqtt/alarm/state", "armed_home");
81         assertState(component, AlarmControlPanel.STATE_CHANNEL_ID, new StringType("armed_home"));
82         publishMessage("zigbee2mqtt/alarm/state", "armed_away");
83         assertState(component, AlarmControlPanel.STATE_CHANNEL_ID, new StringType("armed_away"));
84
85         component.getChannel(AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID).getState()
86                 .publishValue(new StringType("DISARM_"));
87         assertPublished("zigbee2mqtt/alarm/set/state", "DISARM_");
88         component.getChannel(AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID).getState()
89                 .publishValue(new StringType("ARM_AWAY_"));
90         assertPublished("zigbee2mqtt/alarm/set/state", "ARM_AWAY_");
91         component.getChannel(AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID).getState()
92                 .publishValue(new StringType("ARM_HOME_"));
93         assertPublished("zigbee2mqtt/alarm/set/state", "ARM_HOME_");
94     }
95
96     @Override
97     protected Set<String> getConfigTopics() {
98         return Set.of(CONFIG_TOPIC);
99     }
100 }