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