2 * Copyright (c) 2010-2021 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;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.mqtt.generic.values.TextValue;
22 import org.openhab.core.library.types.StringType;
25 * Tests for {@link AlarmControlPanel}
27 * @author Anton Kharuzhy - Initial contribution
29 @SuppressWarnings("ConstantConditions")
30 public class AlarmControlPanelTests extends AbstractComponentTests {
31 public static final String CONFIG_TOPIC = "alarm_control_panel/0x0000000000000000_alarm_control_panel_zigbee2mqtt";
34 public void testAlarmControlPanel() {
36 var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
38 " \"availability\": [ " +
40 " \"topic\": \"zigbee2mqtt/bridge/state\" " +
43 " \"code\": \"12345\", " +
44 " \"command_topic\": \"zigbee2mqtt/alarm/set/state\", " +
46 " \"identifiers\": [ " +
47 " \"zigbee2mqtt_0x0000000000000000\" " +
49 " \"manufacturer\": \"BestAlarmEver\", " +
50 " \"model\": \"Heavy duty super duper alarm\", " +
51 " \"name\": \"Alarm\", " +
52 " \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
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\" " +
64 assertThat(component.channels.size(), is(4));
65 assertThat(component.getName(), is("alarm"));
67 assertChannel(component, AlarmControlPanel.STATE_CHANNEL_ID, "zigbee2mqtt/alarm/state", "", "alarm",
69 assertChannel(component, AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", "alarm",
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);
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"));
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_");
92 protected Set<String> getConfigTopics() {
93 return Set.of(CONFIG_TOPIC);