mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +01:00
[mqtt.homeassistant] JSON Attributes can exist on Number (#17613)
Signed-off-by: Cody Cutrer <cody@cutrer.us> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
926fff034c
commit
e97833b041
@ -17,8 +17,10 @@ import java.math.BigDecimal;
|
|||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.mqtt.generic.values.NumberValue;
|
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.ComponentChannelType;
|
||||||
import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
|
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 org.openhab.core.types.util.UnitUtils;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
@ -31,6 +33,7 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class Number extends AbstractComponent<Number.ChannelConfiguration> {
|
public class Number extends AbstractComponent<Number.ChannelConfiguration> {
|
||||||
public static final String NUMBER_CHANNEL_ID = "number"; // Randomly chosen channel "ID"
|
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
|
* Configuration class for MQTT component
|
||||||
@ -81,6 +84,14 @@ public class Number extends AbstractComponent<Number.ChannelConfiguration> {
|
|||||||
.commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
|
.commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
|
||||||
channelConfiguration.getQos(), channelConfiguration.commandTemplate)
|
channelConfiguration.getQos(), channelConfiguration.commandTemplate)
|
||||||
.inferOptimistic(channelConfiguration.optimistic).build();
|
.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();
|
finalizeChannels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user