From 8455b68ffa7b87c9ad418acee1d99afede4c93ba Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 21 Oct 2024 16:20:11 -0600 Subject: [PATCH] [mqtt.homeassistant] JSON Attributes can exist on Number Signed-off-by: Cody Cutrer --- .../mqtt/homeassistant/internal/component/Number.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Number.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Number.java index 8de66574f32e9..b68af1b54dbc1 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Number.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Number.java @@ -17,8 +17,10 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.mqtt.generic.values.NumberValue; +import org.openhab.binding.mqtt.generic.values.TextValue; import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannelType; import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration; +import org.openhab.core.thing.type.AutoUpdatePolicy; import org.openhab.core.types.util.UnitUtils; import com.google.gson.annotations.SerializedName; @@ -31,6 +33,7 @@ @NonNullByDefault public class Number extends AbstractComponent { public static final String NUMBER_CHANNEL_ID = "number"; // Randomly chosen channel "ID" + public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes"; /** * Configuration class for MQTT component @@ -81,6 +84,14 @@ public Number(ComponentFactory.ComponentConfiguration componentConfiguration, bo .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(), channelConfiguration.getQos(), channelConfiguration.commandTemplate) .inferOptimistic(channelConfiguration.optimistic).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(); } }