2 * Copyright (c) 2010-2020 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;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.mqtt.generic.values.TextValue;
20 * A MQTT alarm control panel, following the https://www.home-assistant.io/components/alarm_control_panel.mqtt/
23 * The implemented provides three state-less switches (For disarming, arming@home, arming@away) and one alarm state
26 * @author David Graeff - Initial contribution
29 public class ComponentAlarmControlPanel extends AbstractComponent<ComponentAlarmControlPanel.ChannelConfiguration> {
30 public static final String stateChannelID = "alarm"; // Randomly chosen channel "ID"
31 public static final String switchDisarmChannelID = "disarm"; // Randomly chosen channel "ID"
32 public static final String switchArmHomeChannelID = "armhome"; // Randomly chosen channel "ID"
33 public static final String switchArmAwayChannelID = "armaway"; // Randomly chosen channel "ID"
36 * Configuration class for MQTT component
38 static class ChannelConfiguration extends BaseChannelConfiguration {
39 ChannelConfiguration() {
43 protected @Nullable String code;
45 protected String state_topic = "";
46 protected String state_disarmed = "disarmed";
47 protected String state_armed_home = "armed_home";
48 protected String state_armed_away = "armed_away";
49 protected String state_pending = "pending";
50 protected String state_triggered = "triggered";
52 protected @Nullable String command_topic;
53 protected String payload_disarm = "DISARM";
54 protected String payload_arm_home = "ARM_HOME";
55 protected String payload_arm_away = "ARM_AWAY";
58 public ComponentAlarmControlPanel(CFactory.ComponentConfiguration componentConfiguration) {
59 super(componentConfiguration, ChannelConfiguration.class);
61 final String[] state_enum = { channelConfiguration.state_disarmed, channelConfiguration.state_armed_home,
62 channelConfiguration.state_armed_away, channelConfiguration.state_pending,
63 channelConfiguration.state_triggered };
64 buildChannel(stateChannelID, new TextValue(state_enum), channelConfiguration.name,
65 componentConfiguration.getUpdateListener())
66 .stateTopic(channelConfiguration.state_topic, channelConfiguration.value_template)//
69 String command_topic = channelConfiguration.command_topic;
70 if (command_topic != null) {
71 buildChannel(switchDisarmChannelID, new TextValue(new String[] { channelConfiguration.payload_disarm }),
72 channelConfiguration.name, componentConfiguration.getUpdateListener())
73 .commandTopic(command_topic, channelConfiguration.retain).build();
75 buildChannel(switchArmHomeChannelID, new TextValue(new String[] { channelConfiguration.payload_arm_home }),
76 channelConfiguration.name, componentConfiguration.getUpdateListener())
77 .commandTopic(command_topic, channelConfiguration.retain).build();
79 buildChannel(switchArmAwayChannelID, new TextValue(new String[] { channelConfiguration.payload_arm_away }),
80 channelConfiguration.name, componentConfiguration.getUpdateListener())
81 .commandTopic(command_topic, channelConfiguration.retain).build();