From: Cody Cutrer Date: Tue, 22 Oct 2024 04:20:11 +0000 (-0500) Subject: [mqtt.homeassistant] JSON Attributes can exist on Cover (#17611) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=b94ed45076433ad2ffe31dc65e0158dc50357612;p=openhab-addons.git [mqtt.homeassistant] JSON Attributes can exist on Cover (#17611) Signed-off-by: Cody Cutrer --- diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java index cc40947d38..69ba7a8b88 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Cover.java @@ -40,6 +40,7 @@ import com.google.gson.annotations.SerializedName; public class Cover extends AbstractComponent { public static final String COVER_CHANNEL_ID = "cover"; public static final String STATE_CHANNEL_ID = "state"; + public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes"; /** * Configuration class for MQTT component @@ -83,6 +84,11 @@ public class Cover extends AbstractComponent { protected String stateOpening = "opening"; @SerializedName("state_stopped") protected String stateStopped = "stopped"; + + @SerializedName("json_attributes_template") + protected @Nullable String jsonAttributesTemplate; + @SerializedName("json_attributes_topic") + protected @Nullable String jsonAttributesTopic; } @Nullable @@ -159,6 +165,13 @@ public class Cover extends AbstractComponent { } return true; }).withAutoUpdatePolicy(optimistic ? AutoUpdatePolicy.RECOMMEND : null).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(); } }