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.RollershutterValue;
18 import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
20 import com.google.gson.annotations.SerializedName;
23 * A MQTT Cover component, following the https://www.home-assistant.io/components/cover.mqtt/ specification.
25 * Only Open/Close/Stop works so far.
27 * @author David Graeff - Initial contribution
30 public class Cover extends AbstractComponent<Cover.ChannelConfiguration> {
31 public static final String SWITCH_CHANNEL_ID = "cover"; // Randomly chosen channel "ID"
34 * Configuration class for MQTT component
36 static class ChannelConfiguration extends AbstractChannelConfiguration {
37 ChannelConfiguration() {
41 @SerializedName("state_topic")
42 protected @Nullable String stateTopic;
43 @SerializedName("command_topic")
44 protected @Nullable String commandTopic;
45 @SerializedName("payload_open")
46 protected String payloadOpen = "OPEN";
47 @SerializedName("payload_close")
48 protected String payloadClose = "CLOSE";
49 @SerializedName("payload_stop")
50 protected String payloadStop = "STOP";
53 public Cover(ComponentFactory.ComponentConfiguration componentConfiguration) {
54 super(componentConfiguration, ChannelConfiguration.class);
56 RollershutterValue value = new RollershutterValue(channelConfiguration.payloadOpen,
57 channelConfiguration.payloadClose, channelConfiguration.payloadStop);
59 buildChannel(SWITCH_CHANNEL_ID, value, getName(), componentConfiguration.getUpdateListener())
60 .stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())
61 .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
62 channelConfiguration.getQos())