From: Cody Cutrer Date: Tue, 22 Oct 2024 04:17:31 +0000 (-0500) Subject: [mqtt.homeassistant] JSON Attributes are supported by Scene (#17614) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=41d306faabf8c2a26a9aac86249f4be5dad4ed74;p=openhab-addons.git [mqtt.homeassistant] JSON Attributes are supported by Scene (#17614) Signed-off-by: Cody Cutrer --- 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 index 0ca4f1ab20..9936a5df74 100644 --- 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 @@ -29,6 +29,7 @@ import com.google.gson.annotations.SerializedName; @NonNullByDefault public class Scene extends AbstractComponent { public static final String SCENE_CHANNEL_ID = "scene"; + public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes"; /** * Configuration class for MQTT component @@ -43,6 +44,11 @@ public class Scene extends AbstractComponent { @SerializedName("payload_on") protected String payloadOn = "ON"; + + @SerializedName("json_attributes_topic") + protected @Nullable String jsonAttributesTopic; + @SerializedName("json_attributes_template") + protected @Nullable String jsonAttributesTemplate; } public Scene(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) { @@ -55,6 +61,14 @@ public class Scene extends AbstractComponent { .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos()) .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build(); + + if (channelConfiguration.jsonAttributesTopic != null) { + buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes", + componentConfiguration.getUpdateListener()) + .stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate) + .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build(); + } + finalizeChannels(); } }