2 * Copyright (c) 2010-2021 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.OnOffValue;
18 import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
21 * A MQTT Fan component, following the https://www.home-assistant.io/components/fan.mqtt/ specification.
23 * Only ON/OFF is supported so far.
25 * @author David Graeff - Initial contribution
28 public class Fan extends AbstractComponent<Fan.ChannelConfiguration> {
29 public static final String switchChannelID = "fan"; // Randomly chosen channel "ID"
32 * Configuration class for MQTT component
34 static class ChannelConfiguration extends AbstractChannelConfiguration {
35 ChannelConfiguration() {
39 protected @Nullable String state_topic;
40 protected String command_topic = "";
41 protected String payload_on = "ON";
42 protected String payload_off = "OFF";
45 public Fan(ComponentFactory.ComponentConfiguration componentConfiguration) {
46 super(componentConfiguration, ChannelConfiguration.class);
48 OnOffValue value = new OnOffValue(channelConfiguration.payload_on, channelConfiguration.payload_off);
49 buildChannel(switchChannelID, value, channelConfiguration.getName(), componentConfiguration.getUpdateListener())
50 .stateTopic(channelConfiguration.state_topic, channelConfiguration.getValueTemplate())
51 .commandTopic(channelConfiguration.command_topic, channelConfiguration.isRetain(),
52 channelConfiguration.getQos())