]> git.basschouten.com Git - openhab-addons.git/blob
bf7af7b942ca0207fc2cbcba1e346109017ca63d
[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.component;
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 import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
19
20 /**
21  * A MQTT Cover component, following the https://www.home-assistant.io/components/cover.mqtt/ specification.
22  *
23  * Only Open/Close/Stop works so far.
24  *
25  * @author David Graeff - Initial contribution
26  */
27 @NonNullByDefault
28 public class Cover extends AbstractComponent<Cover.ChannelConfiguration> {
29     public static final String switchChannelID = "cover"; // Randomly chosen channel "ID"
30
31     /**
32      * Configuration class for MQTT component
33      */
34     static class ChannelConfiguration extends AbstractChannelConfiguration {
35         ChannelConfiguration() {
36             super("MQTT Cover");
37         }
38
39         protected @Nullable String state_topic;
40         protected @Nullable String command_topic;
41         protected String payload_open = "OPEN";
42         protected String payload_close = "CLOSE";
43         protected String payload_stop = "STOP";
44     }
45
46     public Cover(ComponentFactory.ComponentConfiguration componentConfiguration) {
47         super(componentConfiguration, ChannelConfiguration.class);
48
49         RollershutterValue value = new RollershutterValue(channelConfiguration.payload_open,
50                 channelConfiguration.payload_close, channelConfiguration.payload_stop);
51
52         buildChannel(switchChannelID, value, channelConfiguration.getName(), componentConfiguration.getUpdateListener())
53                 .stateTopic(channelConfiguration.state_topic, channelConfiguration.getValueTemplate())
54                 .commandTopic(channelConfiguration.command_topic, channelConfiguration.isRetain(),
55                         channelConfiguration.getQos())
56                 .build();
57     }
58 }