]> git.basschouten.com Git - openhab-addons.git/blob
85df85b4796a030118cb7710b4078c1712c3d627
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.TextValue;
18 import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
19 import org.openhab.core.thing.type.AutoUpdatePolicy;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * A MQTT scene, following the https://www.home-assistant.io/integrations/scene.mqtt/ specification.
25  *
26  * @author Cody Cutrer - Initial contribution
27  */
28 @NonNullByDefault
29 public class Scene extends AbstractComponent<Scene.ChannelConfiguration> {
30     public static final String SCENE_CHANNEL_ID = "scene";
31
32     /**
33      * Configuration class for MQTT component
34      */
35     static class ChannelConfiguration extends AbstractChannelConfiguration {
36         ChannelConfiguration() {
37             super("MQTT Scene");
38         }
39
40         @SerializedName("command_topic")
41         protected @Nullable String commandTopic;
42
43         @SerializedName("payload_on")
44         protected String payloadOn = "ON";
45     }
46
47     public Scene(ComponentFactory.ComponentConfiguration componentConfiguration) {
48         super(componentConfiguration, ChannelConfiguration.class);
49
50         TextValue value = new TextValue(new String[] { channelConfiguration.payloadOn });
51
52         buildChannel(SCENE_CHANNEL_ID, value, getName(), componentConfiguration.getUpdateListener())
53                 .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
54                         channelConfiguration.getQos())
55                 .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build();
56     }
57 }