]> git.basschouten.com Git - openhab-addons.git/blob
5f07e6fffb4d78fdd13a7ca0bf3cde08930458af
[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                         "  \"availability\": [ " +
41                         "    { " +
42                         "      \"topic\": \"zigbee2mqtt/bridge/state\" " +
43                         "    } " +
44                         "  ], " +
45                         "  \"code\": \"12345\", " +
46                         "  \"command_topic\": \"zigbee2mqtt/alarm/set/state\", " +
47                         "  \"device\": { " +
48                         "    \"identifiers\": [ " +
49                         "      \"zigbee2mqtt_0x0000000000000000\" " +
50                         "    ], " +
51                         "    \"manufacturer\": \"BestAlarmEver\", " +
52                         "    \"model\": \"Heavy duty super duper alarm\", " +
53                         "    \"name\": \"Alarm\", " +
54                         "    \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
55                         "  }, " +
56                         "  \"name\": \"alarm\", " +
57                         "  \"payload_arm_away\": \"ARM_AWAY_\", " +
58                         "  \"payload_arm_home\": \"ARM_HOME_\", " +
59                         "  \"payload_arm_night\": \"ARM_NIGHT_\", " +
60                         "  \"payload_arm_custom_bypass\": \"ARM_CUSTOM_BYPASS_\", " +
61                         "  \"payload_disarm\": \"DISARM_\", " +
62                         "  \"state_topic\": \"zigbee2mqtt/alarm/state\" " +
63                         "} ");
64         // @formatter:on
65
66         assertThat(component.channels.size(), is(4));
67         assertThat(component.getName(), is("alarm"));
68
69         assertChannel(component, AlarmControlPanel.STATE_CHANNEL_ID, "zigbee2mqtt/alarm/state", "", "alarm",
70                 TextValue.class);
71         assertChannel(component, AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", "alarm",
72                 TextValue.class);
73         assertChannel(component, AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state",
74                 "alarm", TextValue.class);
75         assertChannel(component, AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state",
76                 "alarm", TextValue.class);
77
78         publishMessage("zigbee2mqtt/alarm/state", "armed_home");
79         assertState(component, AlarmControlPanel.STATE_CHANNEL_ID, new StringType("armed_home"));
80         publishMessage("zigbee2mqtt/alarm/state", "armed_away");
81         assertState(component, AlarmControlPanel.STATE_CHANNEL_ID, new StringType("armed_away"));
82
83         component.getChannel(AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID).getState()
84                 .publishValue(new StringType("DISARM_"));
85         assertPublished("zigbee2mqtt/alarm/set/state", "DISARM_");
86         component.getChannel(AlarmControlPanel.SWITCH_ARM_AWAY_CHANNEL_ID).getState()
87                 .publishValue(new StringType("ARM_AWAY_"));
88         assertPublished("zigbee2mqtt/alarm/set/state", "ARM_AWAY_");
89         component.getChannel(AlarmControlPanel.SWITCH_ARM_HOME_CHANNEL_ID).getState()
90                 .publishValue(new StringType("ARM_HOME_"));
91         assertPublished("zigbee2mqtt/alarm/set/state", "ARM_HOME_");
92     }
93
94     @Override
95     protected Set<String> getConfigTopics() {
96         return Set.of(CONFIG_TOPIC);
97     }
98 }