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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.mqtt.generic.values.TextValue;
18 import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
21 * A MQTT alarm control panel, following the https://www.home-assistant.io/components/alarm_control_panel.mqtt/
24 * The implemented provides three state-less switches (For disarming, arming@home, arming@away) and one alarm state
27 * @author David Graeff - Initial contribution
30 public class AlarmControlPanel extends AbstractComponent<AlarmControlPanel.ChannelConfiguration> {
31 public static final String stateChannelID = "alarm"; // Randomly chosen channel "ID"
32 public static final String switchDisarmChannelID = "disarm"; // Randomly chosen channel "ID"
33 public static final String switchArmHomeChannelID = "armhome"; // Randomly chosen channel "ID"
34 public static final String switchArmAwayChannelID = "armaway"; // Randomly chosen channel "ID"
37 * Configuration class for MQTT component
39 static class ChannelConfiguration extends AbstractChannelConfiguration {
40 ChannelConfiguration() {
44 protected @Nullable String code;
46 protected String state_topic = "";
47 protected String state_disarmed = "disarmed";
48 protected String state_armed_home = "armed_home";
49 protected String state_armed_away = "armed_away";
50 protected String state_pending = "pending";
51 protected String state_triggered = "triggered";
53 protected @Nullable String command_topic;
54 protected String payload_disarm = "DISARM";
55 protected String payload_arm_home = "ARM_HOME";
56 protected String payload_arm_away = "ARM_AWAY";
59 public AlarmControlPanel(ComponentFactory.ComponentConfiguration componentConfiguration) {
60 super(componentConfiguration, ChannelConfiguration.class);
62 final String[] state_enum = { channelConfiguration.state_disarmed, channelConfiguration.state_armed_home,
63 channelConfiguration.state_armed_away, channelConfiguration.state_pending,
64 channelConfiguration.state_triggered };
65 buildChannel(stateChannelID, new TextValue(state_enum), channelConfiguration.getName(),
66 componentConfiguration.getUpdateListener())
67 .stateTopic(channelConfiguration.state_topic, channelConfiguration.getValueTemplate())//
70 String command_topic = channelConfiguration.command_topic;
71 if (command_topic != null) {
72 buildChannel(switchDisarmChannelID, new TextValue(new String[] { channelConfiguration.payload_disarm }),
73 channelConfiguration.getName(), componentConfiguration.getUpdateListener())
74 .commandTopic(command_topic, channelConfiguration.isRetain(), channelConfiguration.getQos())
77 buildChannel(switchArmHomeChannelID, new TextValue(new String[] { channelConfiguration.payload_arm_home }),
78 channelConfiguration.getName(), componentConfiguration.getUpdateListener())
79 .commandTopic(command_topic, channelConfiguration.isRetain(), channelConfiguration.getQos())
82 buildChannel(switchArmAwayChannelID, new TextValue(new String[] { channelConfiguration.payload_arm_away }),
83 channelConfiguration.getName(), componentConfiguration.getUpdateListener())
84 .commandTopic(command_topic, channelConfiguration.isRetain(), channelConfiguration.getQos())