]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt.homeassistant] Add support for Scene component (#15916)
authorCody Cutrer <cody@cutrer.us>
Sun, 19 Nov 2023 16:54:33 +0000 (09:54 -0700)
committerGitHub <noreply@github.com>
Sun, 19 Nov 2023 16:54:33 +0000 (17:54 +0100)
Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/ComponentFactory.java
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Scene.java [new file with mode: 0644]

index 6c95d5eeddecc13d55c063d4fe17951d3d36a5e2..3246c3789480c9d506c92e253d0cd6fa860a87d6 100644 (file)
@@ -75,6 +75,8 @@ public class ComponentFactory {
                 return new Lock(componentConfiguration);
             case "number":
                 return new Number(componentConfiguration);
+            case "scene":
+                return new Scene(componentConfiguration);
             case "select":
                 return new Select(componentConfiguration);
             case "sensor":
diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Scene.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Scene.java
new file mode 100644 (file)
index 0000000..1d323c2
--- /dev/null
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.mqtt.homeassistant.internal.component;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.mqtt.generic.values.TextValue;
+import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * A MQTT scene, following the https://www.home-assistant.io/integrations/scene.mqtt/ specification.
+ *
+ * @author Cody Cutrer - Initial contribution
+ */
+@NonNullByDefault
+public class Scene extends AbstractComponent<Scene.ChannelConfiguration> {
+    public static final String SCENE_CHANNEL_ID = "scene";
+
+    /**
+     * Configuration class for MQTT component
+     */
+    static class ChannelConfiguration extends AbstractChannelConfiguration {
+        ChannelConfiguration() {
+            super("MQTT Scene");
+        }
+
+        @SerializedName("command_topic")
+        protected @Nullable String commandTopic;
+
+        @SerializedName("payload_on")
+        protected String payloadOn = "ON";
+    }
+
+    public Scene(ComponentFactory.ComponentConfiguration componentConfiguration) {
+        super(componentConfiguration, ChannelConfiguration.class);
+
+        TextValue value = new TextValue(new String[] { channelConfiguration.payloadOn });
+
+        buildChannel(SCENE_CHANNEL_ID, value, getName(), componentConfiguration.getUpdateListener())
+                .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
+                        channelConfiguration.getQos())
+                .build();
+    }
+}