*/
package org.openhab.binding.mqtt.homeassistant.internal.component;
-import java.util.List;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.mqtt.generic.ChannelStateUpdateListener;
import org.openhab.binding.mqtt.generic.values.OnOffValue;
+import org.openhab.binding.mqtt.generic.values.TextValue;
import org.openhab.binding.mqtt.generic.values.Value;
import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannelType;
import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
*/
@NonNullByDefault
public class BinarySensor extends AbstractComponent<BinarySensor.ChannelConfiguration> {
- public static final String SENSOR_CHANNEL_ID = "sensor"; // Randomly chosen channel "ID"
+ public static final String SENSOR_CHANNEL_ID = "sensor";
+ public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes";
/**
* Configuration class for MQTT component
protected @Nullable String jsonAttributesTopic;
@SerializedName("json_attributes_template")
protected @Nullable String jsonAttributesTemplate;
- @SerializedName("json_attributes")
- protected @Nullable List<String> jsonAttributes;
}
public BinarySensor(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) {
getListener(componentConfiguration, value))
.stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())
.withAutoUpdatePolicy(AutoUpdatePolicy.VETO).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();
}
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 com.google.gson.annotations.SerializedName;
buildChannel(CAMERA_CHANNEL_ID, ComponentChannelType.IMAGE, value, getName(),
componentConfiguration.getUpdateListener()).stateTopic(channelConfiguration.topic).build();
- if (channelConfiguration.jsonAttributesTemplate != null) {
+ if (channelConfiguration.jsonAttributesTopic != null) {
buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
componentConfiguration.getUpdateListener())
.stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
- .build();
+ .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build();
}
finalizeChannels();
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.thing.ChannelUID;
+import org.openhab.core.thing.type.AutoUpdatePolicy;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
.inferOptimistic(channelConfiguration.optimistic).build();
}
- if (channelConfiguration.jsonAttributesTemplate != null) {
+ if (channelConfiguration.jsonAttributesTopic != null) {
buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
componentConfiguration.getUpdateListener())
.stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
- .build();
+ .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build();
}
finalizeChannels();
*/
package org.openhab.binding.mqtt.homeassistant.internal.component;
-import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.jdt.annotation.NonNullByDefault;
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.listener.ExpireUpdateStateListener;
+import org.openhab.core.thing.type.AutoUpdatePolicy;
import org.openhab.core.types.util.UnitUtils;
import com.google.gson.annotations.SerializedName;
protected @Nullable String jsonAttributesTopic;
@SerializedName("json_attributes_template")
protected @Nullable String jsonAttributesTemplate;
- @SerializedName("json_attributes")
- protected @Nullable List<String> jsonAttributes;
}
public Sensor(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) {
.stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())//
.trigger(trigger).build();
- if (channelConfiguration.jsonAttributesTemplate != null) {
+ if (channelConfiguration.jsonAttributesTopic != null) {
buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
componentConfiguration.getUpdateListener())
.stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
- .build();
+ .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build();
}
finalizeChannels();
}