Skip to content

Commit

Permalink
[mqtt.homeassistant] JSON Attributes can exist on Number (openhab#17613)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored and KaaNee committed Nov 8, 2024
1 parent abb045c commit baeef2f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +33,7 @@
@NonNullByDefault
public class Number extends AbstractComponent<Number.ChannelConfiguration> {
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
Expand Down Expand Up @@ -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();
}
}

0 comments on commit baeef2f

Please sign in to comment.