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;
19 import org.openhab.core.thing.type.AutoUpdatePolicy;
21 import com.google.gson.annotations.SerializedName;
24 * An MQTT button, following the https://www.home-assistant.io/integrations/button.mqtt/ specification.
26 * @author Cody Cutrer - Initial contribution
29 public class Button extends AbstractComponent<Button.ChannelConfiguration> {
30 public static final String BUTTON_CHANNEL_ID = "button";
33 * Configuration class for MQTT component
35 static class ChannelConfiguration extends AbstractChannelConfiguration {
36 ChannelConfiguration() {
40 protected @Nullable Boolean optimistic;
42 @SerializedName("command_topic")
43 protected @Nullable String commandTopic;
45 @SerializedName("payload_press")
46 protected String payloadPress = "PRESS";
49 public Button(ComponentFactory.ComponentConfiguration componentConfiguration) {
50 super(componentConfiguration, ChannelConfiguration.class);
52 TextValue value = new TextValue(new String[] { channelConfiguration.payloadPress });
54 buildChannel(BUTTON_CHANNEL_ID, value, getName(), componentConfiguration.getUpdateListener())
55 .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
56 channelConfiguration.getQos())
57 .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build();