2 * Copyright (c) 2010-2023 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.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;
26 * Tests for {@link AlarmControlPanel}
28 * @author Anton Kharuzhy - Initial contribution
31 public class AlarmControlPanelTests extends AbstractComponentTests {
32 public static final String CONFIG_TOPIC = "alarm_control_panel/0x0000000000000000_alarm_control_panel_zigbee2mqtt";
34 @SuppressWarnings("null")
36 public void testAlarmControlPanel() {
38 var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC),
40 " \"availability\": [ " +
42 " \"topic\": \"zigbee2mqtt/bridge/state\" " +
45 " \"code\": \"12345\", " +
46 " \"command_topic\": \"zigbee2mqtt/alarm/set/state\", " +
48 " \"identifiers\": [ " +
49 " \"zigbee2mqtt_0x0000000000000000\" " +
51 " \"manufacturer\": \"BestAlarmEver\", " +
52 " \"model\": \"Heavy duty super duper alarm\", " +
53 " \"name\": \"Alarm\", " +
54 " \"sw_version\": \"Zigbee2MQTT 1.18.2\" " +
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\" " +
66 assertThat(component.channels.size(), is(4));
67 assertThat(component.getName(), is("alarm"));
69 assertChannel(component, AlarmControlPanel.STATE_CHANNEL_ID, "zigbee2mqtt/alarm/state", "", "alarm",
71 assertChannel(component, AlarmControlPanel.SWITCH_DISARM_CHANNEL_ID, "", "zigbee2mqtt/alarm/set/state", "alarm",
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);
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"));
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_");
95 protected Set<String> getConfigTopics() {
96 return Set.of(CONFIG_TOPIC);