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 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;
20 import com.google.gson.annotations.SerializedName;
23 * A MQTT alarm control panel, following the https://www.home-assistant.io/components/alarm_control_panel.mqtt/
26 * The implemented provides three state-less switches (For disarming, arming@home, arming@away) and one alarm state
29 * @author David Graeff - Initial contribution
32 public class AlarmControlPanel extends AbstractComponent<AlarmControlPanel.ChannelConfiguration> {
33 public static final String STATE_CHANNEL_ID = "alarm"; // Randomly chosen channel "ID"
34 public static final String SWITCH_DISARM_CHANNEL_ID = "disarm"; // Randomly chosen channel "ID"
35 public static final String SWITCH_ARM_HOME_CHANNEL_ID = "armhome"; // Randomly chosen channel "ID"
36 public static final String SWITCH_ARM_AWAY_CHANNEL_ID = "armaway"; // Randomly chosen channel "ID"
39 * Configuration class for MQTT component
41 static class ChannelConfiguration extends AbstractChannelConfiguration {
42 ChannelConfiguration() {
46 protected @Nullable String code;
48 @SerializedName("state_topic")
49 protected String stateTopic = "";
50 @SerializedName("state_disarmed")
51 protected String stateDisarmed = "disarmed";
52 @SerializedName("state_armed_home")
53 protected String stateArmedHome = "armed_home";
54 @SerializedName("state_armed_away")
55 protected String stateArmedAway = "armed_away";
56 @SerializedName("state_pending")
57 protected String statePending = "pending";
58 @SerializedName("state_triggered")
59 protected String stateTriggered = "triggered";
61 @SerializedName("command_topic")
62 protected @Nullable String commandTopic;
63 @SerializedName("payload_disarm")
64 protected String payloadDisarm = "DISARM";
65 @SerializedName("payload_arm_home")
66 protected String payloadArmHome = "ARM_HOME";
67 @SerializedName("payload_arm_away")
68 protected String payloadArmAway = "ARM_AWAY";
71 public AlarmControlPanel(ComponentFactory.ComponentConfiguration componentConfiguration) {
72 super(componentConfiguration, ChannelConfiguration.class);
74 final String[] stateEnum = { channelConfiguration.stateDisarmed, channelConfiguration.stateArmedHome,
75 channelConfiguration.stateArmedAway, channelConfiguration.statePending,
76 channelConfiguration.stateTriggered };
77 buildChannel(STATE_CHANNEL_ID, new TextValue(stateEnum), channelConfiguration.getName(),
78 componentConfiguration.getUpdateListener())
79 .stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())//
82 String commandTopic = channelConfiguration.commandTopic;
83 if (commandTopic != null) {
84 buildChannel(SWITCH_DISARM_CHANNEL_ID, new TextValue(new String[] { channelConfiguration.payloadDisarm }),
85 channelConfiguration.getName(), componentConfiguration.getUpdateListener())
86 .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos())
89 buildChannel(SWITCH_ARM_HOME_CHANNEL_ID,
90 new TextValue(new String[] { channelConfiguration.payloadArmHome }), channelConfiguration.getName(),
91 componentConfiguration.getUpdateListener())
92 .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos())
95 buildChannel(SWITCH_ARM_AWAY_CHANNEL_ID,
96 new TextValue(new String[] { channelConfiguration.payloadArmAway }), channelConfiguration.getName(),
97 componentConfiguration.getUpdateListener())
98 .commandTopic(commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos())