From 4e5ba15493f3b634e7a8c664694a2d08e862b495 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 21 Oct 2024 23:14:02 -0500 Subject: [PATCH] [mqtt.homeassistant] JSON Attributes can exist on Lock (#17612) Signed-off-by: Cody Cutrer --- .../homeassistant/internal/component/Lock.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Lock.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Lock.java index bce7cef228..8a5da2fc9a 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Lock.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Lock.java @@ -36,6 +36,7 @@ import com.google.gson.annotations.SerializedName; public class Lock extends AbstractComponent { public static final String LOCK_CHANNEL_ID = "lock"; public static final String STATE_CHANNEL_ID = "state"; + public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes"; /** * Configuration class for MQTT component @@ -67,6 +68,11 @@ public class Lock extends AbstractComponent { protected String stateUnlocked = "UNLOCKED"; @SerializedName("state_unlocking") protected String stateUnlocking = "UNLOCKING"; + + @SerializedName("json_attributes_template") + protected @Nullable String jsonAttributesTemplate; + @SerializedName("json_attributes_topic") + protected @Nullable String jsonAttributesTopic; } private boolean optimistic = false; @@ -121,6 +127,14 @@ public class Lock extends AbstractComponent { } return true; }).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(); } -- 2.47.3