package org.openhab.binding.mqtt.generic;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
+import org.openhab.core.thing.binding.generic.ChannelTransformation;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
@Override
public void addAvailabilityTopic(String availability_topic, String payload_available,
String payload_not_available) {
- addAvailabilityTopic(availability_topic, payload_available, payload_not_available, List.of());
+ addAvailabilityTopic(availability_topic, payload_available, payload_not_available, null);
}
@Override
public void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available,
- List<String> transformation_pattern) {
+ @Nullable ChannelTransformation transformation) {
availabilityStates.computeIfAbsent(availability_topic, topic -> {
Value value = new OnOffValue(payload_available, payload_not_available);
ChannelGroupUID groupUID = new ChannelGroupUID(getThing().getUID(), "availability");
ChannelUID channelUID = new ChannelUID(groupUID, UIDUtils.encode(topic));
- ChannelState state = new ChannelState(
- ChannelConfigBuilder.create().withStateTopic(topic)
- .withTransformationPattern(transformation_pattern).build(),
+ ChannelState state = new ChannelState(ChannelConfigBuilder.create().withStateTopic(topic).build(),
channelUID, value, new ChannelStateUpdateListener() {
@Override
public void updateChannelState(ChannelUID channelUID, State value) {
@Override
public void postChannelCommand(ChannelUID channelUID, Command value) {
}
- });
+ }, transformation, null);
MqttBrokerConnection connection = getConnection();
if (connection != null) {
state.start(connection, scheduler, 0);
*/
package org.openhab.binding.mqtt.generic;
-import java.util.List;
-
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.core.thing.binding.generic.ChannelTransformation;
/**
* Interface to keep track of the availability of device using an availability topic or messages received
* @param availability_topic The MQTT topic where availability is published to.
* @param payload_available The value for the topic to indicate the device is online.
* @param payload_not_available The value for the topic to indicate the device is offline.
- * @param transformation_pattern A transformation pattern to process the value before comparing to
+ * @param transformation A transformation to process the value before comparing to
* payload_available/payload_not_available.
*/
void addAvailabilityTopic(String availability_topic, String payload_available, String payload_not_available,
- List<String> transformation_pattern);
+ @Nullable ChannelTransformation transformation);
void removeAvailabilityTopic(String availability_topic);
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
+import org.openhab.core.thing.binding.generic.ChannelTransformation;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.StateDescription;
import org.openhab.core.types.util.UnitUtils;
if (availabilityTopic != null) {
addAvailabilityTopic(availabilityTopic, config.payloadAvailable, config.payloadNotAvailable,
- config.transformationPattern);
+ new ChannelTransformation(config.transformationPattern));
} else {
clearAllAvailabilityTopics();
}
*/
@NonNullByDefault
public class ComponentChannel {
- private static final String JINJA = "JINJA";
-
private final ChannelState channelState;
private final Channel channel;
private final @Nullable StateDescription stateDescription;
import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannel;
import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannelType;
import org.openhab.binding.mqtt.homeassistant.internal.HaID;
+import org.openhab.binding.mqtt.homeassistant.internal.HomeAssistantChannelTransformation;
import org.openhab.binding.mqtt.homeassistant.internal.component.ComponentFactory.ComponentConfiguration;
import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
import org.openhab.binding.mqtt.homeassistant.internal.config.dto.Availability;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelGroupUID;
import org.openhab.core.thing.ChannelUID;
+import org.openhab.core.thing.binding.generic.ChannelTransformation;
import org.openhab.core.thing.type.ChannelDefinition;
import org.openhab.core.thing.type.ChannelGroupDefinition;
import org.openhab.core.thing.type.ChannelGroupType;
*/
@NonNullByDefault
public abstract class AbstractComponent<C extends AbstractChannelConfiguration> {
- private static final String JINJA_PREFIX = "JINJA:";
// Component location fields
protected final ComponentConfiguration componentConfiguration;
componentConfiguration.getTracker().setAvailabilityMode(availabilityTrackerMode);
for (Availability availability : availabilities) {
String availabilityTemplate = availability.getValueTemplate();
- List<String> availabilityTemplates = List.of();
+ ChannelTransformation transformation = null;
if (availabilityTemplate != null) {
- availabilityTemplate = JINJA_PREFIX + availabilityTemplate;
- availabilityTemplates = List.of(availabilityTemplate);
+ transformation = new HomeAssistantChannelTransformation(getJinjava(), this, availabilityTemplate);
}
componentConfiguration.getTracker().addAvailabilityTopic(availability.getTopic(),
- availability.getPayloadAvailable(), availability.getPayloadNotAvailable(),
- availabilityTemplates);
+ availability.getPayloadAvailable(), availability.getPayloadNotAvailable(), transformation);
}
} else {
String availabilityTopic = this.channelConfiguration.getAvailabilityTopic();
if (availabilityTopic != null) {
String availabilityTemplate = this.channelConfiguration.getAvailabilityTemplate();
- List<String> availabilityTemplates = List.of();
+ ChannelTransformation transformation = null;
if (availabilityTemplate != null) {
- availabilityTemplate = JINJA_PREFIX + availabilityTemplate;
- availabilityTemplates = List.of(availabilityTemplate);
+ transformation = new HomeAssistantChannelTransformation(getJinjava(), this, availabilityTemplate);
}
componentConfiguration.getTracker().addAvailabilityTopic(availabilityTopic,
this.channelConfiguration.getPayloadAvailable(),
- this.channelConfiguration.getPayloadNotAvailable(), availabilityTemplates);
+ this.channelConfiguration.getPayloadNotAvailable(), transformation);
}
}
}
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingTypeUID;
+import org.openhab.core.thing.binding.generic.ChannelTransformation;
import org.openhab.core.thing.type.ChannelGroupDefinition;
import org.openhab.core.thing.type.ChannelTypeRegistry;
import org.openhab.core.thing.type.ThingType;
return device.nodes.keySet();
}
+
+ // This odd method resolves a compilation issue (possibly with Mockito?) where for some reason
+ // it doesn't realize it needs to import this class which is used by AvailabilityTracker, but
+ // not directly from this bundle
+ // See https://github.com/openhab/openhab-addons/pull/17400
+ private void doNothing(ChannelTransformation transform) {
+ }
}