]> git.basschouten.com Git - openhab-addons.git/blob
e2c89b01e732d7d2e13b4ecf2028ae21c277d8d4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mqtt.homeassistant.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.mqtt.generic.values.RollershutterValue;
18
19 /**
20  * A MQTT Cover component, following the https://www.home-assistant.io/components/cover.mqtt/ specification.
21  *
22  * Only Open/Close/Stop works so far.
23  *
24  * @author David Graeff - Initial contribution
25  */
26 @NonNullByDefault
27 public class ComponentCover extends AbstractComponent<ComponentCover.ChannelConfiguration> {
28     public static final String switchChannelID = "cover"; // Randomly chosen channel "ID"
29
30     /**
31      * Configuration class for MQTT component
32      */
33     static class ChannelConfiguration extends BaseChannelConfiguration {
34         ChannelConfiguration() {
35             super("MQTT Cover");
36         }
37
38         protected @Nullable String state_topic;
39         protected @Nullable String command_topic;
40         protected String payload_open = "OPEN";
41         protected String payload_close = "CLOSE";
42         protected String payload_stop = "STOP";
43     }
44
45     public ComponentCover(CFactory.ComponentConfiguration componentConfiguration) {
46         super(componentConfiguration, ChannelConfiguration.class);
47
48         RollershutterValue value = new RollershutterValue(channelConfiguration.payload_open,
49                 channelConfiguration.payload_close, channelConfiguration.payload_stop);
50
51         buildChannel(switchChannelID, value, channelConfiguration.name, componentConfiguration.getUpdateListener())
52                 .stateTopic(channelConfiguration.state_topic, channelConfiguration.value_template)
53                 .commandTopic(channelConfiguration.command_topic, channelConfiguration.retain).build();
54     }
55 }